summaryrefslogtreecommitdiff
path: root/test
diff options
context:
space:
mode:
authornagachika <nagachika@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2014-01-19 17:14:02 +0000
committernagachika <nagachika@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2014-01-19 17:14:02 +0000
commit24365fb24b4ac7e20556cee2dd842e40008f1ac7 (patch)
tree474ee2a70e7d6cd8d1070bf2fe91c30601f29202 /test
parent8302aa5f951e85984899d73fafa6bef2f23deddd (diff)
merge revision(s) 44609,44610,44612,44613,44617:
test_numeric.rb: coercion failures * test/ruby/test_numeric.rb (test_coerce): new assertions for failure of coercion. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/branches/ruby_2_0_0@44660 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
Diffstat (limited to 'test')
-rw-r--r--test/ruby/test_numeric.rb39
1 files changed, 36 insertions, 3 deletions
diff --git a/test/ruby/test_numeric.rb b/test/ruby/test_numeric.rb
index 09b48ebc69..5cd0de66e8 100644
--- a/test/ruby/test_numeric.rb
+++ b/test/ruby/test_numeric.rb
@@ -1,9 +1,15 @@
require 'test/unit'
+require_relative 'envutil'
class TestNumeric < Test::Unit::TestCase
class DummyNumeric < Numeric
end
+ def assert_raise_with_message(exc, pattern, &blk)
+ e = assert_raise(exc, &blk)
+ assert_match(pattern, e.message)
+ end
+
def test_coerce
a, b = 1.coerce(2)
assert_equal(Fixnum, a.class)
@@ -14,6 +20,24 @@ class TestNumeric < Test::Unit::TestCase
assert_equal(Float, b.class)
assert_raise(TypeError) { -Numeric.new }
+
+ assert_raise_with_message(TypeError, /can't be coerced into /) {1+:foo}
+ assert_raise_with_message(TypeError, /can't be coerced into /) {1&:foo}
+ assert_raise_with_message(TypeError, /can't be coerced into /) {1|:foo}
+ assert_raise_with_message(TypeError, /can't be coerced into /) {1^:foo}
+
+ EnvUtil.with_default_external(Encoding::UTF_8) do
+ assert_raise_with_message(TypeError, /:\u{3042}/) {1+:"\u{3042}"}
+ assert_raise_with_message(TypeError, /:\u{3042}/) {1&:"\u{3042}"}
+ assert_raise_with_message(TypeError, /:\u{3042}/) {1|:"\u{3042}"}
+ assert_raise_with_message(TypeError, /:\u{3042}/) {1^:"\u{3042}"}
+ end
+ EnvUtil.with_default_external(Encoding::US_ASCII) do
+ assert_raise_with_message(TypeError, /:"\\u3042"/) {1+:"\u{3042}"}
+ assert_raise_with_message(TypeError, /:"\\u3042"/) {1&:"\u{3042}"}
+ assert_raise_with_message(TypeError, /:"\\u3042"/) {1|:"\u{3042}"}
+ assert_raise_with_message(TypeError, /:"\\u3042"/) {1^:"\u{3042}"}
+ end
end
def test_dummynumeric
@@ -46,11 +70,20 @@ class TestNumeric < Test::Unit::TestCase
end
end
- def test_numeric
+ def test_singleton_method
+ a = Numeric.new
+ assert_raise_with_message(TypeError, /foo/) { def a.foo; end }
+ assert_raise_with_message(TypeError, /\u3042/) { eval("def a.\u3042; end") }
+ end
+
+ def test_dup
a = Numeric.new
- assert_raise(TypeError) { def a.foo; end }
- assert_raise(TypeError) { eval("def a.\u3042; end") }
assert_raise(TypeError) { a.dup }
+
+ c = Module.new do
+ break eval("class C\u{3042} < Numeric; self; end")
+ end
+ assert_raise_with_message(TypeError, /C\u3042/) {c.new.dup}
end
def test_quo