mirror of
https://github.com/ruby/ruby.git
synced 2025-08-28 07:26:00 +02:00
Add String#bytesplice
This commit is contained in:
parent
b8e72bd2e9
commit
1107839a7f
Notes:
git
2022-03-18 11:51:26 +09:00
2 changed files with 115 additions and 0 deletions
|
@ -3395,6 +3395,50 @@ CODE
|
|||
assert_nil(S("こ").byterindex(S("こんにちは")))
|
||||
assert_nil(S("").byterindex(S("こんにちは")))
|
||||
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_result("", S(""), 0, 0, "")
|
||||
assert_bytesplice_result("xxx", S(""), 0, 0, "xxx")
|
||||
end
|
||||
|
||||
private
|
||||
|
||||
def assert_bytesplice_result(expected, s, *args)
|
||||
assert_equal(args.last, s.send(:bytesplice, *args))
|
||||
assert_equal(expected, s)
|
||||
end
|
||||
|
||||
def assert_bytesplice_raise(e, s, *args)
|
||||
assert_raise(e) { s.send(:bytesplice, *args) }
|
||||
end
|
||||
end
|
||||
|
||||
class TestString2 < TestString
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue