diff options
author | Nobuyoshi Nakada <nobu@ruby-lang.org> | 2019-12-31 14:36:54 +0900 |
---|---|---|
committer | Nobuyoshi Nakada <nobu@ruby-lang.org> | 2019-12-31 19:43:36 +0900 |
commit | 0cf75e38506a412a7b4acd39a93e32aff1e8016c (patch) | |
tree | 2ea809ccbae07ffb0d5e548cee21f3e23153141b | |
parent | a580a3757b162b8d1b2b19d91f5c246c7fc5dca8 (diff) | |
download | ruby-0cf75e38506a412a7b4acd39a93e32aff1e8016c.tar.gz |
Split test_nomethod_error.rb
-rw-r--r-- | test/ruby/test_exception.rb | 86 | ||||
-rw-r--r-- | test/ruby/test_nomethod_error.rb | 89 |
2 files changed, 89 insertions, 86 deletions
diff --git a/test/ruby/test_exception.rb b/test/ruby/test_exception.rb index 44867d2ce3..c0ab23a18e 100644 --- a/test/ruby/test_exception.rb +++ b/test/ruby/test_exception.rb @@ -438,16 +438,6 @@ end.join assert_not_send([e, :success?], "abort means failure") end - def test_nomethoderror - bug3237 = '[ruby-core:29948]' - str = "\u2600" - id = :"\u2604" - msg = "undefined method `#{id}' for \"#{str}\":String" - assert_raise_with_message(NoMethodError, msg, bug3237) do - str.__send__(id) - end - end - def test_errno assert_equal(Encoding.find("locale"), Errno::EINVAL.new.message.encoding) end @@ -828,82 +818,6 @@ end.join assert_in_out_err([], "raise Class.new(RuntimeError), 'foo'", [], /foo\n/) end - def test_nomethod_error_new_default - error = NoMethodError.new - assert_equal("NoMethodError", error.message) - end - - def test_nomethod_error_new_message - error = NoMethodError.new("Message") - assert_equal("Message", error.message) - end - - def test_nomethod_error_new_name - error = NoMethodError.new("Message") - assert_nil(error.name) - - error = NoMethodError.new("Message", :foo) - assert_equal(:foo, error.name) - end - - def test_nomethod_error_new_name_args - error = NoMethodError.new("Message", :foo) - assert_nil(error.args) - - error = NoMethodError.new("Message", :foo, [1, 2]) - assert_equal([:foo, [1, 2]], [error.name, error.args]) - end - - def test_nomethod_error_new_name_args_priv - error = NoMethodError.new("Message", :foo, [1, 2]) - assert_not_predicate(error, :private_call?) - - error = NoMethodError.new("Message", :foo, [1, 2], true) - assert_equal([:foo, [1, 2], true], - [error.name, error.args, error.private_call?]) - end - - def test_nomethod_error_new_receiver - receiver = Object.new - - error = NoMethodError.new - assert_raise(ArgumentError) {error.receiver} - - error = NoMethodError.new(receiver: receiver) - assert_equal(receiver, error.receiver) - - error = NoMethodError.new("Message") - assert_raise(ArgumentError) {error.receiver} - - error = NoMethodError.new("Message", receiver: receiver) - assert_equal(["Message", receiver], - [error.message, error.receiver]) - - error = NoMethodError.new("Message", :foo) - assert_raise(ArgumentError) {error.receiver} - - msg = defined?(DidYouMean.formatter) ? - "Message\nDid you mean? for" : "Message" - - error = NoMethodError.new("Message", :foo, receiver: receiver) - assert_equal([msg, :foo, receiver], - [error.message, error.name, error.receiver]) - - error = NoMethodError.new("Message", :foo, [1, 2]) - assert_raise(ArgumentError) {error.receiver} - - error = NoMethodError.new("Message", :foo, [1, 2], receiver: receiver) - assert_equal([msg, :foo, [1, 2], receiver], - [error.message, error.name, error.args, error.receiver]) - - error = NoMethodError.new("Message", :foo, [1, 2], true) - assert_raise(ArgumentError) {error.receiver} - - error = NoMethodError.new("Message", :foo, [1, 2], true, receiver: receiver) - assert_equal([:foo, [1, 2], true, receiver], - [error.name, error.args, error.private_call?, error.receiver]) - end - def test_output_string_encoding # "\x82\xa0" in cp932 is "\u3042" (Japanese hiragana 'a') # change $stderr to force calling rb_io_write() instead of fwrite() diff --git a/test/ruby/test_nomethod_error.rb b/test/ruby/test_nomethod_error.rb new file mode 100644 index 0000000000..ed3b826d65 --- /dev/null +++ b/test/ruby/test_nomethod_error.rb @@ -0,0 +1,89 @@ +require 'test/unit' + +class TestNoMethodError < Test::Unit::TestCase + def test_new_default + error = NoMethodError.new + assert_equal("NoMethodError", error.message) + end + + def test_new_message + error = NoMethodError.new("Message") + assert_equal("Message", error.message) + end + + def test_new_name + error = NoMethodError.new("Message") + assert_nil(error.name) + + error = NoMethodError.new("Message", :foo) + assert_equal(:foo, error.name) + end + + def test_new_name_args + error = NoMethodError.new("Message", :foo) + assert_nil(error.args) + + error = NoMethodError.new("Message", :foo, [1, 2]) + assert_equal([:foo, [1, 2]], [error.name, error.args]) + end + + def test_new_name_args_priv + error = NoMethodError.new("Message", :foo, [1, 2]) + assert_not_predicate(error, :private_call?) + + error = NoMethodError.new("Message", :foo, [1, 2], true) + assert_equal([:foo, [1, 2], true], + [error.name, error.args, error.private_call?]) + end + + def test_new_receiver + receiver = Object.new + + error = NoMethodError.new + assert_raise(ArgumentError) {error.receiver} + + error = NoMethodError.new(receiver: receiver) + assert_equal(receiver, error.receiver) + + error = NoMethodError.new("Message") + assert_raise(ArgumentError) {error.receiver} + + error = NoMethodError.new("Message", receiver: receiver) + assert_equal(["Message", receiver], + [error.message, error.receiver]) + + error = NoMethodError.new("Message", :foo) + assert_raise(ArgumentError) {error.receiver} + + msg = defined?(DidYouMean.formatter) ? + "Message\nDid you mean? for" : "Message" + + error = NoMethodError.new("Message", :foo, receiver: receiver) + assert_equal([msg, :foo, receiver], + [error.message, error.name, error.receiver]) + + error = NoMethodError.new("Message", :foo, [1, 2]) + assert_raise(ArgumentError) {error.receiver} + + error = NoMethodError.new("Message", :foo, [1, 2], receiver: receiver) + assert_equal([msg, :foo, [1, 2], receiver], + [error.message, error.name, error.args, error.receiver]) + + error = NoMethodError.new("Message", :foo, [1, 2], true) + assert_raise(ArgumentError) {error.receiver} + + error = NoMethodError.new("Message", :foo, [1, 2], true, receiver: receiver) + assert_equal([:foo, [1, 2], true, receiver], + [error.name, error.args, error.private_call?, error.receiver]) + end + + def test_message_encoding + bug3237 = '[ruby-core:29948]' + str = "\u2600" + id = :"\u2604" + msg = "undefined method `#{id}' for \"#{str}\":String" + assert_raise_with_message(NoMethodError, msg, bug3237) do + str.__send__(id) + end + end +end |