You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@pekko.apache.org by fa...@apache.org on 2025/09/26 12:12:32 UTC

(pekko) branch main updated: add containsSlice tests (#2275)

This is an automated email from the ASF dual-hosted git repository.

fanningpj pushed a commit to branch main
in repository https://gitbox.apache.org/repos/asf/pekko.git


The following commit(s) were added to refs/heads/main by this push:
     new 295e15d144 add containsSlice tests (#2275)
295e15d144 is described below

commit 295e15d14466a69fec198f928d64b78ea5718d5a
Author: PJ Fanning <pj...@users.noreply.github.com>
AuthorDate: Fri Sep 26 13:12:27 2025 +0100

    add containsSlice tests (#2275)
---
 .../org/apache/pekko/util/ByteStringSpec.scala     | 28 ++++++++++++++++++++++
 1 file changed, 28 insertions(+)

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 4a3044f6ba..0aa077ffa1 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
@@ -996,6 +996,34 @@ class ByteStringSpec extends AnyWordSpec with Matchers with Checkers {
       verify(byteString.copyToArray(_, 2, 3))(0, 0, 1)
       verify(byteString.copyToArray(_, 3, 3))(0, 0, 0)
     }
+    "containsSlice" in {
+      val slice0 = ByteString1.fromString("xyz")
+      val slice1 = ByteString1.fromString("xyzabc")
+      val notSlice = ByteString1.fromString("12345")
+      val byteStringLong = ByteString1.fromString("abcdefghijklmnopqrstuvwxyz")
+      val byteStrings = ByteStrings(byteStringLong, byteStringLong)
+      byteStringLong.containsSlice(slice0) should ===(true)
+      byteStringLong.containsSlice(slice1) should ===(false)
+      byteStringLong.containsSlice(notSlice) should ===(false)
+
+      byteStrings.containsSlice(slice0) should ===(true)
+      byteStrings.containsSlice(slice1) should ===(true)
+      byteStrings.containsSlice(notSlice) should ===(false)
+    }
+    "indexOfSlice" in {
+      val slice0 = ByteString1.fromString("xyz")
+      val slice1 = ByteString1.fromString("xyzabc")
+      val notSlice = ByteString1.fromString("12345")
+      val byteStringLong = ByteString1.fromString("abcdefghijklmnopqrstuvwxyz")
+      val byteStrings = ByteStrings(byteStringLong, byteStringLong)
+      byteStringLong.indexOfSlice(slice0) should ===(23)
+      byteStringLong.indexOfSlice(slice1) should ===(-1)
+      byteStringLong.indexOfSlice(notSlice) should ===(-1)
+
+      byteStrings.indexOfSlice(slice0) should ===(23)
+      byteStrings.indexOfSlice(slice1) should ===(23)
+      byteStrings.indexOfSlice(notSlice) should ===(-1)
+    }
   }
 
   "A ByteString" must {


---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@pekko.apache.org
For additional commands, e-mail: commits-help@pekko.apache.org