diff --git a/actor-tests/src/test/scala/org/apache/pekko/util/ByteStringSpec.scala b/actor-tests/src/test/scala/org/apache/pekko/util/ByteStringSpec.scala index 81ef0cca99..8dcdf626ef 100644 --- a/actor-tests/src/test/scala/org/apache/pekko/util/ByteStringSpec.scala +++ b/actor-tests/src/test/scala/org/apache/pekko/util/ByteStringSpec.scala @@ -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)