mirror of
https://github.com/ruby/ruby.git
synced 2022-11-09 12:17:21 -05:00
add tests for sub/gsub with hash.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@15535 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
This commit is contained in:
parent
1783b7aacc
commit
d77ddf33ae
2 changed files with 20 additions and 1 deletions
3
re.c
3
re.c
|
@ -3152,7 +3152,8 @@ rb_reg_s_last_match(int argc, VALUE *argv)
|
|||
}
|
||||
|
||||
static void
|
||||
re_warn(const char* s) {
|
||||
re_warn(const char *s)
|
||||
{
|
||||
rb_warn("%s", s);
|
||||
}
|
||||
|
||||
|
|
|
@ -575,6 +575,24 @@ class TestString < Test::Unit::TestCase
|
|||
assert_nil(a.sub!(S('X'), S('Y')))
|
||||
end
|
||||
|
||||
def test_sub_hash
|
||||
assert_equal('azc', 'abc'.sub(/b/, "b" => "z"))
|
||||
assert_equal('ac', 'abc'.sub(/b/, {}))
|
||||
assert_equal('a1c', 'abc'.sub(/b/, "b" => 1))
|
||||
assert_equal('aBc', 'abc'.sub(/b/, Hash.new {|h, k| k.upcase }))
|
||||
assert_equal('aBcabc', 'abcabc'.sub(/b/, Hash.new {|h, k| h[k] = k.upcase }))
|
||||
assert_equal('aBcdef', 'abcdef'.sub(/de|b/, "b" => "B", "de" => "DE"))
|
||||
end
|
||||
|
||||
def test_gsub_hash
|
||||
assert_equal('azc', 'abc'.gsub(/b/, "b" => "z"))
|
||||
assert_equal('ac', 'abc'.gsub(/b/, {}))
|
||||
assert_equal('a1c', 'abc'.gsub(/b/, "b" => 1))
|
||||
assert_equal('aBc', 'abc'.gsub(/b/, Hash.new {|h, k| k.upcase }))
|
||||
assert_equal('aBcaBc', 'abcabc'.gsub(/b/, Hash.new {|h, k| h[k] = k.upcase }))
|
||||
assert_equal('aBcDEf', 'abcdef'.gsub(/de|b/, "b" => "B", "de" => "DE"))
|
||||
end
|
||||
|
||||
def test_hash
|
||||
assert_equal(S("hello").hash, S("hello").hash)
|
||||
assert(S("hello").hash != S("helLO").hash)
|
||||
|
|
Loading…
Reference in a new issue