diff options
| author | Shugo Maeda <shugo@ruby-lang.org> | 2023-01-20 16:09:58 +0900 |
|---|---|---|
| committer | Shugo Maeda <shugo.maeda@gmail.com> | 2023-01-20 18:02:37 +0900 |
| commit | cce3960964784e57cba14762503c5fdd688e9919 (patch) | |
| tree | 0be911c0aedc119af4d636f56eee82ae8b2d7f2b /test/ruby | |
| parent | 845f6275b2b7d9ad24e45e3a0bfabeea25555bbc (diff) | |
[Feature #19314] Add new arguments of String#bytesplice
bytesplice(index, length, str, str_index, str_length) -> string
bytesplice(range, str, str_range) -> string
In these forms, the content of +self+ is replaced by str.byteslice(str_index, str_length) or str.byteslice(str_range); however the substring of +str+ is not allocated as a new string.
Notes
Notes:
Merged: https://github.com/ruby/ruby/pull/7160
Diffstat (limited to 'test/ruby')
| -rw-r--r-- | test/ruby/test_string.rb | 98 |
1 files changed, 71 insertions, 27 deletions
diff --git a/test/ruby/test_string.rb b/test/ruby/test_string.rb index 2e66521df7..a916c8049e 100644 --- a/test/ruby/test_string.rb +++ b/test/ruby/test_string.rb @@ -3454,36 +3454,80 @@ CODE end def test_bytesplice - assert_bytesplice_raise(IndexError, S("hello"), -6, 0, "xxx") - assert_bytesplice_result("xxxhello", S("hello"), -5, 0, "xxx") - assert_bytesplice_result("xxxhello", S("hello"), 0, 0, "xxx") - assert_bytesplice_result("xxxello", S("hello"), 0, 1, "xxx") - assert_bytesplice_result("xxx", S("hello"), 0, 5, "xxx") - assert_bytesplice_result("xxx", S("hello"), 0, 6, "xxx") - - assert_bytesplice_raise(RangeError, S("hello"), -6...-6, "xxx") - assert_bytesplice_result("xxxhello", S("hello"), -5...-5, "xxx") - assert_bytesplice_result("xxxhello", S("hello"), 0...0, "xxx") - assert_bytesplice_result("xxxello", S("hello"), 0..0, "xxx") - assert_bytesplice_result("xxxello", S("hello"), 0...1, "xxx") - assert_bytesplice_result("xxxllo", S("hello"), 0..1, "xxx") - assert_bytesplice_result("xxx", S("hello"), 0..-1, "xxx") - assert_bytesplice_result("xxx", S("hello"), 0...5, "xxx") - assert_bytesplice_result("xxx", S("hello"), 0...6, "xxx") - - assert_bytesplice_raise(TypeError, S("hello"), 0, "xxx") - - assert_bytesplice_raise(IndexError, S("こんにちは"), -16, 0, "xxx") - assert_bytesplice_result("xxxこんにちは", S("こんにちは"), -15, 0, "xxx") - assert_bytesplice_result("xxxこんにちは", S("こんにちは"), 0, 0, "xxx") - assert_bytesplice_raise(IndexError, S("こんにちは"), 1, 0, "xxx") - assert_bytesplice_raise(IndexError, S("こんにちは"), 0, 1, "xxx") - assert_bytesplice_raise(IndexError, S("こんにちは"), 0, 2, "xxx") - assert_bytesplice_result("xxxんにちは", S("こんにちは"), 0, 3, "xxx") - assert_bytesplice_result("こんにちはxxx", S("こんにちは"), 15, 0, "xxx") + assert_bytesplice_raise(IndexError, S("hello"), -6, 0, "bye") + assert_bytesplice_result("byehello", S("hello"), -5, 0, "bye") + assert_bytesplice_result("byehello", S("hello"), 0, 0, "bye") + assert_bytesplice_result("byeello", S("hello"), 0, 1, "bye") + assert_bytesplice_result("bye", S("hello"), 0, 5, "bye") + assert_bytesplice_result("bye", S("hello"), 0, 6, "bye") + + assert_bytesplice_raise(IndexError, S("hello"), -5, 0, "bye", -4, 0) + assert_bytesplice_result("byehello", S("hello"), 0, 0, "bye", 0, 3) + assert_bytesplice_result("yehello", S("hello"), 0, 0, "bye", 1, 3) + assert_bytesplice_result("yehello", S("hello"), 0, 0, "bye", 1, 2) + assert_bytesplice_result("ehello", S("hello"), 0, 0, "bye", 2, 1) + assert_bytesplice_result("hello", S("hello"), 0, 0, "bye", 3, 0) + assert_bytesplice_result("hello", s = S("hello"), 0, 5, s, 0, 5) + assert_bytesplice_result("elloo", s = S("hello"), 0, 4, s, 1, 4) + assert_bytesplice_result("llolo", s = S("hello"), 0, 3, s, 2, 3) + assert_bytesplice_result("lollo", s = S("hello"), 0, 2, s, 3, 2) + assert_bytesplice_result("oello", s = S("hello"), 0, 1, s, 4, 1) + assert_bytesplice_result("hhell", s = S("hello"), 1, 4, s, 0, 4) + assert_bytesplice_result("hehel", s = S("hello"), 2, 3, s, 0, 3) + assert_bytesplice_result("helhe", s = S("hello"), 3, 2, s, 0, 2) + assert_bytesplice_result("hellh", s = S("hello"), 4, 1, s, 0, 1) + + assert_bytesplice_raise(RangeError, S("hello"), -6...-6, "bye") + assert_bytesplice_result("byehello", S("hello"), -5...-5, "bye") + assert_bytesplice_result("byehello", S("hello"), 0...0, "bye") + assert_bytesplice_result("byeello", S("hello"), 0..0, "bye") + assert_bytesplice_result("byeello", S("hello"), 0...1, "bye") + assert_bytesplice_result("byello", S("hello"), 0..1, "bye") + assert_bytesplice_result("bye", S("hello"), 0..-1, "bye") + assert_bytesplice_result("bye", S("hello"), 0...5, "bye") + assert_bytesplice_result("bye", S("hello"), 0...6, "bye") + assert_bytesplice_result("llolo", s = S("hello"), 0..2, s, 2..4) + + assert_bytesplice_raise(RangeError, S("hello"), -5...-5, "bye", -6...-6) + assert_bytesplice_result("byehello", S("hello"), -5...-5, "bye", 0..-1) + assert_bytesplice_result("byehello", S("hello"), 0...0, "bye", 0..-1) + assert_bytesplice_result("bhello", S("hello"), 0...0, "bye", 0..0) + assert_bytesplice_result("byhello", S("hello"), 0...0, "bye", 0..1) + assert_bytesplice_result("byehello", S("hello"), 0...0, "bye", 0..2) + assert_bytesplice_result("yehello", S("hello"), 0...0, "bye", 1..2) + + assert_bytesplice_raise(TypeError, S("hello"), 0, "bye") + + assert_bytesplice_raise(IndexError, S("こんにちは"), -16, 0, "bye") + assert_bytesplice_result("byeこんにちは", S("こんにちは"), -15, 0, "bye") + assert_bytesplice_result("byeこんにちは", S("こんにちは"), 0, 0, "bye") + assert_bytesplice_raise(IndexError, S("こんにちは"), 1, 0, "bye") + assert_bytesplice_raise(IndexError, S("こんにちは"), 0, 1, "bye") + assert_bytesplice_raise(IndexError, S("こんにちは"), 0, 2, "bye") + assert_bytesplice_result("byeんにちは", S("こんにちは"), 0, 3, "bye") + assert_bytesplice_result("こんにちはbye", S("こんにちは"), 15, 0, "bye") + + assert_bytesplice_raise(IndexError, S("こんにちは"), 0, 0, "さようなら", -16, 0) + assert_bytesplice_result("こんにちはさようなら", S("こんにちは"), 15, 0, "さようなら", 0, 15) + assert_bytesplice_result("さようなら", S("こんにちは"), 0, 15, "さようなら", 0, 15) + assert_bytesplice_result("さんにちは", S("こんにちは"), 0, 3, "さようなら", 0, 3) + assert_bytesplice_result("さようちは", S("こんにちは"), 0, 9, "さようなら", 0, 9) + assert_bytesplice_result("ようなちは", S("こんにちは"), 0, 9, "さようなら", 3, 9) + assert_bytesplice_result("ようちは", S("こんにちは"), 0, 9, "さようなら", 3, 6) + assert_bytesplice_result("ようならちは", S("こんにちは"), 0, 9, "さようなら", 3, 12) + assert_bytesplice_raise(IndexError, S("こんにちは"), 0, 15, "さようなら", -16, 0) + assert_bytesplice_raise(IndexError, S("こんにちは"), 0, 15, "さようなら", 1, 0) + assert_bytesplice_raise(IndexError, S("こんにちは"), 0, 15, "さようなら", 2, 0) + assert_bytesplice_raise(IndexError, S("こんにちは"), 0, 15, "さようなら", 0, 1) + assert_bytesplice_raise(IndexError, S("こんにちは"), 0, 15, "さようなら", 0, 2) + assert_bytesplice_result("にちはちは", s = S("こんにちは"), 0, 9, s, 6, 9) assert_bytesplice_result("", S(""), 0, 0, "") assert_bytesplice_result("xxx", S(""), 0, 0, "xxx") + + assert_bytesplice_raise(ArgumentError, S("hello"), 0, 5, "bye", 0) + assert_bytesplice_raise(ArgumentError, S("hello"), 0, 5, "bye", 0..-1) + assert_bytesplice_raise(ArgumentError, S("hello"), 0..-1, "bye", 0, 3) end private |
