diff options
author | nobu <nobu@b2dd03c8-39d4-4d8f-98ff-823fe69b080e> | 2017-09-18 08:05:53 +0000 |
---|---|---|
committer | nobu <nobu@b2dd03c8-39d4-4d8f-98ff-823fe69b080e> | 2017-09-18 08:05:53 +0000 |
commit | 13f5dcb9f25cf07ef22baa5aded490395700b283 (patch) | |
tree | 5678b3e222c96077a2eb8e7a80e21dd5dbef1d3e /test/ruby | |
parent | 2627c19d82252f2bb571f6bcb44e359cacefa92b (diff) | |
download | ruby-13f5dcb9f25cf07ef22baa5aded490395700b283.tar.gz |
error.c: KeyError#receiver and KeyError#key
* error.c: new method KeyError#receiver and KeyError#key.
[Feature #12063]
* hash.c: make KeyError object with receiver and key.
* sprintf.c: ditto.
Author: ksss <co000ri@gmail.com>
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@59955 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
Diffstat (limited to 'test/ruby')
-rw-r--r-- | test/ruby/test_env.rb | 4 | ||||
-rw-r--r-- | test/ruby/test_hash.rb | 6 | ||||
-rw-r--r-- | test/ruby/test_sprintf.rb | 5 |
3 files changed, 12 insertions, 3 deletions
diff --git a/test/ruby/test_env.rb b/test/ruby/test_env.rb index 29c058339f..d136ba75fa 100644 --- a/test/ruby/test_env.rb +++ b/test/ruby/test_env.rb @@ -122,9 +122,11 @@ class TestEnv < Test::Unit::TestCase assert_equal("foo", ENV.fetch("test")) ENV.delete("test") feature8649 = '[ruby-core:56062] [Feature #8649]' - assert_raise_with_message(KeyError, 'key not found: "test"', feature8649) do + e = assert_raise_with_message(KeyError, 'key not found: "test"', feature8649) do ENV.fetch("test") end + assert_same(ENV, e.receiver) + assert_equal("test", e.key) assert_equal("foo", ENV.fetch("test", "foo")) assert_equal("bar", ENV.fetch("test") { "bar" }) assert_equal("bar", ENV.fetch("test", "foo") { "bar" }) diff --git a/test/ruby/test_hash.rb b/test/ruby/test_hash.rb index 8fb1c17003..ebc622a827 100644 --- a/test/ruby/test_hash.rb +++ b/test/ruby/test_hash.rb @@ -531,6 +531,8 @@ class TestHash < Test::Unit::TestCase e = assert_raise(KeyError) { @h.fetch('gumby'*20) } assert_match(/key not found: "gumbygumby/, e.message) assert_match(/\.\.\.\z/, e.message) + assert_same(@h, e.receiver) + assert_equal('gumby'*20, e.key) end def test_key2? @@ -591,9 +593,11 @@ class TestHash < Test::Unit::TestCase assert_equal(4, res.length) assert_equal %w( three two one nil ), res - assert_raise KeyError do + e = assert_raise KeyError do @h.fetch_values(3, 'invalid') end + assert_same(@h, e.receiver) + assert_equal('invalid', e.key) res = @h.fetch_values(3, 'invalid') { |k| k.upcase } assert_equal %w( three INVALID ), res diff --git a/test/ruby/test_sprintf.rb b/test/ruby/test_sprintf.rb index b46f5189e2..a07ac7908b 100644 --- a/test/ruby/test_sprintf.rb +++ b/test/ruby/test_sprintf.rb @@ -452,7 +452,10 @@ class TestSprintf < Test::Unit::TestCase assert_raise_with_message(ArgumentError, "named<key2> after numbered") {sprintf("%1$<key2>s", :key => "value")} assert_raise_with_message(ArgumentError, "named<key2> after unnumbered(2)") {sprintf("%s%s%<key2>s", "foo", "bar", :key => "value")} assert_raise_with_message(ArgumentError, "named<key2> after <key>") {sprintf("%<key><key2>s", :key => "value")} - assert_raise_with_message(KeyError, "key<key> not found") {sprintf("%<key>s", {})} + h = {} + e = assert_raise_with_message(KeyError, "key<key> not found") {sprintf("%<key>s", h)} + assert_same(h, e.receiver) + assert_equal(:key, e.key) end def test_named_untyped_enc |