From f029dba59b20c081e9b278dc754601555cccd3d0 Mon Sep 17 00:00:00 2001 From: yugui Date: Fri, 27 Nov 2009 02:54:29 +0000 Subject: merges r25010 from trunk into ruby_1_9_1 and adds tests for it. -- * struct.c (rb_struct_equal, rb_struct_eql): Handle comparison of recursive structures [ruby-core:24759] * range.c (range_eq, range_eql): ditto for ranges -- test for r25010 * test/ruby/test_struct.rb (TestStruct#test_comparison_when_recursive): new test. * test/ruby/test_range.rb (TestRange#test_comparison_when_recursive): new test. git-svn-id: http://svn.ruby-lang.org/repos/ruby/branches/ruby_1_9_1@25943 b2dd03c8-39d4-4d8f-98ff-823fe69b080e --- test/ruby/test_struct.rb | 30 ++++++++++++++++++++++++++++++ 1 file changed, 30 insertions(+) (limited to 'test/ruby/test_struct.rb') diff --git a/test/ruby/test_struct.rb b/test/ruby/test_struct.rb index 1b68429d0..688012a1f 100644 --- a/test/ruby/test_struct.rb +++ b/test/ruby/test_struct.rb @@ -1,4 +1,5 @@ require 'test/unit' +require 'timeout' class TestStruct < Test::Unit::TestCase def test_struct @@ -219,4 +220,33 @@ class TestStruct < Test::Unit::TestCase a = struct_test.new(42) assert_equal("#", a.inspect, '[ruby-core:24849]') end + + def test_comparison_when_recursive + klass1 = Struct.new(:a, :b, :c) + + x = klass1.new(1, 2, nil); x.c = x + y = klass1.new(1, 2, nil); y.c = y + Timeout.timeout(1) { + assert x == y + assert x.eql? y + } + + z = klass1.new(:something, :other, nil); z.c = z + Timeout.timeout(1) { + assert x != z + assert !x.eql?(z) + } + + x.c = y; y.c = x + Timeout.timeout(1) { + assert x == y + assert x.eql?(y) + } + + x.c = z; z.c = x + Timeout.timeout(1) { + assert x != z + assert !x.eql?(z) + } + end end -- cgit