summaryrefslogtreecommitdiffhomepage
path: root/mrbgems/mruby-string-ext/test
diff options
context:
space:
mode:
authorYukihiro "Matz" Matsumoto <[email protected]>2018-09-20 17:25:07 +0900
committerYukihiro "Matz" Matsumoto <[email protected]>2018-09-21 00:03:07 +0900
commit58f7f2361a39ae288c4233ca434e1dbd37f127d0 (patch)
treec691ef8e6c42b6ec726b4dd4fd4928a29adcd4e0 /mrbgems/mruby-string-ext/test
parent68523b4ec4a271134aae34d744582a974558c962 (diff)
downloadmruby-58f7f2361a39ae288c4233ca434e1dbd37f127d0.tar.gz
mruby-58f7f2361a39ae288c4233ca434e1dbd37f127d0.zip
Implement `String#count`; ref #4086
mruby restriction: In mruby, `String#count` does not take multiple pattern arguments, but only one pattern.
Diffstat (limited to 'mrbgems/mruby-string-ext/test')
-rw-r--r--mrbgems/mruby-string-ext/test/string.rb9
1 files changed, 9 insertions, 0 deletions
diff --git a/mrbgems/mruby-string-ext/test/string.rb b/mrbgems/mruby-string-ext/test/string.rb
index fd6f83e71..3e9ab5b1b 100644
--- a/mrbgems/mruby-string-ext/test/string.rb
+++ b/mrbgems/mruby-string-ext/test/string.rb
@@ -147,6 +147,15 @@ assert('String#casecmp') do
assert_equal 0, "abcdef".casecmp(o)
end
+assert('String#count') do
+ s = "abccdeff123"
+ assert_equal 1, s.count("a")
+ assert_equal 2, s.count("ab")
+ assert_equal 9, s.count("^c")
+ assert_equal 8, s.count("a-z")
+ assert_equal 4, s.count("a0-9")
+end
+
assert('String#tr') do
assert_equal "ABC", "abc".tr('a-z', 'A-Z')
assert_equal "hippo", "hello".tr('el', 'ip')