ruby-changes:59578
From: Nobuyoshi <ko1@a...>
Date: Wed, 1 Jan 2020 01:09:16 +0900 (JST)
Subject: [ruby-changes:59578] 0cf75e3850 (master): Split test_nomethod_error.rb
https://git.ruby-lang.org/ruby.git/commit/?id=0cf75e3850 From 0cf75e38506a412a7b4acd39a93e32aff1e8016c Mon Sep 17 00:00:00 2001 From: Nobuyoshi Nakada <nobu@r...> Date: Tue, 31 Dec 2019 14:36:54 +0900 Subject: Split test_nomethod_error.rb diff --git a/test/ruby/test_exception.rb b/test/ruby/test_exception.rb index 44867d2..c0ab23a 100644 --- a/test/ruby/test_exception.rb +++ b/test/ruby/test_exception.rb @@ -438,16 +438,6 @@ end.join https://github.com/ruby/ruby/blob/trunk/test/ruby/test_exception.rb#L438 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 https://github.com/ruby/ruby/blob/trunk/test/ruby/test_exception.rb#L818 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 0000000..ed3b826 --- /dev/null +++ b/test/ruby/test_nomethod_error.rb @@ -0,0 +1,89 @@ https://github.com/ruby/ruby/blob/trunk/test/ruby/test_nomethod_error.rb#L1 +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 -- cgit v0.10.2 -- ML: ruby-changes@q... Info: http://www.atdot.net/~ko1/quickml/