summaryrefslogtreecommitdiff
path: root/test
diff options
context:
space:
mode:
authornobu <nobu@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2016-11-01 22:34:30 +0000
committernobu <nobu@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2016-11-01 22:34:30 +0000
commit13149a59d8472db4cdd5a63a3eb2e7296e9a6713 (patch)
treeeb5c53df995cf03c199d87b1f5e6673547d58fc6 /test
parentc7e99cbfc8dea00ffa5d0a286ea484e90e789df4 (diff)
numeric.c: bit op with non-integer
* numeric.c (rb_num_coerce_bit): enable bit operations with coercing by non-integer object. [ruby-core:77783] [Bug #12875] git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@56543 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
Diffstat (limited to 'test')
-rw-r--r--test/ruby/test_integer.rb36
1 files changed, 36 insertions, 0 deletions
diff --git a/test/ruby/test_integer.rb b/test/ruby/test_integer.rb
index b52f1f7c51..6e505ec003 100644
--- a/test/ruby/test_integer.rb
+++ b/test/ruby/test_integer.rb
@@ -302,6 +302,42 @@ class TestInteger < Test::Unit::TestCase
assert_equal(3 ^ 10, 3 ^ obj)
end
+ module CoercionToSelf
+ def coerce(other)
+ [self.class.new(other), self]
+ end
+ end
+
+ def test_bitwise_and_with_integer_coercion
+ obj = Struct.new(:value) do
+ include(CoercionToSelf)
+ def &(other)
+ self.value & other.value
+ end
+ end.new(10)
+ assert_equal(3 & 10, 3 & obj)
+ end
+
+ def test_bitwise_or_with_integer_coercion
+ obj = Struct.new(:value) do
+ include(CoercionToSelf)
+ def |(other)
+ self.value | other.value
+ end
+ end.new(10)
+ assert_equal(3 | 10, 3 | obj)
+ end
+
+ def test_bitwise_xor_with_integer_coercion
+ obj = Struct.new(:value) do
+ include(CoercionToSelf)
+ def ^(other)
+ self.value ^ other.value
+ end
+ end.new(10)
+ assert_equal(3 ^ 10, 3 ^ obj)
+ end
+
def test_bit_length
assert_equal(13, (-2**12-1).bit_length)
assert_equal(12, (-2**12).bit_length)