1
0
Fork 0
mirror of https://github.com/ruby/ruby.git synced 2022-11-09 12:17:21 -05:00

* sprintf.c (rb_str_format): fix error message.

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@35297 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
This commit is contained in:
nobu 2012-04-11 12:43:56 +00:00
parent 2f7290d4b3
commit 23ba7541e5
2 changed files with 9 additions and 4 deletions

View file

@ -584,7 +584,7 @@ rb_str_format(int argc, const VALUE *argv, VALUE fmt)
#endif
len = (int)(p - start + 1); /* including parenthesis */
if (id) {
rb_raise(rb_eArgError, "name%.*s after <%s>",
rb_raise(rb_eArgError, "named%.*s after <%s>",
len, start, rb_id2name(id));
}
id = rb_intern3(start + 1, len - 2 /* without parenthesis */, enc);

View file

@ -325,10 +325,15 @@ class TestSprintf < Test::Unit::TestCase
def test_named
assert_equal("value", sprintf("%<key>s", :key => "value"))
assert_raise(ArgumentError) {sprintf("%1$<key2>s", :key => "value")}
assert_raise(ArgumentError) {sprintf("%<key><key2>s", :key => "value")}
e = assert_raise(ArgumentError) {sprintf("%1$<key2>s", :key => "value")}
assert_equal("named<key2> after numbered", e.message)
e = assert_raise(ArgumentError) {sprintf("%<key><key2>s", :key => "value")}
assert_equal("named<key2> after <key>", e.message)
assert_equal("value", sprintf("%{key}", :key => "value"))
assert_raise(ArgumentError) {sprintf("%1${key2}", :key => "value")}
e = assert_raise(ArgumentError) {sprintf("%1${key2}", :key => "value")}
assert_equal("named{key2} after numbered", e.message)
e = assert_raise(ArgumentError) {sprintf("%<key>{key2}", :key => "value")}
assert_equal("named{key2} after <key>", e.message)
assert_equal("value{key2}", sprintf("%{key}{key2}", :key => "value"))
end
end