diff --git a/.travis.yml b/.travis.yml index 933c6cc4..1c8b2a1b 100644 --- a/.travis.yml +++ b/.travis.yml @@ -12,7 +12,7 @@ scala: - 2.12.6 - 2.13.0-M4 jdk: - - openjdk6 + - openjdk7 - oraclejdk8 env: global: @@ -23,25 +23,53 @@ env: # SONA_PASS - secure: "m0Fw/eH7RXJJoBTfqV6CMd7kaIN2pRPnQPNXJGb546UjqYAlYTkfjvVrWpsgpisRBptI1FEHn24yGbgAHjIes/4un/O62K66I0BffL8PbdeHeNcDjSrTesKEqage2mQfGOiqccVsmkgiKeXNYL8tPZRmPQQ3XZ97mS1SXWlqAJSMW6HfNnvqW14Gdb/snR6I8lQ2o5tRnLerWPnI96pp+xjZca2lD4XDvH2wLJXXLmYY61e23ZYzZMepxBxhGa7js3YTYzCWNrOfBLjFJ5nwRxbjR0WMuz5z5Gdy715WtguKS4Fffd/GJHycLROBU9LCAQDMTxMFvqzFqVFpfq0BuTmmkXFXj+a7dO+ABG0RfoDfoMjn7pHwyHNCZyMMuR1HCjMkbGFwC+Zme2UAYNivtcsuWWeMuypwjyqjfFfNns4FHJ0SXFtC/6+OJkAuUdbEJKReYWKWEsP5SnCH/8PLlc+uUl3tjQkFLc1sOAyx9cTWyBErwuJXhgTrjT9AWvO+fvhcm8z/p5+aaF/U9GIrzPqziX4hGjzc/WC+rsFJSiBDlFQl7br+m8WWs7/wuXqPGXmhf0BNQViDi7fZndDHcY3p3T0An05d/IMKjCUrgLDlJi6VYs9XN7S8ay6MH+XTwIsJGSxtGjfEO4rHGIjtR2GRr8TqdNfnpsI3ucbia1Y=" matrix: - - SCALAJS_VERSION= - - SCALAJS_VERSION=0.6.23 - - SCALAJS_VERSION=1.0.0-M3 + - SCALA_TARGET=jvm + - SCALA_TARGET=js SCALAJS_VERSION=0.6.23 + - SCALA_TARGET=js SCALAJS_VERSION=1.0.0-M3 matrix: exclude: - - jdk: openjdk6 + # > 2.12 requires jdk8 + - jdk: openjdk7 scala: 2.12.6 - - jdk: openjdk6 + + - jdk: openjdk7 scala: 2.13.0-M4 + + # ? - jdk: oraclejdk8 scala: 2.11.12 + + # 2.13.0-M4 is not available in Scala.js 1.0.0-M3 - scala: 2.13.0-M4 - env: SCALAJS_VERSION=1.0.0-M3 + env: SCALA_TARGET=js SCALAJS_VERSION=1.0.0-M3 + + # run migration test include: - scala: 2.12.6 jdk: oraclejdk8 env: TEST_SCALAFIX=true + - scala: 2.11.12 + jdk: oraclejdk8 + env: SCALA_TARGET=native + sudo: required + before_install: + - curl https://raw.githubusercontent.com/scala-native/scala-native/master/scripts/travis_setup.sh | bash - + +# | jdk | scala | scala target | scala target version | scalafix test | +# | ----------- | --------- | ------------ | -------------------- |---------------| +# | openjdk7 | 2.11.12 | jvm | | | +# | openjdk7 | 2.11.12 | js | 0.6.23 | | +# | openjdk7 | 2.11.12 | js | 1.0.0-M3 | | +# | oraclejdk8 | 2.12.6 | jvm | | | +# | oraclejdk8 | 2.12.6 | js | 0.6.23 | | +# | oraclejdk8 | 2.12.6 | js | 1.0.0-M3 | | +# | oraclejdk8 | 2.13.0-M4 | jvm | | | +# | oraclejdk8 | 2.13.0-M4 | js | 0.6.23 | | +# | oraclejdk8 | 2.11.12 | native | 0.3.7 | | +# | oraclejdk8 | 2.12.6 | jvm | | true | + before_script: ./checkCLA.sh script: # work around https://github.com/travis-ci/travis-ci/issues/9713 diff --git a/admin/build.sh b/admin/build.sh index 82c69809..1a700243 100755 --- a/admin/build.sh +++ b/admin/build.sh @@ -23,11 +23,24 @@ if [[ "$TEST_SCALAFIX" == "true" ]]; then exit 0 fi -if [ "$SCALAJS_VERSION" = "" ]; then - projectPrefix="scala-collection-compat" -else - projectPrefix="scala-collection-compatJS" -fi +case "$SCALA_TARGET" in + jvm) + targetSuffix="" + ;; + + js) + targetSuffix="JS" + ;; + + native) + targetSuffix="Native" + ;; + *) + echo $"SCALA_TARGET: $SCALA_TARGET {jvm|js|native}" + exit 1 +esac + +projectPrefix="scala-collection-compat$targetSuffix" verPat="[0-9]+\.[0-9]+\.[0-9]+(-[A-Za-z0-9-]+)?" tagPat="^v$verPat(#.*)?$" @@ -52,4 +65,4 @@ if [[ "$TRAVIS_TAG" =~ $tagPat ]]; then fi fi -sbt "++$TRAVIS_SCALA_VERSION" "$publishVersion" "$projectPrefix/clean" "$projectPrefix/test" "$projectPrefix/publishLocal" "$publishTask" +sbt -Dhttps.protocols=TLSv1.2 "++$TRAVIS_SCALA_VERSION" "$publishVersion" "$projectPrefix/clean" "$projectPrefix/test" "$projectPrefix/publishLocal" "$publishTask" diff --git a/admin/nix-run.sh b/admin/nix-run.sh new file mode 100755 index 00000000..7e5f263f --- /dev/null +++ b/admin/nix-run.sh @@ -0,0 +1,5 @@ +#!/usr/bin/env bash + +HERE="`dirname $0`" + +nix-shell $HERE/scala-native.nix -A clangEnv \ No newline at end of file diff --git a/admin/scala-native.nix b/admin/scala-native.nix new file mode 100644 index 00000000..dca052c7 --- /dev/null +++ b/admin/scala-native.nix @@ -0,0 +1,23 @@ +let + pkgs = import {}; + stdenv = pkgs.stdenv; +in rec { + clangEnv = stdenv.mkDerivation rec { + name = "clang-env"; + shellHook = '' + alias cls=clear + ''; + CLANG_PATH = pkgs.clang + "/bin/clang"; + CLANGPP_PATH = pkgs.clang + "/bin/clang++"; + buildInputs = with pkgs; [ + stdenv + sbt + openjdk + boehmgc + libunwind + re2 + clang + zlib + ]; + }; +} \ No newline at end of file diff --git a/build.sbt b/build.sbt index bf43cc3d..38d756b9 100644 --- a/build.sbt +++ b/build.sbt @@ -5,9 +5,16 @@ inThisBuild(Seq( crossScalaVersions := Seq("2.12.6", "2.13.0-M4", "2.11.12") )) -disablePlugins(JvmPlugin) +lazy val root = project + .in(file(".")) + .aggregate( + `scala-collection-compatJVM`, + `scala-collection-compatJS`, + `scala-collection-compatNative` + ) -lazy val `scala-collection-compat` = crossProject(JSPlatform, JVMPlatform) + +lazy val `scala-collection-compat` = crossProject(JSPlatform, JVMPlatform, NativePlatform) .withoutSuffixFor(JVMPlatform) .crossType(CrossType.Pure) .in(file(".")) @@ -17,6 +24,8 @@ lazy val `scala-collection-compat` = crossProject(JSPlatform, JVMPlatform) name := "scala-collection-compat", version := "0.1-SNAPSHOT", scalacOptions ++= Seq("-feature", "-language:higherKinds", "-language:implicitConversions"), + libraryDependencies += "com.lihaoyi" %%% "utest" % "0.6.4", + testFrameworks += new TestFramework("utest.runner.Framework"), unmanagedSourceDirectories in Compile += { val sharedSourceDir = baseDirectory.value.getParentFile / "src/main" if (scalaVersion.value.startsWith("2.13.")) sharedSourceDir / "scala-2.13" @@ -24,8 +33,7 @@ lazy val `scala-collection-compat` = crossProject(JSPlatform, JVMPlatform) } ) .jvmSettings( - OsgiKeys.exportPackage := Seq(s"scala.collection.compat.*;version=${version.value}"), - libraryDependencies += "com.novocode" % "junit-interface" % "0.11" % "test" + OsgiKeys.exportPackage := Seq(s"scala.collection.compat.*;version=${version.value}") ) .jsSettings( scalacOptions += { @@ -35,7 +43,10 @@ lazy val `scala-collection-compat` = crossProject(JSPlatform, JVMPlatform) }, fork in Test := false // Scala.js cannot run forked tests ) - .jsConfigure(_.enablePlugins(ScalaJSJUnitPlugin)) + .nativeSettings( + scalaVersion := "2.11.12" + ) lazy val `scala-collection-compatJVM` = `scala-collection-compat`.jvm lazy val `scala-collection-compatJS` = `scala-collection-compat`.js +lazy val `scala-collection-compatNative` = `scala-collection-compat`.native diff --git a/project/plugins.sbt b/project/plugins.sbt index 0670f0ee..8fb4e558 100644 --- a/project/plugins.sbt +++ b/project/plugins.sbt @@ -5,9 +5,12 @@ else // see https://github.com/scala/sbt-scala-module/issues/35 Seq(addSbtPlugin("com.typesafe.sbt" % "sbt-osgi" % "0.9.3")) -val scalaJSVersion = - Option(System.getenv("SCALAJS_VERSION")).filter(_.nonEmpty).getOrElse("0.6.23") - -addSbtPlugin("org.scala-js" % "sbt-scalajs" % scalaJSVersion) -addSbtPlugin("org.portable-scala" % "sbt-scalajs-crossproject" % "0.4.0") addSbtPlugin("org.scala-lang.modules" % "sbt-scala-module" % "1.0.14") + + +val scalaJSVersion = Option(System.getenv("SCALAJS_VERSION")).filter(_.nonEmpty).getOrElse("0.6.23") + +addSbtPlugin("org.scala-js" % "sbt-scalajs" % scalaJSVersion) +addSbtPlugin("org.portable-scala" % "sbt-scalajs-crossproject" % "0.5.0") +addSbtPlugin("org.portable-scala" % "sbt-scala-native-crossproject" % "0.5.0") +addSbtPlugin("org.scala-native" % "sbt-scala-native" % "0.3.7") \ No newline at end of file diff --git a/src/test/scala/test/scala/collection/ArraySeqTest.scala b/src/test/scala/test/scala/collection/ArraySeqTest.scala index beac7289..5adc652b 100644 --- a/src/test/scala/test/scala/collection/ArraySeqTest.scala +++ b/src/test/scala/test/scala/collection/ArraySeqTest.scala @@ -1,60 +1,60 @@ package test.scala.collection -import org.junit.{Assert, Test} +import utest._ import scala.collection.compat.immutable.ArraySeq // The unmodified ArraySeqTest from collection-strawman -class ArraySeqTest { - @Test - def slice(): Unit = { - - implicit def array2ArraySeq[T](array: Array[T]): ArraySeq[T] = - ArraySeq.unsafeWrapArray(array) - - val booleanArray = Array(true, false, true, false) - check(booleanArray, Array(true, false), Array(false, true)) - - val shortArray = Array(1.toShort, 2.toShort, 3.toShort, 4.toShort) - check(shortArray, Array(1.toShort, 2.toShort), Array(2.toShort, 3.toShort)) - - val intArray = Array(1, 2, 3, 4) - check(intArray, Array(1, 2), Array(2, 3)) - - val longArray = Array(1L, 2L, 3L, 4L) - check(longArray, Array(1L, 2L), Array(2L, 3L)) - - val byteArray = Array(1.toByte, 2.toByte, 3.toByte, 4.toByte) - check(byteArray, Array(1.toByte, 2.toByte), Array(2.toByte, 3.toByte)) - - val charArray = Array('1', '2', '3', '4') - check(charArray, Array('1', '2'), Array('2', '3')) - - val doubleArray = Array(1.0, 2.0, 3.0, 4.0) - check(doubleArray, Array(1.0, 2.0), Array(2.0, 3.0)) - - val floatArray = Array(1.0f, 2.0f, 3.0f, 4.0f) - check(floatArray, Array(1.0f, 2.0f), Array(2.0f, 3.0f)) - - val refArray = Array("1", "2", "3", "4") - check[String](refArray, Array("1", "2"), Array("2", "3")) - - def unit1(): Unit = {} - def unit2(): Unit = {} - Assert.assertEquals(unit1, unit2) - // unitArray is actually an instance of Immutable[BoxedUnit], the check to which is actually checked slice - // implementation of ofRef - val unitArray: ArraySeq[Unit] = Array(unit1, unit2, unit1, unit2) - check(unitArray, Array(unit1, unit1), Array(unit1, unit1)) +object ArraySeqTest extends TestSuite{ + val tests = Tests{ + 'slice - { + implicit def array2ArraySeq[T](array: Array[T]): ArraySeq[T] = + ArraySeq.unsafeWrapArray(array) + + val booleanArray = Array(true, false, true, false) + check(booleanArray, Array(true, false), Array(false, true)) + + val shortArray = Array(1.toShort, 2.toShort, 3.toShort, 4.toShort) + check(shortArray, Array(1.toShort, 2.toShort), Array(2.toShort, 3.toShort)) + + val intArray = Array(1, 2, 3, 4) + check(intArray, Array(1, 2), Array(2, 3)) + + val longArray = Array(1L, 2L, 3L, 4L) + check(longArray, Array(1L, 2L), Array(2L, 3L)) + + val byteArray = Array(1.toByte, 2.toByte, 3.toByte, 4.toByte) + check(byteArray, Array(1.toByte, 2.toByte), Array(2.toByte, 3.toByte)) + + val charArray = Array('1', '2', '3', '4') + check(charArray, Array('1', '2'), Array('2', '3')) + + val doubleArray = Array(1.0, 2.0, 3.0, 4.0) + check(doubleArray, Array(1.0, 2.0), Array(2.0, 3.0)) + + val floatArray = Array(1.0f, 2.0f, 3.0f, 4.0f) + check(floatArray, Array(1.0f, 2.0f), Array(2.0f, 3.0f)) + + val refArray = Array("1", "2", "3", "4") + check[String](refArray, Array("1", "2"), Array("2", "3")) + + def unit1(): Unit = {} + def unit2(): Unit = {} + + // unitArray is actually an instance of Immutable[BoxedUnit], the check to which is actually checked slice + // implementation of ofRef + val unitArray: ArraySeq[Unit] = Array(unit1, unit2, unit1, unit2) + check(unitArray, Array(unit1, unit1), Array(unit1, unit1)) + } } private def check[T](array: ArraySeq[T], expectedSliceResult1: ArraySeq[T], expectedSliceResult2: ArraySeq[T]) { - Assert.assertEquals(array, array.slice(-1, 4)) - Assert.assertEquals(array, array.slice(0, 5)) - Assert.assertEquals(array, array.slice(-1, 5)) - Assert.assertEquals(expectedSliceResult1, array.slice(0, 2)) - Assert.assertEquals(expectedSliceResult2, array.slice(1, 3)) - Assert.assertEquals(ArraySeq.empty[Nothing], array.slice(1, 1)) - Assert.assertEquals(ArraySeq.empty[Nothing], array.slice(2, 1)) + assert(array == array.slice(-1, 4)) + assert(array == array.slice(0, 5)) + assert(array == array.slice(-1, 5)) + assert(expectedSliceResult1 == array.slice(0, 2)) + assert(expectedSliceResult2 == array.slice(1, 3)) + assert(ArraySeq.empty[Nothing] == array.slice(1, 1)) + assert(ArraySeq.empty[Nothing] == array.slice(2, 1)) } } \ No newline at end of file diff --git a/src/test/scala/test/scala/collection/BuildFromTest.scala b/src/test/scala/test/scala/collection/BuildFromTest.scala index 5904f003..9cee6210 100644 --- a/src/test/scala/test/scala/collection/BuildFromTest.scala +++ b/src/test/scala/test/scala/collection/BuildFromTest.scala @@ -1,6 +1,6 @@ package test.scala.collection -import org.junit.Test +import utest._ import scala.collection.compat._ import scala.collection.immutable.{HashMap, TreeMap, TreeSet} @@ -8,7 +8,7 @@ import scala.collection.mutable.{ArrayBuffer, Builder, ListBuffer} import scala.collection.{BitSet, SortedMap, SortedSet, immutable, mutable} // Tests copied from the 2.13 scala-library -class BuildFromTest { +object BuildFromTest extends TestSuite{ // Using BuildFrom to abstract over both and also allow building arbitrary collection types def optionSequence2[CC[X] <: Iterable[X], A, To](xs: CC[Option[A]])(implicit bf: BuildFrom[CC[Option[A]], A, To]): Option[To] = @@ -31,49 +31,6 @@ class BuildFromTest { case (_ , Left(a)) => Left(a) }.right.map(_.result()) - @Test - def optionSequence2Test: Unit = { - val xs1 = List(Some(1), None, Some(2)) - val o1 = optionSequence2(xs1) - val o1t: Option[List[Int]] = o1 - - val xs2 = TreeSet(Some("foo"), Some("bar"), None) - val o2 = optionSequence2(xs2) - // Not working: the resolved implicit BuildFrom results in a SortedSet instead of a TreeSet - // val o2t: Option[TreeSet[String]] = o2 - val o2t: Option[SortedSet[String]] = o2 - - // Breakout-like use case from https://github.com/scala/scala/pull/5233: - val xs4 = List[Option[(Int, String)]](Some((1 -> "a")), Some((2 -> "b"))) - val o4 = optionSequence2(xs4)(TreeMap) - val o4t: Option[TreeMap[Int, String]] = o4 - } - - @Test - def optionSequence3Test: Unit = { - val xs1 = List(Some(1), None, Some(2)) - val o1 = optionSequence3(xs1) - val o1t: Option[List[Int]] = o1 - - val xs2 = TreeSet(Some("foo"), Some("bar"), None) - val o2 = optionSequence3(xs2) - // Not working: the resolved implicit BuildFrom results in a SortedSet instead of a TreeSet - // val o2t: Option[TreeSet[String]] = o2 - val o2t: Option[SortedSet[String]] = o2 - - // Breakout-like use case from https://github.com/scala/scala/pull/5233: - val xs4 = List[Option[(Int, String)]](Some((1 -> "a")), Some((2 -> "b"))) - val o4 = optionSequence3(xs4)(TreeMap) // same syntax as in `.to` - val o4t: Option[TreeMap[Int, String]] = o4 - } - - @Test - def eitherSequenceTest: Unit = { - val xs3 = ListBuffer(Right("foo"), Left(0), Right("bar")) - val e1 = eitherSequence(xs3) - val e1t: Either[Int, ListBuffer[String]] = e1 - } - // From https://github.com/scala/collection-strawman/issues/44 def flatCollect[A, B, To](coll: Iterable[A])(f: PartialFunction[A, IterableOnce[B]]) (implicit bf: BuildFrom[coll.type, B, To]): To = { @@ -93,40 +50,6 @@ class BuildFromTest { (left.result(), right.result()) } - @Test - def flatCollectTest: Unit = { - val xs1 = List(1, 2, 3) - val xs2 = flatCollect(xs1) { case 2 => ArrayBuffer("foo", "bar") } - val xs3: List[String] = xs2 - - val xs4 = TreeMap((1, "1"), (2, "2")) - val xs5 = flatCollect(xs4) { case (2, v) => List((v, v)) } - val xs6: TreeMap[String, String] = xs5 - - val xs7 = HashMap((1, "1"), (2, "2")) - val xs8 = flatCollect(xs7) { case (2, v) => List((v, v)) } - val xs9: HashMap[String, String] = xs8 - - val xs10 = TreeSet(1, 2, 3) - val xs11 = flatCollect(xs10) { case 2 => List("foo", "bar") } - // Not working: the resolved implicit BuildFrom results in a SortedSet instead of a TreeSet - // val xs12: TreeSet[String] = xs11 - val xs12: SortedSet[String] = xs11 - } - - @Test - def mapSplitTest: Unit = { - val xs1 = List(1, 2, 3) - val (xs2, xs3) = mapSplit(xs1)(x => if (x % 2 == 0) Left(x) else Right(x.toString)) - val xs4: List[Int] = xs2 - val xs5: List[String] = xs3 - - val xs6 = TreeMap((1, "1"), (2, "2")) - val (xs7, xs8) = mapSplit(xs6) { case (k, v) => Left[(String, Int), (Int, Boolean)]((v, k)) } - val xs9: TreeMap[String, Int] = xs7 - val xs10: TreeMap[Int, Boolean] = xs8 - } - implicitly[BuildFrom[String, Char, String]] implicitly[BuildFrom[Array[Int], Char, Array[Char]]] implicitly[BuildFrom[BitSet, Int, BitSet]] @@ -138,4 +61,78 @@ class BuildFromTest { Map: BuildFrom[_, (Int, String), Map[Int, String]] SortedSet: BuildFrom[_, Int, SortedSet[Int]] SortedMap: BuildFrom[_, (Int, String), SortedMap[Int, String]] + + val tests = Tests{ + 'optionSequence2Test - { + val xs1 = List(Some(1), None, Some(2)) + val o1 = optionSequence2(xs1) + val o1t: Option[List[Int]] = o1 + + val xs2 = TreeSet(Some("foo"), Some("bar"), None) + val o2 = optionSequence2(xs2) + // Not working: the resolved implicit BuildFrom results in a SortedSet instead of a TreeSet + // val o2t: Option[TreeSet[String]] = o2 + val o2t: Option[SortedSet[String]] = o2 + + // Breakout-like use case from https://github.com/scala/scala/pull/5233: + val xs4 = List[Option[(Int, String)]](Some((1 -> "a")), Some((2 -> "b"))) + val o4 = optionSequence2(xs4)(TreeMap) + val o4t: Option[TreeMap[Int, String]] = o4 + } + + 'optionSequence3Test - { + val xs1 = List(Some(1), None, Some(2)) + val o1 = optionSequence3(xs1) + val o1t: Option[List[Int]] = o1 + + val xs2 = TreeSet(Some("foo"), Some("bar"), None) + val o2 = optionSequence3(xs2) + // Not working: the resolved implicit BuildFrom results in a SortedSet instead of a TreeSet + // val o2t: Option[TreeSet[String]] = o2 + val o2t: Option[SortedSet[String]] = o2 + + // Breakout-like use case from https://github.com/scala/scala/pull/5233: + val xs4 = List[Option[(Int, String)]](Some((1 -> "a")), Some((2 -> "b"))) + val o4 = optionSequence3(xs4)(TreeMap) // same syntax as in `.to` + val o4t: Option[TreeMap[Int, String]] = o4 + } + + 'eitherSequenceTest - { + val xs3 = ListBuffer(Right("foo"), Left(0), Right("bar")) + val e1 = eitherSequence(xs3) + val e1t: Either[Int, ListBuffer[String]] = e1 + } + + 'flatCollectTest - { + val xs1 = List(1, 2, 3) + val xs2 = flatCollect(xs1) { case 2 => ArrayBuffer("foo", "bar") } + val xs3: List[String] = xs2 + + val xs4 = TreeMap((1, "1"), (2, "2")) + val xs5 = flatCollect(xs4) { case (2, v) => List((v, v)) } + val xs6: TreeMap[String, String] = xs5 + + val xs7 = HashMap((1, "1"), (2, "2")) + val xs8 = flatCollect(xs7) { case (2, v) => List((v, v)) } + val xs9: HashMap[String, String] = xs8 + + val xs10 = TreeSet(1, 2, 3) + val xs11 = flatCollect(xs10) { case 2 => List("foo", "bar") } + // Not working: the resolved implicit BuildFrom results in a SortedSet instead of a TreeSet + // val xs12: TreeSet[String] = xs11 + val xs12: SortedSet[String] = xs11 + } + + 'mapSplitTest - { + val xs1 = List(1, 2, 3) + val (xs2, xs3) = mapSplit(xs1)(x => if (x % 2 == 0) Left(x) else Right(x.toString)) + val xs4: List[Int] = xs2 + val xs5: List[String] = xs3 + + val xs6 = TreeMap((1, "1"), (2, "2")) + val (xs7, xs8) = mapSplit(xs6) { case (k, v) => Left[(String, Int), (Int, Boolean)]((v, k)) } + val xs9: TreeMap[String, Int] = xs7 + val xs10: TreeMap[Int, Boolean] = xs8 + } + } } diff --git a/src/test/scala/test/scala/collection/CollectionTest.scala b/src/test/scala/test/scala/collection/CollectionTest.scala index da499f14..898d7515 100644 --- a/src/test/scala/test/scala/collection/CollectionTest.scala +++ b/src/test/scala/test/scala/collection/CollectionTest.scala @@ -1,55 +1,54 @@ package test.scala.collection -import org.junit.Assert._ -import org.junit.Test +import utest._ import scala.collection.compat._ import scala.collection.immutable.BitSet -class CollectionTest { - @Test - def testTo: Unit = { - val xs = List(1,2,3) - val v = xs.to(Vector) - val vT: Vector[Int] = v - assertEquals(Vector(1,2,3), v) - - val a = xs.to(Array) - val aT: Array[Int] = a - assertEquals(Vector(1,2,3), a.toVector) - - val b = xs.to(BitSet) // we can fake a type constructor for the 2 standard BitSet types - val bT: BitSet = b - assertEquals(BitSet(1,2,3), b) - - val ys = List(1 -> "a", 2 -> "b") - val m = ys.to(Map) - // Not possible - `to` returns a Col[A] so this is only typed as an Iterable[(Int, String)] - //val mT: Map[Int, String] = m - assertEquals(Map(1 -> "a", 2 -> "b"), m) - assertTrue(m.isInstanceOf[Map[_, _]]) - } - - @Test - def testFrom: Unit = { - val xs = List(1,2,3) - val v = Vector.from(xs) - val vT: Vector[Int] = v - assertEquals(Vector(1,2,3), v) - - val b = BitSet.fromSpecific(xs) - val bT: BitSet = b - assertEquals(BitSet(1,2,3), b) - - val ys = List(1 -> "a", 2 -> "b") - val m = Map.from(ys) - val mT: Map[Int, String] = m - assertEquals(Map(1 -> "a", 2 -> "b"), m) - } - - @Test - def testIterator: Unit = { - val xs = Iterator(1, 2, 3).iterator.toList - assertEquals(List(1, 2, 3), xs) +object CollectionTest extends TestSuite{ + + val tests = Tests{ + 'testTo - { + val xs = List(1,2,3) + val v = xs.to(Vector) + val vT: Vector[Int] = v + assert(Vector(1,2,3) == v) + + val a = xs.to(Array) + val aT: Array[Int] = a + assert(Vector(1,2,3) == a.toVector) + + val b = xs.to(BitSet) // we can fake a type constructor for the 2 standard BitSet types + val bT: BitSet = b + assert(BitSet(1,2,3) == b) + + val ys = List(1 -> "a", 2 -> "b") + val m = ys.to(Map) + // Not possible - `to` returns a Col[A] so this is only typed as an Iterable[(Int, String)] + //val mT: Map[Int, String] = m + assert(Map(1 -> "a", 2 -> "b") == m) + assert(m.isInstanceOf[Map[_, _]]) + } + + 'testFrom- { + val xs = List(1,2,3) + val v = Vector.from(xs) + val vT: Vector[Int] = v + assert(Vector(1,2,3) == v) + + val b = BitSet.fromSpecific(xs) + val bT: BitSet = b + assert(BitSet(1,2,3) == b) + + val ys = List(1 -> "a", 2 -> "b") + val m = Map.from(ys) + val mT: Map[Int, String] = m + assert(Map(1 -> "a", 2 -> "b") == m) + } + + 'testIterator - { + val xs = Iterator(1, 2, 3).iterator.toList + assert(List(1, 2, 3) == xs) + } } } diff --git a/src/test/scala/test/scala/collection/FactoryTest.scala b/src/test/scala/test/scala/collection/FactoryTest.scala index 06533efa..73823461 100644 --- a/src/test/scala/test/scala/collection/FactoryTest.scala +++ b/src/test/scala/test/scala/collection/FactoryTest.scala @@ -1,11 +1,11 @@ package test.scala.collection -import org.junit.{Assert, Test} +import utest._ import scala.collection.compat._ import scala.collection.{BitSet, immutable, mutable} -class FactoryTest { +object FactoryTest extends TestSuite{ implicitly[Factory[Char, String]] implicitly[Factory[Char, Array[Char]]] @@ -19,13 +19,13 @@ class FactoryTest { Map: Factory[(Int, String), Map[Int, String]] immutable.TreeMap: Factory[(Int, String), immutable.TreeMap[Int, String]] - @Test - def streamFactoryPreservesLaziness(): Unit = { - val factory = implicitly[Factory[Int, Stream[Int]]] - var counter = 0 - val source = Stream.continually { counter += 1; 1 } - val result = factory.fromSpecific(source) - Assert.assertEquals(1, counter) // One element has been evaluated because Stream is not lazy in its head + val tests = Tests{ + 'streamFactoryPreservesLaziness - { + val factory = implicitly[Factory[Int, Stream[Int]]] + var counter = 0 + val source = Stream.continually { counter += 1; 1 } + val result = factory.fromSpecific(source) + assert(1 == counter) // One element has been evaluated because Stream is not lazy in its head + } } - } diff --git a/src/test/scala/test/scala/collection/StreamTest.scala b/src/test/scala/test/scala/collection/StreamTest.scala index f31e38d5..0a451606 100644 --- a/src/test/scala/test/scala/collection/StreamTest.scala +++ b/src/test/scala/test/scala/collection/StreamTest.scala @@ -1,15 +1,15 @@ package test.scala.collection -import org.junit.Test +import utest._ import scala.collection.compat._ -class StreamTest { +object StreamTest extends TestSuite{ - @Test - def lazyAppendedAll(): Unit = { - val s = 1 #:: 2 #:: 3 #:: Stream.Empty - s.lazyAppendedAll(List(4, 5, 6)) + val tests = Tests{ + 'lazyAppendedAll - { + val s = 1 #:: 2 #:: 3 #:: Stream.Empty + s.lazyAppendedAll(List(4, 5, 6)) + } } - } diff --git a/src/test/scala/test/scala/collection/generic/SortedTest.scala b/src/test/scala/test/scala/collection/generic/SortedTest.scala index 5e0a30fd..6aa36478 100644 --- a/src/test/scala/test/scala/collection/generic/SortedTest.scala +++ b/src/test/scala/test/scala/collection/generic/SortedTest.scala @@ -1,55 +1,54 @@ package test.scala.collection.generic -import org.junit.Assert._ -import org.junit.Test +import utest._ import scala.collection.compat._ import scala.collection.{immutable => i, mutable => m} -class SortedTest { - @Test - def immutableRangeOps(): Unit = { - val st = i.SortedSet(-1, 2, 4, 3) - for (x <- List(0, 1, 4, -1, -4)) { - val s1 = st.rangeFrom(x) - assertEquals(s1: i.SortedSet[Int], st.from(x)) - val s2 = st.rangeTo(x) - assertEquals(s2: i.SortedSet[Int], st.to(x)) - val s3 = st.rangeUntil(x) - assertEquals(s3: i.SortedSet[Int], st.until(x)) +object SortedTest extends TestSuite{ + val tests = Tests{ + 'immutableRangeOps - { + val st = i.SortedSet(-1, 2, 4, 3) + for (x <- List(0, 1, 4, -1, -4)) { + val s1 = st.rangeFrom(x) + assert((s1: i.SortedSet[Int]) == st.from(x)) + val s2 = st.rangeTo(x) + assert((s2: i.SortedSet[Int]) == st.to(x)) + val s3 = st.rangeUntil(x) + assert((s3: i.SortedSet[Int]) == st.until(x)) + } + val mp = i.SortedMap("" -> 0, "ds" -> -3, "-??" -> 13, "Df" -> 33, "d!" -> -32) + for (x <- List("", "-", "@", "aa", "D", "d")) { + val m1 = mp.rangeFrom(x) + assert((m1: i.SortedMap[String, Int]) == mp.from(x)) + val m2 = mp.rangeTo(x) + assert((m2: i.SortedMap[String, Int]) == mp.to(x)) + val m3 = mp.rangeUntil(x) + assert((m3: i.SortedMap[String, Int]) == mp.until(x)) + } } - val mp = i.SortedMap("" -> 0, "ds" -> -3, "-??" -> 13, "Df" -> 33, "d!" -> -32) - for (x <- List("", "-", "@", "aa", "D", "d")) { - val m1 = mp.rangeFrom(x) - assertEquals(m1: i.SortedMap[String, Int], mp.from(x)) - val m2 = mp.rangeTo(x) - assertEquals(m2: i.SortedMap[String, Int], mp.to(x)) - val m3 = mp.rangeUntil(x) - assertEquals(m3: i.SortedMap[String, Int], mp.until(x)) - } - } - @Test - def mutableRangeOps(): Unit = { - val st = m.SortedSet(-1, 2, 4, 3) - for (x <- List(0, 1, 4, -1, -4)) { - val s1 = st.rangeFrom(x) - assertEquals(s1: m.SortedSet[Int], st.from(x)) - val s2 = st.rangeTo(x) - assertEquals(s2: m.SortedSet[Int], st.to(x)) - val s3 = st.rangeUntil(x) - assertEquals(s3: m.SortedSet[Int], st.until(x)) - } - /* 2.11 doesn't have a mutable.SortedMap - val mp = m.SortedMap("" -> 0, "ds" -> -3, "-??" -> 13, "Df" -> 33, "d!" -> -32) - for (x <- List("", "-", "@", "aa", "D", "d")) { - val m1 = mp.rangeFrom(x) - assertEquals(m1: m.SortedMap[String, Int], mp.from(x)) - val m2 = mp.rangeTo(x) - assertEquals(m2: m.SortedMap[String, Int], mp.to(x)) - val m3 = mp.rangeUntil(x) - assertEquals(m3: m.SortedMap[String, Int], mp.until(x)) + 'mutableRangeOps - { + val st = m.SortedSet(-1, 2, 4, 3) + for (x <- List(0, 1, 4, -1, -4)) { + val s1 = st.rangeFrom(x) + assert((s1: m.SortedSet[Int]) == st.from(x)) + val s2 = st.rangeTo(x) + assert((s2: m.SortedSet[Int]) == st.to(x)) + val s3 = st.rangeUntil(x) + assert((s3: m.SortedSet[Int]) == st.until(x)) + } + /* 2.11 doesn't have a mutable.SortedMap + val mp = m.SortedMap("" -> 0, "ds" -> -3, "-??" -> 13, "Df" -> 33, "d!" -> -32) + for (x <- List("", "-", "@", "aa", "D", "d")) { + val m1 = mp.rangeFrom(x) + assert(m1: m.SortedMap[String, Int], mp.from(x)) + val m2 = mp.rangeTo(x) + assert(m2: m.SortedMap[String, Int], mp.to(x)) + val m3 = mp.rangeUntil(x) + assert(m3: m.SortedMap[String, Int], mp.until(x)) + } + */ } - */ } }