Move tests related to `getbyte`, `setbyte`, byteslice` to core.
MODIFY
mrbgems/mruby-string-ext/test/string.rb
mrbgems/mruby-string-ext/test/string.rb
@@ -10,85 +10,6 @@ def assert_upto(exp, receiver, *args)
assert_equal exp, act
end
-assert('String#getbyte') do
- str1 = "hello"
- bytes1 = [104, 101, 108, 108, 111]
- assert_equal bytes1[0], str1.getbyte(0)
- assert_equal bytes1[-1], str1.getbyte(-1)
- assert_equal bytes1[6], str1.getbyte(6)
-
- str2 = "\xFF"
- bytes2 = [0xFF]
- assert_equal bytes2[0], str2.getbyte(0)
-end
-
-assert('String#setbyte') do
- str1 = "hello"
- h = "H".getbyte(0)
- str1.setbyte(0, h)
- assert_equal(h, str1.getbyte(0))
- assert_equal("Hello", str1)
-end
-
-assert('String#byteslice') do
- str1 = "hello"
- str2 = "\u3042ab" # "\xE3\x81\x82ab"
-
- assert_equal("h", str1.byteslice(0))
- assert_equal("e", str1.byteslice(1))
- assert_equal(nil, str1.byteslice(5))
- assert_equal("o", str1.byteslice(-1))
- assert_equal(nil, str1.byteslice(-6))
- assert_equal("\xE3", str2.byteslice(0))
- assert_equal("\x81", str2.byteslice(1))
- assert_equal(nil, str2.byteslice(5))
- assert_equal("b", str2.byteslice(-1))
- assert_equal(nil, str2.byteslice(-6))
-
- assert_equal("", str1.byteslice(0, 0))
- assert_equal(str1, str1.byteslice(0, 6))
- assert_equal("el", str1.byteslice(1, 2))
- assert_equal("", str1.byteslice(5, 1))
- assert_equal("o", str1.byteslice(-1, 6))
- assert_equal(nil, str1.byteslice(-6, 1))
- assert_equal(nil, str1.byteslice(0, -1))
- assert_equal("", str2.byteslice(0, 0))
- assert_equal(str2, str2.byteslice(0, 6))
- assert_equal("\x81\x82", str2.byteslice(1, 2))
- assert_equal("", str2.byteslice(5, 1))
- assert_equal("b", str2.byteslice(-1, 6))
- assert_equal(nil, str2.byteslice(-6, 1))
- assert_equal(nil, str2.byteslice(0, -1))
-
- assert_equal("ell", str1.byteslice(1..3))
- assert_equal("el", str1.byteslice(1...3))
- assert_equal("h", str1.byteslice(0..0))
- assert_equal("", str1.byteslice(5..0))
- assert_equal("o", str1.byteslice(4..5))
- assert_equal(nil, str1.byteslice(6..0))
- assert_equal("", str1.byteslice(-1..0))
- assert_equal("llo", str1.byteslice(-3..5))
- assert_equal("\x81\x82a", str2.byteslice(1..3))
- assert_equal("\x81\x82", str2.byteslice(1...3))
- assert_equal("\xE3", str2.byteslice(0..0))
- assert_equal("", str2.byteslice(5..0))
- assert_equal("b", str2.byteslice(4..5))
- assert_equal(nil, str2.byteslice(6..0))
- assert_equal("", str2.byteslice(-1..0))
- assert_equal("\x82ab", str2.byteslice(-3..5))
-
- assert_raise(ArgumentError) { str1.byteslice }
- assert_raise(ArgumentError) { str1.byteslice(1, 2, 3) }
- assert_raise(TypeError) { str1.byteslice("1") }
- assert_raise(TypeError) { str1.byteslice("1", 2) }
- assert_raise(TypeError) { str1.byteslice(1, "2") }
- assert_raise(TypeError) { str1.byteslice(1..2, 3) }
-
- skip unless Object.const_defined?(:Float)
- assert_equal("o", str1.byteslice(4.0))
- assert_equal("\x82ab", str2.byteslice(2.0, 3.0))
-end
-
assert('String#dump') do
assert_equal("\"\\x00\"", "\0".dump)
assert_equal("\"foo\"", "foo".dump)

MODIFY
test/t/string.rb
test/t/string.rb
@@ -784,3 +784,82 @@ assert('String literal concatenation') do
assert_equal 3, ('A' "B" 'C').size
assert_equal 4, (%(A) "B#{?C}" "D").size
end
+
+assert('String#getbyte') do
+ str1 = "hello"
+ bytes1 = [104, 101, 108, 108, 111]
+ assert_equal bytes1[0], str1.getbyte(0)
+ assert_equal bytes1[-1], str1.getbyte(-1)
+ assert_equal bytes1[6], str1.getbyte(6)
+
+ str2 = "\xFF"
+ bytes2 = [0xFF]
+ assert_equal bytes2[0], str2.getbyte(0)
+end
+
+assert('String#setbyte') do
+ str1 = "hello"
+ h = "H".getbyte(0)
+ str1.setbyte(0, h)
+ assert_equal(h, str1.getbyte(0))
+ assert_equal("Hello", str1)
+end
+
+assert('String#byteslice') do
+ str1 = "hello"
+ str2 = "\u3042ab" # "\xE3\x81\x82ab"
+
+ assert_equal("h", str1.byteslice(0))
+ assert_equal("e", str1.byteslice(1))
+ assert_equal(nil, str1.byteslice(5))
+ assert_equal("o", str1.byteslice(-1))
+ assert_equal(nil, str1.byteslice(-6))
+ assert_equal("\xE3", str2.byteslice(0))
+ assert_equal("\x81", str2.byteslice(1))
+ assert_equal(nil, str2.byteslice(5))
+ assert_equal("b", str2.byteslice(-1))
+ assert_equal(nil, str2.byteslice(-6))
+
+ assert_equal("", str1.byteslice(0, 0))
+ assert_equal(str1, str1.byteslice(0, 6))
+ assert_equal("el", str1.byteslice(1, 2))
+ assert_equal("", str1.byteslice(5, 1))
+ assert_equal("o", str1.byteslice(-1, 6))
+ assert_equal(nil, str1.byteslice(-6, 1))
+ assert_equal(nil, str1.byteslice(0, -1))
+ assert_equal("", str2.byteslice(0, 0))
+ assert_equal(str2, str2.byteslice(0, 6))
+ assert_equal("\x81\x82", str2.byteslice(1, 2))
+ assert_equal("", str2.byteslice(5, 1))
+ assert_equal("b", str2.byteslice(-1, 6))
+ assert_equal(nil, str2.byteslice(-6, 1))
+ assert_equal(nil, str2.byteslice(0, -1))
+
+ assert_equal("ell", str1.byteslice(1..3))
+ assert_equal("el", str1.byteslice(1...3))
+ assert_equal("h", str1.byteslice(0..0))
+ assert_equal("", str1.byteslice(5..0))
+ assert_equal("o", str1.byteslice(4..5))
+ assert_equal(nil, str1.byteslice(6..0))
+ assert_equal("", str1.byteslice(-1..0))
+ assert_equal("llo", str1.byteslice(-3..5))
+ assert_equal("\x81\x82a", str2.byteslice(1..3))
+ assert_equal("\x81\x82", str2.byteslice(1...3))
+ assert_equal("\xE3", str2.byteslice(0..0))
+ assert_equal("", str2.byteslice(5..0))
+ assert_equal("b", str2.byteslice(4..5))
+ assert_equal(nil, str2.byteslice(6..0))
+ assert_equal("", str2.byteslice(-1..0))
+ assert_equal("\x82ab", str2.byteslice(-3..5))
+
+ assert_raise(ArgumentError) { str1.byteslice }
+ assert_raise(ArgumentError) { str1.byteslice(1, 2, 3) }
+ assert_raise(TypeError) { str1.byteslice("1") }
+ assert_raise(TypeError) { str1.byteslice("1", 2) }
+ assert_raise(TypeError) { str1.byteslice(1, "2") }
+ assert_raise(TypeError) { str1.byteslice(1..2, 3) }
+
+ skip unless Object.const_defined?(:Float)
+ assert_equal("o", str1.byteslice(4.0))
+ assert_equal("\x82ab", str2.byteslice(2.0, 3.0))
+end

Move tests related to `getbyte`, `setbyte`, byteslice` to core.