add tests for ByteStrings with non-zero startIndex (#2158)

This commit is contained in:
PJ Fanning 2025-09-06 15:35:16 +01:00 committed by GitHub
parent c708891504
commit 9b6797f3d8
No known key found for this signature in database
GPG key ID: B5690EEEBB952194

View file

@ -701,6 +701,16 @@ class ByteStringSpec extends AnyWordSpec with Matchers with Checkers {
byteString1.indexOf('a', 0) should ===(0)
byteString1.indexOf('a', 1) should ===(-1)
val array = Array[Byte]('x', 'y', 'z', 'a', 'b', 'c')
val byteString2 = ByteString1(array, 3, 3)
byteString2.indexOf('x', -1) should ===(-1)
byteString2.indexOf('x', 0) should ===(-1)
byteString2.indexOf('x', 1) should ===(-1)
byteString2.indexOf('x', 4) should ===(-1)
byteString2.indexOf('a', -1) should ===(0)
byteString2.indexOf('a', 0) should ===(0)
byteString2.indexOf('a', 1) should ===(-1)
val byteStrings = ByteStrings(ByteString1.fromString("abc"), ByteString1.fromString("efg"))
byteStrings.indexOf('c', -1) should ===(2)
byteStrings.indexOf('c', 0) should ===(2)
@ -755,6 +765,19 @@ class ByteStringSpec extends AnyWordSpec with Matchers with Checkers {
byteString1.lastIndexOf('b', 1) should ===(1)
byteString1.lastIndexOf('b', 0) should ===(-1)
val array = Array[Byte]('x', 'y', 'z', 'a', 'b', 'b')
val byteString2 = ByteString1(array, 3, 3)
byteString2.lastIndexOf('x', -1) should ===(-1)
byteString2.lastIndexOf('x', 0) should ===(-1)
byteString2.lastIndexOf('x', 3) should ===(-1)
byteString2.lastIndexOf('x', 4) should ===(-1)
byteString2.lastIndexOf('a', -1) should ===(-1)
byteString2.lastIndexOf('a', 0) should ===(0)
byteString2.lastIndexOf('a', 1) should ===(0)
byteString2.lastIndexOf('b', 2) should ===(2)
byteString2.lastIndexOf('b', 1) should ===(1)
byteString2.lastIndexOf('b', 0) should ===(-1)
val byteStrings = ByteStrings(ByteString1.fromString("abb"), ByteString1.fromString("efg"))
byteStrings.lastIndexOf('e', 6) should ===(3)
byteStrings.lastIndexOf('e', 4) should ===(3)
@ -789,6 +812,16 @@ class ByteStringSpec extends AnyWordSpec with Matchers with Checkers {
byteString1.indexOf('c'.toByte) should ===(2)
byteString1.indexOf('d'.toByte) should ===(-1)
val array = Array[Byte]('x', 'y', 'z', 'a', 'b', 'c')
val byteString2 = ByteString1(array, 3, 3)
byteString2.indexOf('x'.toByte, -1) should ===(-1)
byteString2.indexOf('x'.toByte, 0) should ===(-1)
byteString2.indexOf('x'.toByte, 1) should ===(-1)
byteString2.indexOf('x'.toByte, 4) should ===(-1)
byteString2.indexOf('a'.toByte, -1) should ===(0)
byteString2.indexOf('a'.toByte, 0) should ===(0)
byteString2.indexOf('a'.toByte, 1) should ===(-1)
val byteStrings = ByteStrings(ByteString1.fromString("abc"), ByteString1.fromString("efg"))
byteStrings.indexOf('a'.toByte) should ===(0)
byteStrings.indexOf('c'.toByte) should ===(2)