diff --git a/.travis.yml b/.travis.yml index bcc8f5afa..a1efeaf61 100644 --- a/.travis.yml +++ b/.travis.yml @@ -17,7 +17,7 @@ scala: - 2.10.7 - 2.11.12 - 2.12.6 - - 2.13.0-M3 + - 2.13.0-M4 jdk: - oraclejdk8 env: @@ -38,6 +38,9 @@ matrix: before_script: - curl https://raw.githubusercontent.com/scala-native/scala-native/master/scripts/travis_setup.sh | bash -x sudo: required + addons: + apt: + update: true # https://github.com/rickynils/scalacheck/issues/412 env: PLATFORM=native SBT_PARALLEL=true WORKERS=1 DEPLOY=true - env: EXAMPLES script: @@ -46,3 +49,5 @@ matrix: exclude: - scala: 2.10.7 env: PLATFORM=js SBT_PARALLEL=true WORKERS=1 DEPLOY=true SCALAJS_VERSION=1.0.0-M3 + - scala: 2.13.0-M4 + env: PLATFORM=js SBT_PARALLEL=true WORKERS=1 DEPLOY=true SCALAJS_VERSION=1.0.0-M3 diff --git a/build.sbt b/build.sbt index 07f12bb27..c0df70f3b 100644 --- a/build.sbt +++ b/build.sbt @@ -1,5 +1,7 @@ sourceDirectory := file("dummy source directory") +val scalaMajorVersion = SettingKey[Int]("scalaMajorVersion") + scalaVersionSettings lazy val versionNumber = "1.14.1" @@ -10,7 +12,13 @@ lazy val travisCommit = Option(System.getenv().get("TRAVIS_COMMIT")) lazy val scalaVersionSettings = Seq( scalaVersion := "2.12.6", - crossScalaVersions := Seq("2.10.7", "2.11.12", "2.13.0-M3", scalaVersion.value) + crossScalaVersions := Seq("2.10.7", "2.11.12", "2.13.0-M4", scalaVersion.value), + scalaMajorVersion := { + val v = scalaVersion.value + CrossVersion.partialVersion(v).map(_._2.toInt).getOrElse { + throw new RuntimeException(s"could not get Scala major version from $v") + } + } ) lazy val sharedSettings = MimaSettings.settings ++ scalaVersionSettings ++ Seq( @@ -43,6 +51,11 @@ lazy val sharedSettings = MimaSettings.settings ++ scalaVersionSettings ++ Seq( unmanagedSourceDirectories in Compile += (baseDirectory in LocalRootProject).value / "src" / "main" / "scala", + unmanagedSourceDirectories in Compile += { + val s = if (scalaMajorVersion.value >= 13) "+" else "-" + (baseDirectory in LocalRootProject).value / "src" / "main" / s"scala-2.13$s" + }, + unmanagedSourceDirectories in Test += (baseDirectory in LocalRootProject).value / "src" / "test" / "scala", resolvers += "sonatype" at "https://oss.sonatype.org/content/repositories/releases", @@ -54,18 +67,18 @@ lazy val sharedSettings = MimaSettings.settings ++ scalaVersionSettings ++ Seq( "-encoding", "UTF-8", "-feature", "-unchecked", - "-Xfatal-warnings", "-Xfuture", - "-Yno-adapted-args", "-Ywarn-dead-code", "-Ywarn-inaccessible", "-Ywarn-nullary-override", "-Ywarn-nullary-unit", "-Ywarn-numeric-widen") ++ { - scalaBinaryVersion.value match { - case "2.10" => Seq("-Xlint") - case "2.11" => Seq("-Xlint", "-Ywarn-infer-any", "-Ywarn-unused-import") - case _ => Seq("-Xlint:-unused", "-Ywarn-infer-any", "-Ywarn-unused-import", "-Ywarn-unused:-patvars,-implicits,-locals,-privates,-explicits") + val modern = Seq("-Xlint:-unused", "-Ywarn-infer-any", "-Ywarn-unused-import", "-Ywarn-unused:-patvars,-implicits,-locals,-privates,-explicits") + scalaMajorVersion.value match { + case 10 => Seq("-Xfatal-warnings", "-Xlint") + case 11 => Seq("-Xfatal-warnings", "-Xlint", "-Ywarn-infer-any", "-Ywarn-unused-import") + case 12 => "-Xfatal-warnings" +: modern + case 13 => modern } }, @@ -78,7 +91,11 @@ lazy val sharedSettings = MimaSettings.settings ++ scalaVersionSettings ++ Seq( // don't use fatal warnings in tests scalacOptions in Test ~= (_ filterNot (_ == "-Xfatal-warnings")), - mimaPreviousArtifacts := Set("org.scalacheck" %% "scalacheck" % "1.14.0"), + mimaPreviousArtifacts := { + // TODO: re-enable MiMa for 2.13.0-M4 once there is a release out + if (scalaMajorVersion.value == 13) Set() + else Set("org.scalacheck" %% "scalacheck" % "1.14.0") + }, publishTo := { val nexus = "https://oss.sonatype.org/" diff --git a/doc/UserGuide.md b/doc/UserGuide.md index 522b04aea..ae9a348a9 100644 --- a/doc/UserGuide.md +++ b/doc/UserGuide.md @@ -471,17 +471,17 @@ responsible for generating the individual items. You can use it in the following way: ```scala -val genIntList = Gen.containerOf[List,Int](Gen.oneOf(1, 3, 5)) +val genIntList = Gen.containerOf[List,Int](Gen.oneOf(1, 3, 5)) -val genStringStream = Gen.containerOf[Stream,String](Gen.alphaStr) +val genStringLazyList = Gen.containerOf[LazyList,String](Gen.alphaStr) -val genBoolArray = Gen.containerOf[Array,Boolean](true) +val genBoolArray = Gen.containerOf[Array,Boolean](true) ``` -By default, ScalaCheck supports generation of `List`, `Stream`, `Set`, `Array`, -and `ArrayList` (from `java.util`). You can add support for additional -containers by adding implicit `Buildable` instances. See `Buildable.scala` for -examples. +By default, ScalaCheck supports generation of `List`, `Stream` (Scala 2.10 - +2.12, deprecated in 2.13), `LazyList` (Scala 2.13), `Set`, `Array`, and +`ArrayList` (from `java.util`). You can add support for additional containers +by adding implicit `Buildable` instances. See `Buildable.scala` for examples. There is also `Gen.nonEmptyContainerOf` for generating non-empty containers, and `Gen.containerOfN` for generating containers of a given size. @@ -778,9 +778,9 @@ can also define default shrinking methods. This is done by defining an implicit method that returns a `Shrink[T]` instance. This is done by using the `Shrink(...)` factory method, which as its only parameter takes a function and returns an instance of `Shrink[T]`. In turn, the function should take a value -of the given type `T`, and return a `Stream` of shrank variants of the given -value. As an example, look at the implicit `Shrink` instance for a tuple as it -is defined in ScalaCheck: +of the given type `T`, and return a `Stream` of shrank +variants of the given value. As an example, look at the implicit `Shrink` instance +for a tuple as it is defined in ScalaCheck: ```scala /** Shrink instance of 2-tuple */ diff --git a/jvm/src/test/scala/org/scalacheck/CogenSpecification.scala b/jvm/src/test/scala/org/scalacheck/CogenSpecification.scala index 106333f8e..617184bfd 100644 --- a/jvm/src/test/scala/org/scalacheck/CogenSpecification.scala +++ b/jvm/src/test/scala/org/scalacheck/CogenSpecification.scala @@ -5,6 +5,8 @@ import org.scalacheck.Gen.listOfN import org.scalacheck.GenSpecification.arbSeed import org.scalacheck.Prop.forAll import org.scalacheck.rng.Seed +import ScalaVersionSpecific._ + import scala.util.Try import scala.concurrent.duration.{Duration, FiniteDuration} @@ -141,6 +143,7 @@ object CogenSpecification extends Properties("Cogen") { include(cogenLaws[List[Int]], "cogenList.") include(cogenLaws[Vector[Int]], "cogenVector.") include(cogenLaws[Stream[Int]], "cogenStream.") + include(cogenLaws[LazyList[Int]], "cogenLazyList.") include(cogenLaws[Set[Int]], "cogenSet.") include(cogenLaws[Map[Int, Int]], "cogenMap.") include(cogenLaws[() => Int], "cogenFunction0.") diff --git a/jvm/src/test/scala/org/scalacheck/GenSpecification.scala b/jvm/src/test/scala/org/scalacheck/GenSpecification.scala index 59c2b9647..cfd478691 100644 --- a/jvm/src/test/scala/org/scalacheck/GenSpecification.scala +++ b/jvm/src/test/scala/org/scalacheck/GenSpecification.scala @@ -18,7 +18,7 @@ import Shrink._ import java.util.Date import scala.util.{Try, Success, Failure} -object GenSpecification extends Properties("Gen") { +object GenSpecification extends Properties("Gen") with GenSpecificationVersionSpecific { implicit val arbSeed: Arbitrary[Seed] = Arbitrary( arbitrary[Long] flatMap Seed.apply @@ -54,7 +54,7 @@ object GenSpecification extends Properties("Gen") { forAll(g) { n => true } } - property("frequency 3") = forAll(choose(0,100000)) { n => + property("frequency 3") = forAll(choose(1,100000)) { n => forAll(frequency(List.fill(n)((1,const(0))): _*)) { _ == 0 } } @@ -183,6 +183,10 @@ object GenSpecification extends Properties("Gen") { s.drop(n & 0xffff).nonEmpty } + property("infiniteLazyList") = forAll(infiniteLazyList(arbitrary[Int]), arbitrary[Short]) { (s, n) => + s.drop(n & 0xffff).nonEmpty + } + property("someOf") = forAll { l: List[Int] => forAll(someOf(l))(_.toList.forall(l.contains)) } @@ -201,7 +205,7 @@ object GenSpecification extends Properties("Gen") { property("distributed pick") = { val lst = (0 to 7).toIterable val n = 2 - forAll(pick(n, lst)) { xs: Seq[Int] => + forAll(pick(n, lst)) { xs: collection.Seq[Int] => xs.map { x: Int => Prop.collect(x) { xs.size == n diff --git a/jvm/src/test/scala/org/scalacheck/PropertyFilterSpecification.scala b/jvm/src/test/scala/org/scalacheck/PropertyFilterSpecification.scala index 3a9340a6c..03d52775a 100644 --- a/jvm/src/test/scala/org/scalacheck/PropertyFilterSpecification.scala +++ b/jvm/src/test/scala/org/scalacheck/PropertyFilterSpecification.scala @@ -26,8 +26,8 @@ object PropertyFilterSpecification extends Properties("PropertyFilter") { val nl = System.lineSeparator - private def diff(filter: Option[String], actual: Seq[String], - expected: Seq[String]): String = { + private def diff(filter: Option[String], actual: collection.Seq[String], + expected: collection.Seq[String]): String = { s"filter: ${filter.getOrElse("not supplied")}" + s"${nl}expected values:$nl" + s"\t${expected.mkString(s"$nl\t")}" + @@ -35,8 +35,8 @@ object PropertyFilterSpecification extends Properties("PropertyFilter") { s"\t${actual.mkString(s"$nl\t")}" } - private def prop(filter: Option[String], actualNames: Seq[String], - expectedNames: Seq[String]): Prop = { + private def prop(filter: Option[String], actualNames: collection.Seq[String], + expectedNames: collection.Seq[String]): Prop = { def lengthProp = actualNames.length == expectedNames.length def props = actualNames.forall(expectedNames.contains) diff --git a/project/plugin.sbt b/project/plugin.sbt index a637c556e..5dea6ce83 100644 --- a/project/plugin.sbt +++ b/project/plugin.sbt @@ -3,7 +3,7 @@ addSbtPlugin("com.typesafe" % "sbt-mima-plugin" % "0.2.0") addSbtPlugin("com.jsuereth" % "sbt-pgp" % "1.1.1") val scalaJSVersion = - Option(System.getenv("SCALAJS_VERSION")).getOrElse("0.6.22") + Option(System.getenv("SCALAJS_VERSION")).getOrElse("0.6.23") addSbtPlugin("org.scala-js" % "sbt-scalajs" % scalaJSVersion) diff --git a/src/main/scala-2.13+/org/scalacheck/ScalaVersionSpecific.scala b/src/main/scala-2.13+/org/scalacheck/ScalaVersionSpecific.scala new file mode 100644 index 000000000..dc7ab3ce9 --- /dev/null +++ b/src/main/scala-2.13+/org/scalacheck/ScalaVersionSpecific.scala @@ -0,0 +1,40 @@ +/*-------------------------------------------------------------------------*\ +** ScalaCheck ** +** Copyright (c) 2007-2018 Rickard Nilsson. All rights reserved. ** +** http://www.scalacheck.org ** +** ** +** This software is released under the terms of the Revised BSD License. ** +** There is NO WARRANTY. See the file LICENSE for the full text. ** +\*------------------------------------------------------------------------ */ + +package org.scalacheck + +import rng.Seed + +private[scalacheck] object ScalaVersionSpecific { + def toLazyList[T](i: IterableOnce[T]) = LazyList.from(i) +} + +private[scalacheck] trait GenVersionSpecific { + + /** Generates an infinite lazy list. */ + def infiniteLazyList[T](g: => Gen[T]): Gen[LazyList[T]] = { + def unfold[A, S](z: S)(f: S => Option[(A, S)]): LazyList[A] = f(z) match { + case Some((h, s)) => h #:: unfold(s)(f) + case None => LazyList.empty + } + Gen.gen { (p, seed0) => + new Gen.R[LazyList[T]] { + val result: Option[LazyList[T]] = Some(unfold(seed0)(s => Some(g.pureApply(p, s) -> s.next))) + val seed: Seed = seed0.next + } + } + } +} + +private[scalacheck] trait GenSpecificationVersionSpecific + +private[scalacheck] trait CogenVersionSpecific { + implicit def cogenLazyList[A: Cogen]: Cogen[LazyList[A]] = + Cogen.it(_.iterator) +} diff --git a/src/main/scala-2.13+/org/scalacheck/util/BuildableVersionSpecific.scala b/src/main/scala-2.13+/org/scalacheck/util/BuildableVersionSpecific.scala new file mode 100644 index 000000000..db60cc892 --- /dev/null +++ b/src/main/scala-2.13+/org/scalacheck/util/BuildableVersionSpecific.scala @@ -0,0 +1,59 @@ +/*-------------------------------------------------------------------------*\ +** ScalaCheck ** +** Copyright (c) 2007-2018 Rickard Nilsson. All rights reserved. ** +** http://www.scalacheck.org ** +** ** +** This software is released under the terms of the Revised BSD License. ** +** There is NO WARRANTY. See the file LICENSE for the full text. ** +\*------------------------------------------------------------------------ */ + +package org.scalacheck.util + +import java.util.ArrayList + +import collection.{Map => _, _} +import scala.collection.mutable.Builder + + +private[util] trait BuildableVersionSpecific { + implicit def buildableFactory[T,C](implicit f: Factory[T,C]) = + new Buildable[T,C] { + def builder = f.newBuilder + } +} + +private[util] class ArrayListBuilder[T] extends Builder[T, ArrayList[T]] { + private val al = new ArrayList[T] + def addOne(x: T): this.type = { + al.add(x) + this + } + def clear(): Unit = al.clear() + def result(): ArrayList[T] = al +} + +/** + * Factory instances implementing Serializable, so that the objects capturing those can be + * serializable too. + */ +// Named `...CanBuildFroms` for 2.12 source compatibility (`import SerializableCanBuildFroms._`) +// Can be renamed to `SerializableFactories` in a major release. +object SerializableCanBuildFroms { + implicit def listFactory[T]: Factory[T, List[T]] = + new Factory[T, List[T]] with Serializable { + def fromSpecific(source: IterableOnce[T]): List[T] = List.from(source) + def newBuilder: Builder[T, List[T]] = List.newBuilder[T] + } + + implicit def bitsetFactory[T]: Factory[Int, BitSet] = + new Factory[Int, BitSet] with Serializable { + def fromSpecific(source: IterableOnce[Int]) = BitSet.fromSpecific(source) + def newBuilder: Builder[Int, BitSet] = BitSet.newBuilder + } + + implicit def mapFactory[T, U]: Factory[(T, U), Map[T, U]] = + new Factory[(T, U), Map[T, U]] with Serializable { + def fromSpecific(source: IterableOnce[(T, U)]) = Map.from(source) + def newBuilder: Builder[(T, U), Map[T, U]] = Map.newBuilder[T, U] + } +} diff --git a/src/main/scala-2.13-/org/scalacheck/ScalaVersionSpecific.scala b/src/main/scala-2.13-/org/scalacheck/ScalaVersionSpecific.scala new file mode 100644 index 000000000..38bc0bff3 --- /dev/null +++ b/src/main/scala-2.13-/org/scalacheck/ScalaVersionSpecific.scala @@ -0,0 +1,39 @@ +/*-------------------------------------------------------------------------*\ +** ScalaCheck ** +** Copyright (c) 2007-2018 Rickard Nilsson. All rights reserved. ** +** http://www.scalacheck.org ** +** ** +** This software is released under the terms of the Revised BSD License. ** +** There is NO WARRANTY. See the file LICENSE for the full text. ** +\*------------------------------------------------------------------------ */ + +package org.scalacheck + +import scala.collection.generic.Sorted +import scala.collection.immutable.Stream +import scala.collection.TraversableOnce + +private[scalacheck] object ScalaVersionSpecific { + def toLazyList[T](i: TraversableOnce[T]) = i.toStream + + type LazyList[+A] = Stream[A] + val LazyList = Stream + + implicit class StreamExt[+A](val s: Stream[A]) extends AnyVal { + def lazyAppendedAll[B >: A](rest: => TraversableOnce[B]): Stream[B] = s.append(rest) + } + + implicit class SortedExt[K, T <: Sorted[K, T]](val s: Sorted[K, T]) extends AnyVal { + def rangeFrom(from: K): T = s.from(from) + def rangeTo(to: K): T = s.to(to) + def rangeUntil(until: K): T = s.until(until) + } +} + +private[scalacheck] trait GenVersionSpecific +private[scalacheck] trait CogenVersionSpecific + +// Used in tests +private[scalacheck] trait GenSpecificationVersionSpecific { + def infiniteLazyList[T](g: => Gen[T]): Gen[Stream[T]] = Gen.infiniteStream(g) +} diff --git a/src/main/scala-2.13-/org/scalacheck/util/BuildableVersionSpecific.scala b/src/main/scala-2.13-/org/scalacheck/util/BuildableVersionSpecific.scala new file mode 100644 index 000000000..ebf7e2f65 --- /dev/null +++ b/src/main/scala-2.13-/org/scalacheck/util/BuildableVersionSpecific.scala @@ -0,0 +1,57 @@ +/*-------------------------------------------------------------------------*\ +** ScalaCheck ** +** Copyright (c) 2007-2018 Rickard Nilsson. All rights reserved. ** +** http://www.scalacheck.org ** +** ** +** This software is released under the terms of the Revised BSD License. ** +** There is NO WARRANTY. See the file LICENSE for the full text. ** +\*------------------------------------------------------------------------ */ + +package org.scalacheck.util + +import java.util.ArrayList + +import collection.{Map => _, _} +import generic.CanBuildFrom +import scala.collection.mutable.Builder + +private[util] trait BuildableVersionSpecific { + implicit def buildableCanBuildFrom[T,F,C](implicit c: CanBuildFrom[F,T,C]) = + new Buildable[T,C] { + def builder = c.apply + } +} + +private[util] class ArrayListBuilder[T] extends Builder[T, ArrayList[T]] { + private val al = new ArrayList[T] + def +=(x: T): this.type = { + al.add(x) + this + } + def clear(): Unit = al.clear() + def result(): ArrayList[T] = al +} + +/** + * CanBuildFrom instances implementing Serializable, so that the objects capturing those can be + * serializable too. + */ +object SerializableCanBuildFroms { + implicit def listCanBuildFrom[T]: CanBuildFrom[List[T], T, List[T]] = + new CanBuildFrom[List[T], T, List[T]] with Serializable { + def apply(from: List[T]) = List.newBuilder[T] + def apply() = List.newBuilder[T] + } + + implicit def bitsetCanBuildFrom[T]: CanBuildFrom[BitSet, Int, BitSet] = + new CanBuildFrom[BitSet, Int, BitSet] with Serializable { + def apply(from: BitSet) = BitSet.newBuilder + def apply() = BitSet.newBuilder + } + + implicit def mapCanBuildFrom[T, U]: CanBuildFrom[Map[T, U], (T, U), Map[T, U]] = + new CanBuildFrom[Map[T, U], (T, U), Map[T, U]] with Serializable { + def apply(from: Map[T, U]) = Map.newBuilder[T, U] + def apply() = Map.newBuilder[T, U] + } +} diff --git a/src/main/scala/org/scalacheck/Arbitrary.scala b/src/main/scala/org/scalacheck/Arbitrary.scala index f543e95de..814a0ee71 100644 --- a/src/main/scala/org/scalacheck/Arbitrary.scala +++ b/src/main/scala/org/scalacheck/Arbitrary.scala @@ -357,7 +357,7 @@ private[scalacheck] sealed trait ArbitraryLowPriority { Arbitrary(Gen.oneOf(arbitrary[T].map(Success(_)), arbitrary[Throwable].map(Failure(_)))) /** Arbitrary instance of any [[org.scalacheck.util.Buildable]] container - * (such as lists, arrays, streams, etc). The maximum size of the container + * (such as lists, arrays, streams / lazy lists, etc). The maximum size of the container * depends on the size generation parameter. */ implicit def arbContainer[C[_],T](implicit a: Arbitrary[T], b: Buildable[T,C[T]], t: C[T] => Traversable[T] @@ -372,7 +372,7 @@ private[scalacheck] sealed trait ArbitraryLowPriority { implicit def arbEnum[A <: java.lang.Enum[A]](implicit A: reflect.ClassTag[A]): Arbitrary[A] = { val values = A.runtimeClass.getEnumConstants.asInstanceOf[Array[A]] - Arbitrary(Gen.oneOf(values)) + Arbitrary(Gen.oneOf(values.toIndexedSeq)) } implicit def arbPartialFunction[A: Cogen, B: Arbitrary]: Arbitrary[PartialFunction[A, B]] = diff --git a/src/main/scala/org/scalacheck/Cogen.scala b/src/main/scala/org/scalacheck/Cogen.scala index c8585d9c9..baf014155 100644 --- a/src/main/scala/org/scalacheck/Cogen.scala +++ b/src/main/scala/org/scalacheck/Cogen.scala @@ -28,7 +28,7 @@ sealed trait Cogen[T] extends Serializable { Cogen((seed: Seed, s: S) => perturb(seed, f(s))) } -object Cogen extends CogenArities with CogenLowPriority { +object Cogen extends CogenArities with CogenLowPriority with CogenVersionSpecific { // for binary compatibility private[scalacheck] def apply[T](ev: Cogen[T]): Cogen[T] = ev diff --git a/src/main/scala/org/scalacheck/Gen.scala b/src/main/scala/org/scalacheck/Gen.scala index 638995d71..3384e0f0c 100644 --- a/src/main/scala/org/scalacheck/Gen.scala +++ b/src/main/scala/org/scalacheck/Gen.scala @@ -15,6 +15,7 @@ import language.implicitConversions import rng.Seed import util.Buildable import util.SerializableCanBuildFroms._ +import ScalaVersionSpecific._ import scala.annotation.tailrec import scala.collection.immutable.TreeMap @@ -200,7 +201,7 @@ sealed abstract class Gen[+T] extends Serializable { self => Gen.gen((p, seed) => doApply(p, f(seed))) } -object Gen extends GenArities{ +object Gen extends GenArities with GenVersionSpecific { //// Private interface //// @@ -559,7 +560,7 @@ object Gen extends GenArities{ builder += ((total, value)) } val tree = builder.result - choose(1L, total).flatMap(r => tree.from(r).head._2).suchThat { x => + choose(1L, total).flatMap(r => tree.rangeFrom(r).head._2).suchThat { x => gs.exists(_._2.sieveCopy(x)) } } @@ -687,7 +688,7 @@ object Gen extends GenArities{ choose(1, gs.length+2).flatMap(pick(_, g1, g2, gs: _*)) /** A generator that picks a given number of elements from a list, randomly */ - def pick[T](n: Int, l: Iterable[T]): Gen[Seq[T]] = { + def pick[T](n: Int, l: Iterable[T]): Gen[collection.Seq[T]] = { if (n > l.size || n < 0) throw new IllegalArgumentException(s"invalid choice: $n") else if (n == 0) Gen.const(Nil) else gen { (p, seed0) => diff --git a/src/main/scala/org/scalacheck/Properties.scala b/src/main/scala/org/scalacheck/Properties.scala index f9abe0702..f726791ce 100644 --- a/src/main/scala/org/scalacheck/Properties.scala +++ b/src/main/scala/org/scalacheck/Properties.scala @@ -41,7 +41,7 @@ class Properties(val name: String) { /** Returns all properties of this collection in a list of name/property * pairs. */ - def properties: Seq[(String,Prop)] = props + def properties: collection.Seq[(String,Prop)] = props /** Convenience method that checks the properties with the given parameters * (or default parameters, if not specified) diff --git a/src/main/scala/org/scalacheck/ScalaCheckFramework.scala b/src/main/scala/org/scalacheck/ScalaCheckFramework.scala index 071b9d251..e69e68da6 100644 --- a/src/main/scala/org/scalacheck/ScalaCheckFramework.scala +++ b/src/main/scala/org/scalacheck/ScalaCheckFramework.scala @@ -51,7 +51,7 @@ private abstract class ScalaCheckRunner extends Runner { abstract class BaseTask(override val taskDef: TaskDef) extends Task { val tags: Array[String] = Array() - val props: Seq[(String,Prop)] = { + val props: collection.Seq[(String,Prop)] = { val fp = taskDef.fingerprint.asInstanceOf[SubclassFingerprint] val obj = if (fp.isModule) Platform.loadModule(taskDef.fullyQualifiedName,loader) else Platform.newInstance(taskDef.fullyQualifiedName, loader, Seq())(Seq()) diff --git a/src/main/scala/org/scalacheck/Test.scala b/src/main/scala/org/scalacheck/Test.scala index 67ec6cf46..58fb8e2db 100644 --- a/src/main/scala/org/scalacheck/Test.scala +++ b/src/main/scala/org/scalacheck/Test.scala @@ -370,7 +370,7 @@ object Test { } /** Check a set of properties. */ - def checkProperties(prms: Parameters, ps: Properties): Seq[(String,Result)] = { + def checkProperties(prms: Parameters, ps: Properties): collection.Seq[(String,Result)] = { val params = ps.overrideParameters(prms) val propertyFilter = prms.propFilter.map(_.r) diff --git a/src/main/scala/org/scalacheck/util/Buildable.scala b/src/main/scala/org/scalacheck/util/Buildable.scala index 2e8d5fd80..2d8eab3bf 100644 --- a/src/main/scala/org/scalacheck/util/Buildable.scala +++ b/src/main/scala/org/scalacheck/util/Buildable.scala @@ -9,8 +9,7 @@ package org.scalacheck.util -import collection.{ Map => _, _ } -import generic.CanBuildFrom +import scala.collection.{mutable, Map => _, _} trait Buildable[T,C] extends Serializable { def builder: mutable.Builder[T,C] @@ -21,53 +20,13 @@ trait Buildable[T,C] extends Serializable { } } -/** - * CanBuildFrom instances implementing Serializable, so that the objects capturing those can be - * serializable too. - */ -object SerializableCanBuildFroms { - - implicit def listCanBuildFrom[T]: CanBuildFrom[List[T], T, List[T]] = - new CanBuildFrom[List[T], T, List[T]] with Serializable { - def apply(from: List[T]) = List.newBuilder[T] - def apply() = List.newBuilder[T] - } - - implicit def bitsetCanBuildFrom[T]: CanBuildFrom[BitSet, Int, BitSet] = - new CanBuildFrom[BitSet, Int, BitSet] with Serializable { - def apply(from: BitSet) = BitSet.newBuilder - def apply() = BitSet.newBuilder - } - - implicit def mapCanBuildFrom[T, U]: CanBuildFrom[Map[T, U], (T, U), Map[T, U]] = - new CanBuildFrom[Map[T, U], (T, U), Map[T, U]] with Serializable { - def apply(from: Map[T, U]) = Map.newBuilder[T, U] - def apply() = Map.newBuilder[T, U] - } - -} - -object Buildable { - - implicit def buildableCanBuildFrom[T,F,C](implicit c: CanBuildFrom[F,T,C]) = - new Buildable[T,C] { - def builder = c.apply - } - +object Buildable extends BuildableVersionSpecific { import java.util.ArrayList - implicit def buildableArrayList[T] = new Buildable[T,ArrayList[T]] { - def builder = new mutable.Builder[T,ArrayList[T]] { - val al = new ArrayList[T] - def +=(x: T) = { - al.add(x) - this - } - def clear() = al.clear() - def result() = al - } + implicit def buildableArrayList[T]: Buildable[T, ArrayList[T]] = new Buildable[T,ArrayList[T]] { + def builder = new ArrayListBuilder[T] } - } + /* object Buildable2 { diff --git a/src/main/scala/org/scalacheck/util/FreqMap.scala b/src/main/scala/org/scalacheck/util/FreqMap.scala index a62512930..7f653939d 100644 --- a/src/main/scala/org/scalacheck/util/FreqMap.scala +++ b/src/main/scala/org/scalacheck/util/FreqMap.scala @@ -9,6 +9,8 @@ package org.scalacheck.util +import org.scalacheck.ScalaVersionSpecific._ + sealed trait FreqMap[T] extends Serializable { protected val underlying: scala.collection.immutable.Map[T,Int] val total: Int @@ -32,7 +34,7 @@ sealed trait FreqMap[T] extends Serializable { def ++(fm: FreqMap[T]): FreqMap[T] = new FreqMap[T] { private val keys = FreqMap.this.underlying.keySet ++ fm.underlying.keySet - private val mappings = keys.toStream.map { x => + private val mappings = toLazyList(keys).map { x => (x, fm.getCount(x).getOrElse(0) + FreqMap.this.getCount(x).getOrElse(0)) } val underlying = scala.collection.immutable.Map(mappings: _*) @@ -43,7 +45,7 @@ sealed trait FreqMap[T] extends Serializable { val underlying = FreqMap.this.underlying transform { case (x,n) => n - fm.getCount(x).getOrElse(0) } - lazy val total = (0 /: underlying.valuesIterator) (_ + _) + lazy val total = underlying.valuesIterator.foldLeft(0)(_ + _) } def getCount(t: T) = underlying.get(t) diff --git a/src/test/scala/org/scalacheck/ShrinkSpecification.scala b/src/test/scala/org/scalacheck/ShrinkSpecification.scala index ad65260ad..83bc726cc 100644 --- a/src/test/scala/org/scalacheck/ShrinkSpecification.scala +++ b/src/test/scala/org/scalacheck/ShrinkSpecification.scala @@ -11,6 +11,7 @@ package org.scalacheck import Prop.{forAll, forAllNoShrink, BooleanOperators} import Shrink.shrink +import ScalaVersionSpecific._ import scala.concurrent.duration.{Duration, FiniteDuration} diff --git a/src/test/scala/org/scalacheck/util/BuildableSpecification.scala b/src/test/scala/org/scalacheck/util/BuildableSpecification.scala index 2311a8a65..4764f026d 100644 --- a/src/test/scala/org/scalacheck/util/BuildableSpecification.scala +++ b/src/test/scala/org/scalacheck/util/BuildableSpecification.scala @@ -10,9 +10,9 @@ package org.scalacheck package util -import language.higherKinds - -import collection._ +import scala.collection._ +import scala.language.higherKinds +import ScalaVersionSpecific._ object BuildableSpecification { def container[C[_]](implicit @@ -24,6 +24,8 @@ object BuildableSpecification { implicit val streamGen: Gen[Stream[String]] = container[Stream] + implicit val lazyListGen: Gen[LazyList[String]] = container[LazyList] + implicit val arrayGen: Gen[Array[String]] = container[Array] implicit val mutableSetGen: Gen[mutable.Set[String]] = container[mutable.Set]