summaryrefslogtreecommitdiff
path: root/test/ruby
diff options
context:
space:
mode:
Diffstat (limited to 'test/ruby')
-rw-r--r--test/ruby/test_bignum.rb36
-rw-r--r--test/ruby/test_integer.rb36
2 files changed, 72 insertions, 0 deletions
diff --git a/test/ruby/test_bignum.rb b/test/ruby/test_bignum.rb
index 1ff23e2a00..4af3748344 100644
--- a/test/ruby/test_bignum.rb
+++ b/test/ruby/test_bignum.rb
@@ -654,4 +654,40 @@ class TestBignum < Test::Unit::TestCase
def test_frozen
assert_equal(true, (2**100).frozen?)
end
+
+ def test_bitwise_and_with_integer_mimic_object
+ def (obj = Object.new).to_int
+ 10
+ end
+ assert_raise(TypeError, '[ruby-core:39491]') { T1024 & obj }
+
+ def obj.coerce(other)
+ [other, 10]
+ end
+ assert_equal(T1024 & 10, T1024 & obj)
+ end
+
+ def test_bitwise_or_with_integer_mimic_object
+ def (obj = Object.new).to_int
+ 10
+ end
+ assert_raise(TypeError, '[ruby-core:39491]') { T1024 | obj }
+
+ def obj.coerce(other)
+ [other, 10]
+ end
+ assert_equal(T1024 | 10, T1024 | obj)
+ end
+
+ def test_bitwise_xor_with_integer_mimic_object
+ def (obj = Object.new).to_int
+ 10
+ end
+ assert_raise(TypeError, '[ruby-core:39491]') { T1024 ^ obj }
+
+ def obj.coerce(other)
+ [other, 10]
+ end
+ assert_equal(T1024 ^ 10, T1024 ^ obj)
+ end
end
diff --git a/test/ruby/test_integer.rb b/test/ruby/test_integer.rb
index 3f4add7f15..655f8bb1a5 100644
--- a/test/ruby/test_integer.rb
+++ b/test/ruby/test_integer.rb
@@ -205,4 +205,40 @@ class TestInteger < Test::Unit::TestCase
assert_equal(-1111_1111_1111_1111_1111_1111_1111_1110, (-1111_1111_1111_1111_1111_1111_1111_1111).round(-1))
assert_equal(Bignum, (-1111_1111_1111_1111_1111_1111_1111_1111).round(-1).class)
end
+
+ def test_bitwise_and_with_integer_mimic_object
+ def (obj = Object.new).to_int
+ 10
+ end
+ assert_raise(TypeError, '[ruby-core:39491]') { 3 & obj }
+
+ def obj.coerce(other)
+ [other, 10]
+ end
+ assert_equal(3 & 10, 3 & obj)
+ end
+
+ def test_bitwise_or_with_integer_mimic_object
+ def (obj = Object.new).to_int
+ 10
+ end
+ assert_raise(TypeError, '[ruby-core:39491]') { 3 | obj }
+
+ def obj.coerce(other)
+ [other, 10]
+ end
+ assert_equal(3 | 10, 3 | obj)
+ end
+
+ def test_bitwise_xor_with_integer_mimic_object
+ def (obj = Object.new).to_int
+ 10
+ end
+ assert_raise(TypeError, '[ruby-core:39491]') { 3 ^ obj }
+
+ def obj.coerce(other)
+ [other, 10]
+ end
+ assert_equal(3 ^ 10, 3 ^ obj)
+ end
end