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 2024/01/04 11:21:18 UTC

(incubator-pekko) branch main updated: fix ByteStringBuilder.addAll (#903)

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/incubator-pekko.git


The following commit(s) were added to refs/heads/main by this push:
     new d5381958c8 fix ByteStringBuilder.addAll (#903)
d5381958c8 is described below

commit d5381958c8ef7349aaf9b01e7c394c71aff39295
Author: PJ Fanning <pj...@users.noreply.github.com>
AuthorDate: Thu Jan 4 12:21:13 2024 +0100

    fix ByteStringBuilder.addAll (#903)
    
    * fix ByteStringBuilder.addAll
    
    * sort out tests for different scala versions
    
    * rework tests
    
    * rework unmanaged source dirs
---
 .../util/ByteStringBuilderScala213PlusSpec.scala   | 41 ++++++++++++++++++++++
 .../apache/pekko/util/ByteStringBuilderSpec.scala  | 38 ++++++++++++++++++++
 .../org/apache/pekko/util/ByteString.scala         |  2 +-
 .../scala-3/org/apache/pekko/util/ByteString.scala |  2 +-
 project/PekkoBuild.scala                           | 10 ++++++
 5 files changed, 91 insertions(+), 2 deletions(-)

diff --git a/actor-tests/src/test/scala-2.13+/org/apache/pekko/util/ByteStringBuilderScala213PlusSpec.scala b/actor-tests/src/test/scala-2.13+/org/apache/pekko/util/ByteStringBuilderScala213PlusSpec.scala
new file mode 100644
index 0000000000..7c7777d3a0
--- /dev/null
+++ b/actor-tests/src/test/scala-2.13+/org/apache/pekko/util/ByteStringBuilderScala213PlusSpec.scala
@@ -0,0 +1,41 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ *    http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.pekko.util
+
+import org.scalatest.matchers.should.Matchers
+import org.scalatest.wordspec.AnyWordSpec
+
+/**
+ * Extra tests to run for ByteStringBuilder when building with Scala 2.13+
+ */
+class ByteStringBuilderScala213PlusSpec extends AnyWordSpec with Matchers {
+  "ByteStringBuilder" should {
+    "handle addAll with LinearSeq" in {
+      val result: ByteString = ByteString.newBuilder.addAll(List[Byte]('a')).result()
+      result shouldEqual ByteString("a")
+    }
+    "handle addAll with IndexedSeq" in {
+      val result: ByteString = ByteString.newBuilder.addAll(Vector[Byte]('a')).result()
+      result shouldEqual ByteString("a")
+    }
+    "handle addAll with ByteString" in {
+      val result: ByteString = ByteString.newBuilder.addAll(ByteString("a")).result()
+      result shouldEqual ByteString("a")
+    }
+  }
+}
diff --git a/actor-tests/src/test/scala/org/apache/pekko/util/ByteStringBuilderSpec.scala b/actor-tests/src/test/scala/org/apache/pekko/util/ByteStringBuilderSpec.scala
new file mode 100644
index 0000000000..c878e59c5b
--- /dev/null
+++ b/actor-tests/src/test/scala/org/apache/pekko/util/ByteStringBuilderSpec.scala
@@ -0,0 +1,38 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ *    http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.pekko.util
+
+import org.scalatest.matchers.should.Matchers
+import org.scalatest.wordspec.AnyWordSpec
+
+class ByteStringBuilderSpec extends AnyWordSpec with Matchers {
+  "ByteStringBuilder" should {
+    "handle ++= with LinearSeq" in {
+      val result: ByteString = ByteString.newBuilder.++=(List[Byte]('a')).result()
+      result shouldEqual ByteString("a")
+    }
+    "handle ++= with IndexedSeq" in {
+      val result: ByteString = ByteString.newBuilder.++=(Vector[Byte]('a')).result()
+      result shouldEqual ByteString("a")
+    }
+    "handle ++= with ByteString" in {
+      val result: ByteString = ByteString.newBuilder.++=(ByteString("a")).result()
+      result shouldEqual ByteString("a")
+    }
+  }
+}
diff --git a/actor/src/main/scala-2.13/org/apache/pekko/util/ByteString.scala b/actor/src/main/scala-2.13/org/apache/pekko/util/ByteString.scala
index a03fac661a..6c3078851c 100644
--- a/actor/src/main/scala-2.13/org/apache/pekko/util/ByteString.scala
+++ b/actor/src/main/scala-2.13/org/apache/pekko/util/ByteString.scala
@@ -1190,7 +1190,7 @@ final class ByteStringBuilder extends Builder[Byte, ByteString] {
           _length += seq.length
         }
       case _ =>
-        super.++=(xs)
+        super.addAll(xs)
     }
     this
   }
diff --git a/actor/src/main/scala-3/org/apache/pekko/util/ByteString.scala b/actor/src/main/scala-3/org/apache/pekko/util/ByteString.scala
index 9dfa1990f7..dc4d8717dd 100644
--- a/actor/src/main/scala-3/org/apache/pekko/util/ByteString.scala
+++ b/actor/src/main/scala-3/org/apache/pekko/util/ByteString.scala
@@ -1190,7 +1190,7 @@ final class ByteStringBuilder extends Builder[Byte, ByteString] {
           _length += seq.length
         }
       case _ =>
-        super.++=(xs)
+        super.addAll(xs)
     }
     this
   }
diff --git a/project/PekkoBuild.scala b/project/PekkoBuild.scala
index 491ca445fd..b065547f03 100644
--- a/project/PekkoBuild.scala
+++ b/project/PekkoBuild.scala
@@ -166,6 +166,16 @@ object PekkoBuild {
         case _                       => Nil
       }
     },
+    // Adds a `src/test/scala-2.13+` source directory for code shared
+    // between Scala 2.13 and Scala 3
+    Test / unmanagedSourceDirectories ++= {
+      val sourceDir = (Test / sourceDirectory).value
+      CrossVersion.partialVersion(scalaVersion.value) match {
+        case Some((3, n))            => Seq(sourceDir / "scala-2.13+")
+        case Some((2, n)) if n >= 13 => Seq(sourceDir / "scala-2.13+")
+        case _                       => Nil
+      }
+    },
     ThisBuild / ivyLoggingLevel := UpdateLogging.Quiet,
     licenses := Seq(("Apache-2.0", url("https://www.apache.org/licenses/LICENSE-2.0.html"))),
     homepage := Some(url("https://pekko.apache.org/")),


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