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/")),