diff options
| author | Yukihiro "Matz" Matsumoto <[email protected]> | 2019-09-28 00:20:01 +0900 |
|---|---|---|
| committer | GitHub <[email protected]> | 2019-09-28 00:20:01 +0900 |
| commit | 19e4f56c679790f2ed2f11fb18f653ec506030e2 (patch) | |
| tree | e9e248bda4d3a9df454a32ad8bffd067c3802ba7 /test | |
| parent | 2de757eef0ff677dc677094e0f02597598d8565e (diff) | |
| parent | 198683e914ebaceba7b989c6592f871ac8fe5aa0 (diff) | |
| download | mruby-19e4f56c679790f2ed2f11fb18f653ec506030e2.tar.gz mruby-19e4f56c679790f2ed2f11fb18f653ec506030e2.zip | |
Merge pull request #4734 from shuujii/simplify-arguments-check-in-String-rindex
Simplify arguments check in `String#rindex`
Diffstat (limited to 'test')
| -rw-r--r-- | test/t/string.rb | 8 |
1 files changed, 8 insertions, 0 deletions
diff --git a/test/t/string.rb b/test/t/string.rb index 01f3da327..e1ff48312 100644 --- a/test/t/string.rb +++ b/test/t/string.rb @@ -554,9 +554,16 @@ end if UTF8STRING assert('String#rindex', '15.2.10.5.31') do assert_equal 0, 'abc'.rindex('a') + assert_equal 0, 'abc'.rindex('a', 3) + assert_nil 'abc'.rindex('a', -4) assert_nil 'abc'.rindex('d') + assert_equal 6, 'abcabc'.rindex('') + assert_equal 3, 'abcabc'.rindex('a') assert_equal 0, 'abcabc'.rindex('a', 1) assert_equal 3, 'abcabc'.rindex('a', 4) + assert_equal 0, 'abcabc'.rindex('a', -4) + assert_raise(ArgumentError) { "hello".rindex } + assert_raise(TypeError) { "hello".rindex(101) } end assert('String#rindex(UTF-8)', '15.2.10.5.31') do @@ -564,6 +571,7 @@ assert('String#rindex(UTF-8)', '15.2.10.5.31') do assert_nil str.rindex('さ') assert_equal 12, str.rindex('ち') assert_equal 3, str.rindex('ち', 10) + assert_equal 3, str.rindex('ち', -6) broken = "\xf0☀\xf1☁\xf2☂\xf3☃\xf0☀\xf1☁\xf2☂\xf3☃" assert_nil broken.rindex("\x81") # "\x81" is a part of "☁" ("\xe2\x98\x81") |
