summaryrefslogtreecommitdiffhomepage
path: root/mrbgems/mruby-string-ext/test/string.rb
diff options
context:
space:
mode:
authorYukihiro "Matz" Matsumoto <[email protected]>2018-09-20 15:13:13 +0900
committerYukihiro "Matz" Matsumoto <[email protected]>2018-09-21 00:03:07 +0900
commit58ba38fe1e11828190596b44e0789dd8a0607ff3 (patch)
tree8325ab9b013efd4330c3446f19890dc7fc3635bd /mrbgems/mruby-string-ext/test/string.rb
parentf23f2bbdad7a15bec8812b029cb23c2117d7c63c (diff)
downloadmruby-58ba38fe1e11828190596b44e0789dd8a0607ff3.tar.gz
mruby-58ba38fe1e11828190596b44e0789dd8a0607ff3.zip
Add `String#tr` and `#tr!` to `mruby-string-ext` gem; fix #4086
This patch is based on `mruby/c` implementation by Hirohito Higashi. We might need to add `#tr_s`, `#squeeze` and `#delete` as well. Adding them should not be too hard using functions we implemented here.
Diffstat (limited to 'mrbgems/mruby-string-ext/test/string.rb')
-rw-r--r--mrbgems/mruby-string-ext/test/string.rb13
1 files changed, 13 insertions, 0 deletions
diff --git a/mrbgems/mruby-string-ext/test/string.rb b/mrbgems/mruby-string-ext/test/string.rb
index b6146fb90..6b8a89c4d 100644
--- a/mrbgems/mruby-string-ext/test/string.rb
+++ b/mrbgems/mruby-string-ext/test/string.rb
@@ -147,6 +147,19 @@ assert('String#casecmp') do
assert_equal 0, "abcdef".casecmp(o)
end
+assert('String#tr') do
+ assert_equal "ABC", "abc".tr('a-z', 'A-Z')
+ assert_equal "hippo", "hello".tr('el', 'ip')
+ assert_equal "Ruby", "Lisp".tr("Lisp", "Ruby")
+ assert_equal "*e**o", "hello".tr('^aeiou', '*')
+end
+
+assert('String#tr!') do
+ s = "abcdefghijklmnopqR"
+ assert_equal "ab12222hijklmnopqR", s.tr!("cdefg", "12")
+ assert_equal "ab12222hijklmnopqR", s
+end
+
assert('String#start_with?') do
assert_true "hello".start_with?("heaven", "hell")
assert_true !"hello".start_with?("heaven", "paradise")