diff options
author | nobu <nobu@b2dd03c8-39d4-4d8f-98ff-823fe69b080e> | 2009-11-08 03:59:42 +0000 |
---|---|---|
committer | nobu <nobu@b2dd03c8-39d4-4d8f-98ff-823fe69b080e> | 2009-11-08 03:59:42 +0000 |
commit | 6ef3d123dd8c0defbe56db17926faac10b2085ae (patch) | |
tree | f7411b025f2c0c5e22390432bee2130a6128c5bd /test/ruby/test_comparable.rb | |
parent | c63b9d9632a1ee95c6855d31b4771bfae733f229 (diff) | |
download | ruby-6ef3d123dd8c0defbe56db17926faac10b2085ae.tar.gz |
* test/ruby/test_comparable.rb (TestComparable#cmp): suppress warnings.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@25689 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
Diffstat (limited to 'test/ruby/test_comparable.rb')
-rw-r--r-- | test/ruby/test_comparable.rb | 38 |
1 files changed, 22 insertions, 16 deletions
diff --git a/test/ruby/test_comparable.rb b/test/ruby/test_comparable.rb index e558b190f0..00ce6b485a 100644 --- a/test/ruby/test_comparable.rb +++ b/test/ruby/test_comparable.rb @@ -5,54 +5,60 @@ class TestComparable < Test::Unit::TestCase @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)) |