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 | df886c394905e90682705f7e5a221024dbedcc06 (patch) | |
| tree | 889b2cbad49c81c0ef99da191cadc70671332d39 /test/ruby | |
| parent | cf3e434122cc45f4b6c9f17fef2312bde4ddca1e (diff) | |
| download | ruby-df886c394905e90682705f7e5a221024dbedcc06.tar.gz ruby-df886c394905e90682705f7e5a221024dbedcc06.tar.xz ruby-df886c394905e90682705f7e5a221024dbedcc06.zip | |
add tests for sub/gsub with hash.
git-svn-id: http://svn.ruby-lang.org/repos/ruby/trunk@15535 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
Diffstat (limited to 'test/ruby')
| -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 711d9ea1f..277cdaf6e 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) |
