diff options
author | nobu <nobu@b2dd03c8-39d4-4d8f-98ff-823fe69b080e> | 2016-11-01 13:10:16 +0000 |
---|---|---|
committer | nobu <nobu@b2dd03c8-39d4-4d8f-98ff-823fe69b080e> | 2016-11-01 13:10:16 +0000 |
commit | 544e59ec7d55f3e600e530d7b8893d94808da94f (patch) | |
tree | 5a994bbc8e0eddee54ae31be9a0bbb9269c358a2 /test/ruby/test_integer.rb | |
parent | 69fc155c7743d83dec2fc6b80a9eb2e6414cb10b (diff) | |
download | ruby-544e59ec7d55f3e600e530d7b8893d94808da94f.tar.gz |
test_integer.rb: common parts
* test/ruby/test_integer.rb (MimicInteger, CoercionToInt): extract
common parts.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@56540 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
Diffstat (limited to 'test/ruby/test_integer.rb')
-rw-r--r-- | test/ruby/test_integer.rb | 34 |
1 files changed, 13 insertions, 21 deletions
diff --git a/test/ruby/test_integer.rb b/test/ruby/test_integer.rb index 00c3c12577..b52f1f7c51 100644 --- a/test/ruby/test_integer.rb +++ b/test/ruby/test_integer.rb @@ -274,39 +274,31 @@ class TestInteger < Test::Unit::TestCase assert_int_equal(-1111_1111_1111_1111_1111_1111_1111_1110, (-1111_1111_1111_1111_1111_1111_1111_1111).truncate(-1)) end - def test_bitwise_and_with_integer_mimic_object - def (obj = Object.new).to_int - 10 + MimicInteger = Struct.new(:to_int) + module CoercionToInt + def coerce(other) + [other, to_int] end - assert_raise(TypeError, '[ruby-core:39491]') { 3 & obj } + end - def obj.coerce(other) - [other, 10] - end + def test_bitwise_and_with_integer_mimic_object + obj = MimicInteger.new(10) + assert_raise(TypeError, '[ruby-core:39491]') { 3 & obj } + obj.extend(CoercionToInt) assert_equal(3 & 10, 3 & obj) end def test_bitwise_or_with_integer_mimic_object - def (obj = Object.new).to_int - 10 - end + obj = MimicInteger.new(10) assert_raise(TypeError, '[ruby-core:39491]') { 3 | obj } - - def obj.coerce(other) - [other, 10] - end + obj.extend(CoercionToInt) assert_equal(3 | 10, 3 | obj) end def test_bitwise_xor_with_integer_mimic_object - def (obj = Object.new).to_int - 10 - end + obj = MimicInteger.new(10) assert_raise(TypeError, '[ruby-core:39491]') { 3 ^ obj } - - def obj.coerce(other) - [other, 10] - end + obj.extend(CoercionToInt) assert_equal(3 ^ 10, 3 ^ obj) end |