diff options
author | akr <akr@b2dd03c8-39d4-4d8f-98ff-823fe69b080e> | 2008-02-18 03:51:34 +0000 |
---|---|---|
committer | akr <akr@b2dd03c8-39d4-4d8f-98ff-823fe69b080e> | 2008-02-18 03:51:34 +0000 |
commit | d77ddf33aed2177ff0be4b4fc72aaee003865198 (patch) | |
tree | 889b2cbad49c81c0ef99da191cadc70671332d39 /test | |
parent | 1783b7aaccf52291c5e7f84e349ad3c95a858269 (diff) |
add tests for sub/gsub with hash.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@15535 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
Diffstat (limited to 'test')
-rw-r--r-- | test/ruby/test_string.rb | 18 |
1 files changed, 18 insertions, 0 deletions
diff --git a/test/ruby/test_string.rb b/test/ruby/test_string.rb index 711d9ea1f9..277cdaf6ea 100644 --- a/test/ruby/test_string.rb +++ b/test/ruby/test_string.rb @@ -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) |