From 21c32a3c7a64bed2379b3c2d31e832748467df0f Mon Sep 17 00:00:00 2001 From: yugui Date: Thu, 26 Nov 2009 12:17:47 +0000 Subject: [PATCH] * test/ruby/test_range.rb (TestRange#test_comparison_when_recursive): test for r25010. * test/ruby/test_struct.rb (TestStruct#test_comparison_when_recursive): ditto. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@25933 b2dd03c8-39d4-4d8f-98ff-823fe69b080e --- ChangeLog | 8 ++++++++ test/ruby/test_range.rb | 34 ++++++++++++++++++++++++++++++++++ test/ruby/test_struct.rb | 30 ++++++++++++++++++++++++++++++ 3 files changed, 72 insertions(+) diff --git a/ChangeLog b/ChangeLog index 4953f1e3bb..f0bec1993c 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,11 @@ +Thu Nov 26 21:08:54 2009 Yuki Sonoda (Yugui) + + * test/ruby/test_range.rb (TestRange#test_comparison_when_recursive): + test for r25010. + + * test/ruby/test_struct.rb (TestStruct#test_comparison_when_recursive): + ditto. + Thu Nov 26 20:18:02 2009 NARUSE, Yui * gem_prelude.rb (Gem.set_home): must dup before force_encoding diff --git a/test/ruby/test_range.rb b/test/ruby/test_range.rb index 5ad2638d4a..e0ff273836 100644 --- a/test/ruby/test_range.rb +++ b/test/ruby/test_range.rb @@ -1,5 +1,6 @@ require 'test/unit' require 'delegate' +require 'timeout' class TestRange < Test::Unit::TestCase def test_range_string @@ -294,4 +295,37 @@ class TestRange < Test::Unit::TestCase o.instance_eval { initialize(o, 1) } assert_equal("(... .. ...)..1", o.inspect) end + + def test_comparison_when_recursive + x = CyclicRange.allocate; x.send(:initialize, x, 1) + y = CyclicRange.allocate; y.send(:initialize, y, 1) + Timeout.timeout(1) { + assert x == y + assert x.eql? y + } + + z = CyclicRange.allocate; z.send(:initialize, z, :another) + Timeout.timeout(1) { + assert x != z + assert !x.eql?(z) + } + + x = CyclicRange.allocate + y = CyclicRange.allocate + x.send(:initialize, y, 1) + y.send(:initialize, x, 1) + Timeout.timeout(1) { + assert x == y + assert x.eql?(y) + } + + x = CyclicRange.allocate + z = CyclicRange.allocate + x.send(:initialize, z, 1) + z.send(:initialize, x, :other) + Timeout.timeout(1) { + assert x != z + assert !x.eql?(z) + } + end end diff --git a/test/ruby/test_struct.rb b/test/ruby/test_struct.rb index b6a77a9fb7..49dcdb45b2 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