diff options
-rw-r--r-- | re.c | 3 | ||||
-rw-r--r-- | test/ruby/test_string.rb | 18 |
2 files changed, 20 insertions, 1 deletions
@@ -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); } 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) |