[前][次][番号順一覧][スレッド一覧]

ruby-changes:13887

From: nobu <ko1@a...>
Date: Sun, 8 Nov 2009 12:59:52 +0900 (JST)
Subject: [ruby-changes:13887] Ruby:r25689 (trunk): * test/ruby/test_comparable.rb (TestComparable#cmp): suppress warnings.

nobu	2009-11-08 12:59:42 +0900 (Sun, 08 Nov 2009)

  New Revision: 25689

  http://svn.ruby-lang.org/cgi-bin/viewvc.cgi?view=rev&revision=25689

  Log:
    * test/ruby/test_comparable.rb (TestComparable#cmp): suppress warnings.

  Modified files:
    trunk/test/ruby/test_comparable.rb

Index: test/ruby/test_comparable.rb
===================================================================
--- test/ruby/test_comparable.rb	(revision 25688)
+++ test/ruby/test_comparable.rb	(revision 25689)
@@ -5,54 +5,60 @@
     @o = Object.new
     @o.extend(Comparable)
   end
+  def cmp(b)
+    class << @o; self; end.class_eval {
+      undef :<=>
+      define_method(:<=>, b)
+    }
+  end
 
   def test_equal
-    def @o.<=>(x); 0; end
+    cmp->(x) do 0; end
     assert_equal(true, @o == nil)
-    def @o.<=>(x); 1; end
+    cmp->(x) do 1; end
     assert_equal(false, @o == nil)
-    def @o.<=>(x); raise; end
+    cmp->(x) do raise; end
     assert_equal(false, @o == nil)
   end
 
   def test_gt
-    def @o.<=>(x); 1; end
+    cmp->(x) do 1; end
     assert_equal(true, @o > nil)
-    def @o.<=>(x); 0; end
+    cmp->(x) do 0; end
     assert_equal(false, @o > nil)
-    def @o.<=>(x); -1; end
+    cmp->(x) do -1; end
     assert_equal(false, @o > nil)
   end
 
   def test_ge
-    def @o.<=>(x); 1; end
+    cmp->(x) do 1; end
     assert_equal(true, @o >= nil)
-    def @o.<=>(x); 0; end
+    cmp->(x) do 0; end
     assert_equal(true, @o >= nil)
-    def @o.<=>(x); -1; end
+    cmp->(x) do -1; end
     assert_equal(false, @o >= nil)
   end
 
   def test_lt
-    def @o.<=>(x); 1; end
+    cmp->(x) do 1; end
     assert_equal(false, @o < nil)
-    def @o.<=>(x); 0; end
+    cmp->(x) do 0; end
     assert_equal(false, @o < nil)
-    def @o.<=>(x); -1; end
+    cmp->(x) do -1; end
     assert_equal(true, @o < nil)
   end
 
   def test_le
-    def @o.<=>(x); 1; end
+    cmp->(x) do 1; end
     assert_equal(false, @o <= nil)
-    def @o.<=>(x); 0; end
+    cmp->(x) do 0; end
     assert_equal(true, @o <= nil)
-    def @o.<=>(x); -1; end
+    cmp->(x) do -1; end
     assert_equal(true, @o <= nil)
   end
 
   def test_between
-    def @o.<=>(x); 0 <=> x end
+    cmp->(x) do 0 <=> x end
     assert_equal(false, @o.between?(1, 2))
     assert_equal(false, @o.between?(-2, -1))
     assert_equal(true, @o.between?(-1, 1))

--
ML: ruby-changes@q...
Info: http://www.atdot.net/~ko1/quickml/

[前][次][番号順一覧][スレッド一覧]