summaryrefslogtreecommitdiff
path: root/test
diff options
context:
space:
mode:
authoryugui <yugui@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2009-11-27 02:54:29 +0000
committeryugui <yugui@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2009-11-27 02:54:29 +0000
commit6e6417c8d38afced7eb7c10781f20f7b19ebbc89 (patch)
treea0e48c71d1584691383297d9c7f46cdc300ad8a3 /test
parent9abf98bbe47b65dbc058b8ab752aa81ba8c7754b (diff)
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: svn+ssh://ci.ruby-lang.org/ruby/branches/ruby_1_9_1@25943 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
Diffstat (limited to 'test')
-rw-r--r--test/ruby/test_range.rb34
-rw-r--r--test/ruby/test_struct.rb30
2 files changed, 64 insertions, 0 deletions
diff --git a/test/ruby/test_range.rb b/test/ruby/test_range.rb
index 9dfd29012a..dabe7fab87 100644
--- a/test/ruby/test_range.rb
+++ b/test/ruby/test_range.rb
@@ -1,4 +1,5 @@
require 'test/unit'
+require 'timeout'
class TestRange < Test::Unit::TestCase
def test_range_string
@@ -280,4 +281,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 1b68429d0c..688012a1fd 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("#<struct Struct::R\u{e9}sum\u{e9} r\u{e9}sum\u{e9}=42>", 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