diff options
author | Vojin Jovanovic <vojin.jovanovic@epfl.ch> | 2012-01-09 18:11:10 +0100 |
---|---|---|
committer | Vojin Jovanovic <vojin.jovanovic@epfl.ch> | 2012-01-09 18:11:10 +0100 |
commit | 1126912bce5d098571c1bd29a04e4781e19c3d85 (patch) | |
tree | 79e753014c1adfa26e39e32911125bfc0ad8ee4c /test | |
parent | 5a4b555c378d79d57b59dfd6edafd2b9a59866bb (diff) | |
parent | 820491ed6376e9f8f8a8102387495113dce55444 (diff) | |
download | scala-1126912bce5d098571c1bd29a04e4781e19c3d85.tar.gz scala-1126912bce5d098571c1bd29a04e4781e19c3d85.tar.bz2 scala-1126912bce5d098571c1bd29a04e4781e19c3d85.zip |
Merge branch 'master' into execution-context
Diffstat (limited to 'test')
105 files changed, 1401 insertions, 136 deletions
diff --git a/test/benchmarks/src/scala/collection/immutable/range-bench.scala b/test/benchmarks/src/scala/collection/immutable/range-bench.scala new file mode 100644 index 0000000000..e167ff04e8 --- /dev/null +++ b/test/benchmarks/src/scala/collection/immutable/range-bench.scala @@ -0,0 +1,61 @@ +package scala.collection.immutable +package benchmarks + +object RangeTest { + // not inlined any more, needs investigation + // + // class XXS { + // private val array = Array.range(0, 100) + // def tst = { var sum = 0; for (i <- 0 until array.length) sum += array(i); sum } + // } + + var x: Int = 0 + + def foreachSum(max: Int): Int = { + var sum = 0 + 1 to max foreach (sum += _) + sum + } + def whileSum(max: Int) = { + var sum = 0 + var num = 1 + while (num <= max) { + sum += num + num += 1 + } + sum + } + + def show(max: Int, foreachNanos: Long, whileNanos: Long) { + val winner = if (foreachNanos < whileNanos) "foreachSum" else "whileSum" + val ratio = if (foreachNanos < whileNanos) foreachNanos.toDouble / whileNanos else whileNanos.toDouble / foreachNanos + println("1 to %d:, %12s wins, %.3f: foreach %.3f while %.3f".format( + max, winner, ratio, + foreachNanos.toDouble / 1000000L, + whileNanos.toDouble / 1000000L) + ) + } + + def run(max: Int) = { + val foreachFirst = util.Random.nextBoolean + val t1 = System.nanoTime + x = if (foreachFirst) foreachSum(max) else whileSum(max) + val t2 = System.nanoTime + x = if (foreachFirst) whileSum(max) else foreachSum(max) + val t3 = System.nanoTime + + val foreachNanos = if (foreachFirst) t2 - t1 else t3 - t2 + val whileNanos = if (foreachFirst) t3 - t2 else t2 - t1 + show(max, foreachNanos, whileNanos) + } + + def main(args: Array[String]): Unit = { + var max = if (args.isEmpty) 100 else args(0).toInt + while (max > 0) { + run(max) + run(max) + run(max) + max += (max / 7) + } + } +} diff --git a/test/files/presentation/properties.check b/test/disabled/properties.check index a721d49e3a..a721d49e3a 100644 --- a/test/files/presentation/properties.check +++ b/test/disabled/properties.check diff --git a/test/files/presentation/properties/Runner.scala b/test/disabled/properties/Runner.scala index 1ef3cf9025..1ef3cf9025 100644 --- a/test/files/presentation/properties/Runner.scala +++ b/test/disabled/properties/Runner.scala diff --git a/test/files/presentation/properties/src/properties.scala b/test/disabled/properties/src/properties.scala index 35b6a92221..35b6a92221 100644 --- a/test/files/presentation/properties/src/properties.scala +++ b/test/disabled/properties/src/properties.scala diff --git a/test/files/continuations-neg/t2949.check b/test/files/continuations-neg/t2949.check index dd9768807c..411aed1b5b 100644 --- a/test/files/continuations-neg/t2949.check +++ b/test/files/continuations-neg/t2949.check @@ -1,6 +1,6 @@ t2949.scala:13: error: type mismatch; found : Int - required: ? @scala.util.continuations.cpsParam[List[?],Any] + required: ? @scala.util.continuations.cpsParam[List[?],?] x * y ^ one error found diff --git a/test/files/jvm/mkLibNatives.bat b/test/files/jvm/mkLibNatives.bat index e11b6ee21c..2f99f7aab5 100755 --- a/test/files/jvm/mkLibNatives.bat +++ b/test/files/jvm/mkLibNatives.bat @@ -67,4 +67,4 @@ goto end :end
if "%OS%"=="Windows_NT" @endlocal
-
+exit /b %errorlevel%
diff --git a/test/files/jvm/serialization.check b/test/files/jvm/serialization.check index 8704bcc643..15708f0c3b 100644 --- a/test/files/jvm/serialization.check +++ b/test/files/jvm/serialization.check @@ -160,8 +160,8 @@ x = Map(C -> 3, B -> 2, A -> 1) y = Map(C -> 3, A -> 1, B -> 2) x equals y: true, y equals x: true -x = Set(layers, title, buffers) -y = Set(layers, title, buffers) +x = Set(buffers, title, layers) +y = Set(buffers, title, layers) x equals y: true, y equals x: true x = History() @@ -279,8 +279,8 @@ x = ParHashMap(1 -> 2, 2 -> 4) y = ParHashMap(1 -> 2, 2 -> 4) x equals y: true, y equals x: true -x = ParHashSet(2, 1, 3) -y = ParHashSet(2, 1, 3) +x = ParHashSet(1, 2, 3) +y = ParHashSet(1, 2, 3) x equals y: true, y equals x: true x = ParRange(0, 1, 2, 3, 4) diff --git a/test/files/jvm/xml03syntax.check b/test/files/jvm/xml03syntax.check index 75dc539137..9fbedc2ae6 100644 --- a/test/files/jvm/xml03syntax.check +++ b/test/files/jvm/xml03syntax.check @@ -23,4 +23,4 @@ true 4 node=<elem key="<b>hello</b>"></elem>, key=Some(<b>hello</b>) -node=<elem ></elem>, key=None +node=<elem></elem>, key=None diff --git a/test/files/neg/checksensible.check b/test/files/neg/checksensible.check index d45d16165f..0881205bb4 100644 --- a/test/files/neg/checksensible.check +++ b/test/files/neg/checksensible.check @@ -28,12 +28,6 @@ checksensible.scala:27: error: comparing values of types Int and Unit using `==' checksensible.scala:29: error: comparing values of types Int and String using `==' will always yield false 1 == "abc" ^ -checksensible.scala:32: error: String and Int are unrelated: they will most likely never compare equal - "abc" == 1 // warns because the lub of String and Int is Any - ^ -checksensible.scala:33: error: Some[Int] and Int are unrelated: they will most likely never compare equal - Some(1) == 1 // as above - ^ checksensible.scala:38: error: comparing a fresh object using `==' will always yield false new AnyRef == 1 ^ @@ -100,4 +94,4 @@ checksensible.scala:84: error: comparing values of types EqEqRefTest.this.C3 and checksensible.scala:95: error: comparing values of types Unit and Int using `!=' will always yield true while ((c = in.read) != -1) ^ -34 errors found +32 errors found diff --git a/test/files/neg/logImplicits.check b/test/files/neg/logImplicits.check new file mode 100644 index 0000000000..d98422dacb --- /dev/null +++ b/test/files/neg/logImplicits.check @@ -0,0 +1,19 @@ +logImplicits.scala:2: applied implicit conversion from xs.type to ?{val size: ?} = implicit def byteArrayOps(xs: Array[Byte]): scala.collection.mutable.ArrayOps[Byte] + def f(xs: Array[Byte]) = xs.size + ^ +logImplicits.scala:7: applied implicit conversion from String("abc") to ?{val map: ?} = implicit def augmentString(x: String): scala.collection.immutable.StringOps + def f = "abc" map (_ + 1) + ^ +logImplicits.scala:15: inferred view from String("abc") to Int = C.this.convert:(p: String("abc"))Int + math.max(122, x: Int) + ^ +logImplicits.scala:19: applied implicit conversion from Int(1) to ?{val ->: ?} = implicit def any2ArrowAssoc[A](x: A): ArrowAssoc[A] + def f = (1 -> 2) + "c" + ^ +logImplicits.scala:19: applied implicit conversion from (Int, Int) to ?{val +: ?} = implicit def any2stringadd(x: Any): scala.runtime.StringAdd + def f = (1 -> 2) + "c" + ^ +logImplicits.scala:22: error: class Un needs to be abstract, since method unimplemented is not defined +class Un { + ^ +one error found diff --git a/test/files/neg/logImplicits.flags b/test/files/neg/logImplicits.flags new file mode 100644 index 0000000000..97e5ae94ef --- /dev/null +++ b/test/files/neg/logImplicits.flags @@ -0,0 +1 @@ +-Xlog-implicit-conversions
\ No newline at end of file diff --git a/test/files/neg/logImplicits.scala b/test/files/neg/logImplicits.scala new file mode 100644 index 0000000000..fb5dd8a025 --- /dev/null +++ b/test/files/neg/logImplicits.scala @@ -0,0 +1,25 @@ +class A { + def f(xs: Array[Byte]) = xs.size + def g(xs: Array[Byte]) = xs.length +} + +class B { + def f = "abc" map (_ + 1) +} + +object C { + final val x = "abc" + + implicit def convert(p: x.type): Int = 123 + + math.max(122, x: Int) +} + +class D { + def f = (1 -> 2) + "c" +} + +class Un { + // forcing post-typer failure, since we're only interested in the output from the above + def unimplemented: Int +}
\ No newline at end of file diff --git a/test/files/neg/migration28.check b/test/files/neg/migration28.check index 97146e88f7..d7dfacf3db 100644 --- a/test/files/neg/migration28.check +++ b/test/files/neg/migration28.check @@ -1,6 +1,5 @@ -migration28.scala:4: error: method scanRight in trait TraversableLike has changed semantics: -This scanRight definition has changed in 2.9. -The previous behavior can be reproduced with scanRight.reverse. +migration28.scala:4: error: method scanRight in trait TraversableLike has changed semantics in version 2.9.0: +The behavior of `scanRight` has changed. The previous behavior can be reproduced with scanRight.reverse. List(1,2,3,4,5).scanRight(0)(_+_) ^ one error found diff --git a/test/files/neg/names-defaults-neg.check b/test/files/neg/names-defaults-neg.check index 03e44f745d..01bbe2de4e 100644 --- a/test/files/neg/names-defaults-neg.check +++ b/test/files/neg/names-defaults-neg.check @@ -10,8 +10,7 @@ names-defaults-neg.scala:5: error: type mismatch; names-defaults-neg.scala:8: error: positional after named argument. test1(b = "(*", 23) ^ -names-defaults-neg.scala:13: error: reference to x is ambiguous; it is both, a parameter -name of the method and the name of a variable currently in scope. +names-defaults-neg.scala:13: error: reference to x is ambiguous; it is both a method parameter and a variable in scope. test2(x = 1) ^ names-defaults-neg.scala:15: error: not found: value c @@ -26,8 +25,7 @@ names-defaults-neg.scala:17: error: not found: value m names-defaults-neg.scala:18: error: not found: value m test7 { m = 1 } // no named arguments in argument block ^ -names-defaults-neg.scala:19: error: reference to x is ambiguous; it is both, a parameter -name of the method and the name of a variable currently in scope. +names-defaults-neg.scala:19: error: reference to x is ambiguous; it is both a method parameter and a variable in scope. test8(x = 1) ^ names-defaults-neg.scala:22: error: parameter specified twice: a @@ -85,7 +83,7 @@ names-defaults-neg.scala:76: error: no type parameters for method test4: (x: T[T --- because --- argument expression's type is not compatible with formal parameter type; found : List[Int] - required: ?T[?T[List[?T[X forSome { type X }]]]] + required: ?T Error occurred in an application involving default arguments. test4() ^ @@ -118,8 +116,7 @@ names-defaults-neg.scala:93: error: parameter specified twice: b names-defaults-neg.scala:98: error: unknown parameter name: m f3818(y = 1, m = 1) ^ -names-defaults-neg.scala:131: error: reference to var2 is ambiguous; it is both, a parameter -name of the method and the name of a variable currently in scope. +names-defaults-neg.scala:131: error: reference to var2 is ambiguous; it is both a method parameter and a variable in scope. delay(var2 = 40) ^ names-defaults-neg.scala:134: error: missing parameter type for expanded function ((x$1) => a = x$1) @@ -146,15 +143,13 @@ names-defaults-neg.scala:164: error: variable definition needs type because 'x' names-defaults-neg.scala:167: error: variable definition needs type because 'x' is used as a named argument in its body. def u6 { var x = u.f(x = "32") } ^ -names-defaults-neg.scala:170: error: reference to x is ambiguous; it is both, a parameter -name of the method and the name of a variable currently in scope. +names-defaults-neg.scala:170: error: reference to x is ambiguous; it is both a method parameter and a variable in scope. def u9 { var x: Int = u.f(x = 1) } ^ names-defaults-neg.scala:177: error: variable definition needs type because 'x' is used as a named argument in its body. class u15 { var x = u.f(x = 1) } ^ -names-defaults-neg.scala:180: error: reference to x is ambiguous; it is both, a parameter -name of the method and the name of a variable currently in scope. +names-defaults-neg.scala:180: error: reference to x is ambiguous; it is both a method parameter and a variable in scope. class u18 { var x: Int = u.f(x = 1) } ^ one warning found diff --git a/test/files/neg/t1960.check b/test/files/neg/t1960.check index dabf53f126..5238141c4e 100644 --- a/test/files/neg/t1960.check +++ b/test/files/neg/t1960.check @@ -1,4 +1,4 @@ -t1960.scala:5: error: parameter 'p' requires field but conflicts with p in 'TBase' +t1960.scala:5: error: parameter 'p' requires field but conflicts with method p in trait TBase class Aclass (p: Int) extends TBase { def g() { f(p) } } ^ one error found diff --git a/test/files/neg/t5354.check b/test/files/neg/t5354.check new file mode 100644 index 0000000000..e47cecb5fe --- /dev/null +++ b/test/files/neg/t5354.check @@ -0,0 +1,7 @@ +t5354.scala:9: error: ambiguous implicit values: + both method x123 in package foo of type => foo.Bippy + and method z of type => foo.Bippy + match expected type foo.Bippy + implicitly[Bippy] + ^ +one error found diff --git a/test/files/neg/t5354.scala b/test/files/neg/t5354.scala new file mode 100644 index 0000000000..99b5650155 --- /dev/null +++ b/test/files/neg/t5354.scala @@ -0,0 +1,15 @@ +package object foo { + implicit def x123: Bippy = new Bippy("x") +} +package foo { + class Bippy(override val toString: String){ } + class Dingus { + def f1 = { + implicit def z: Bippy = new Bippy("z") + implicitly[Bippy] + } + } + object Test extends App { + println(new Dingus().f1) + } +} diff --git a/test/files/neg/t5357.check b/test/files/neg/t5357.check new file mode 100644 index 0000000000..3385559071 --- /dev/null +++ b/test/files/neg/t5357.check @@ -0,0 +1,4 @@ +t5357.scala:5: error: Pattern variables must start with a lower-case letter. (SLS 8.1.1.) + case A: N => 1 + ^ +one error found diff --git a/test/files/neg/t5357.scala b/test/files/neg/t5357.scala new file mode 100644 index 0000000000..369a5568a4 --- /dev/null +++ b/test/files/neg/t5357.scala @@ -0,0 +1,9 @@ +trait M + +case class N() extends M { + def mytest(x: M) = x match { + case A: N => 1 + case _ => 0 + } +} + diff --git a/test/files/pos/t1459/App.scala b/test/files/pos/t1459/App.scala index 651b285b17..36e5022e94 100755 --- a/test/files/pos/t1459/App.scala +++ b/test/files/pos/t1459/App.scala @@ -1,7 +1,7 @@ package foo import base._ -object App extends Application { +object App extends scala.App { class Concrete extends AbstractBase { override def doStuff(params:java.lang.String*): Unit = println("doStuff invoked") } diff --git a/test/files/pos/t4063.scala b/test/files/pos/t4063.scala new file mode 100644 index 0000000000..5e19c42edc --- /dev/null +++ b/test/files/pos/t4063.scala @@ -0,0 +1,39 @@ +trait Parallel +trait Parallelizable[+ParRepr <: Parallel] + +trait PIterableLike[+T, +Repr <: Parallel] extends Parallel with Parallelizable[PIterableLike[T, Repr]] + +trait PMap[K, V] extends PIterableLike[(K, V), PMap[K, V]] +trait PSet[T] extends PIterableLike[T, PSet[T]] + +trait CIterableLike[+T, +Repr] + +trait CSet[T] extends CIterableLike[T, CSet[T]] with Parallelizable[PSet[T]] + +trait CMap[K, V] extends CIterableLike[(K, V), CMap[K, V]] with Parallelizable[PMap[K, V]] + +object Test { + var x = 0 + + def main() { + val map: CMap[Int, CSet[Int]] = new CMap[Int, CSet[Int]] {} + val set: CSet[Int] = new CSet[Int] {} + + // should infer type argument + //map.synchronized[CIterableLike[Any, Any] with Parallelizable[PIterableLike[Any, Parallel with Parallelizable[Parallel]]]] { + // or: + //map.synchronized[CIterableLike[Any, Any] with Parallelizable[PIterableLike[Any, Parallel]]] { + // or, maybe it could also infer existential types: + //map.synchronized[CIterableLike[Any, _] with Parallelizable[PIterableLike[Any, _]]] { + + map.synchronized { + if (x == 0) { + map + } else { + set + } + } + + } +} + diff --git a/test/files/pos/t4070.scala b/test/files/pos/t4070.scala new file mode 100644 index 0000000000..29c8d16e30 --- /dev/null +++ b/test/files/pos/t4070.scala @@ -0,0 +1,37 @@ +package a { + // method before classes + trait Foo { + def crash(x: Dingus[_]): Unit = x match { case m: Bippy[tv] => () } + + class Dingus[T] + class Bippy[CC[X] <: Seq[X]]() extends Dingus[CC[Int]] + } +} + +package b { + // classes before method + trait Foo { + class Dingus[T] + class Bippy[CC[X] <: Seq[X]]() extends Dingus[CC[Int]] + + def crash(x: Dingus[_]): Unit = x match { case m: Bippy[tv] => () } + } +} + + +/* +// With crash below the clasess: +% scalac -Dscalac.debug.tvar ./a.scala +[ create] ?_$1 ( In Foo#crash ) +[ setInst] tv[Int] ( In Foo#crash, _$1=tv[Int] ) +[ create] tv[Int] ( In Foo#crash ) +[ clone] tv[Int] ( Foo#crash ) + +// With crash above the classes: +% scalac -Dscalac.debug.tvar ./a.scala +[ create] ?tv ( In Foo#crash ) +./a.scala:2: error: Invalid type application in TypeVar: List(), List(Int) + def crash(x: Dingus[_]): Unit = x match { case m: Bippy[tv] => () } + ^ +one error found +*/ diff --git a/test/files/pos/t4070b.scala b/test/files/pos/t4070b.scala new file mode 100644 index 0000000000..36d03de80c --- /dev/null +++ b/test/files/pos/t4070b.scala @@ -0,0 +1,35 @@ +package a { + abstract class DeliteOp[B] + abstract class DeliteCollection[A] + abstract class Exp[T] { def Type: T } + + trait DeliteOpMap[A,B,C[X] <: DeliteCollection[X]] extends DeliteOp[C[B]] { + val in: Exp[C[A]] + val func: Exp[B] + val alloc: Exp[C[B]] + } + + object Test { + def f(x: DeliteOp[_]) = x match { + case map: DeliteOpMap[_,_,_] => map.alloc.Type + } + } +} + +package b { + object Test { + def f(x: DeliteOp[_]) = x match { + case map: DeliteOpMap[_,_,_] => map.alloc.Type + } + } + + abstract class DeliteOp[B] + abstract class DeliteCollection[A] + abstract class Exp[T] { def Type: T } + + trait DeliteOpMap[A,B,C[X] <: DeliteCollection[X]] extends DeliteOp[C[B]] { + val in: Exp[C[A]] + val func: Exp[B] + val alloc: Exp[C[B]] + } +}
\ No newline at end of file diff --git a/test/files/pos/t4273.scala b/test/files/pos/t4273.scala new file mode 100644 index 0000000000..9a942e8325 --- /dev/null +++ b/test/files/pos/t4273.scala @@ -0,0 +1,8 @@ +class A { + implicit def compareComparables[T](x: T)(implicit ord: Ordering[T]) = new ord.Ops(x) + + class Bippy + implicit val bippyOrdering = new Ordering[Bippy] { def compare(x: Bippy, y: Bippy) = util.Random.nextInt } + + (new Bippy) < (new Bippy) +}
\ No newline at end of file diff --git a/test/files/pos/t5020.scala b/test/files/pos/t5020.scala new file mode 100644 index 0000000000..06f7723f9f --- /dev/null +++ b/test/files/pos/t5020.scala @@ -0,0 +1,19 @@ +package a { + sealed trait GenericList[U, M[_ <: U]] { + type Transformed[N[MMA <: U]] <: GenericList[U, N] + } + + trait GenericCons[U, M[_ <: U], T <: GenericList[U, M]] extends GenericList[U, M] { + type Transformed[N[MMB <: U]] = GenericCons[U, N, GenericList[U, M]#Transformed[N]] + } +} + +package b { + sealed trait GenericList[L, M[_ >: L]] { + type Transformed[N[MMA >: L]] <: GenericList[L, N] + } + + trait GenericCons[L, M[_ >: L], T <: GenericList[L, M]] extends GenericList[L, M] { + type Transformed[N[MMB >: L]] = GenericCons[L, N, T#Transformed[N]] + } +}
\ No newline at end of file diff --git a/test/files/pos/t5119.scala b/test/files/pos/t5119.scala new file mode 100644 index 0000000000..4a67244e50 --- /dev/null +++ b/test/files/pos/t5119.scala @@ -0,0 +1,13 @@ +import collection.mutable + +object Test { + class IMap0[K[_], V[_]](backing: Map[K[_], V[_]]) { + def mapSeparate[VL[_], VR[_]](f: V[_] => ({type l[T] = Either[VL[T], VR[T]]})#l[_] ) = { + backing.view.map { case (k,v) => f(v) match { + case Left(l) => Left((k, l)) + case Right(r) => Right((k, r)) + } + } + } + } +} diff --git a/test/files/pos/t5175.flags b/test/files/pos/t5175.flags new file mode 100644 index 0000000000..e8fb65d50c --- /dev/null +++ b/test/files/pos/t5175.flags @@ -0,0 +1 @@ +-Xfatal-warnings
\ No newline at end of file diff --git a/test/files/pos/t5175.scala b/test/files/pos/t5175.scala new file mode 100644 index 0000000000..e15cc3affd --- /dev/null +++ b/test/files/pos/t5175.scala @@ -0,0 +1,9 @@ +object Test { + def ==(p: Phase): Int = 0 + + def foo { + ==(new Phase()) + } +} + +class Phase diff --git a/test/files/pos/t5317.scala b/test/files/pos/t5317.scala new file mode 100644 index 0000000000..8c9c9d8222 --- /dev/null +++ b/test/files/pos/t5317.scala @@ -0,0 +1,12 @@ +object Test { + trait S { type T; val x: AnyRef } + trait A extends S { type T <: A; val x: A = null } + trait B extends S { type T <: B; val x: B = null } + + val a = new A{} + val b = new B{} + val y = if (true) a else b + + // lub of y should allow for this + println(y.x.x) +} diff --git a/test/files/pos/t5359.scala b/test/files/pos/t5359.scala new file mode 100644 index 0000000000..c22b2b1c76 --- /dev/null +++ b/test/files/pos/t5359.scala @@ -0,0 +1,17 @@ +// /scala/trac/5359/a.scala +// Thu Jan 5 13:31:05 PST 2012 + +object test { + trait Step[F[_]] { + // crash: typeConstructor inapplicable for <none> + this match { + case S1() => + } + } + case class S1[F[_]]() extends Step[F] + + // okay + (null: Step[Option]) match { + case S1() => + } +} diff --git a/test/files/pos/virtpatmat_alts_subst.flags b/test/files/pos/virtpatmat_alts_subst.flags new file mode 100644 index 0000000000..9769db9257 --- /dev/null +++ b/test/files/pos/virtpatmat_alts_subst.flags @@ -0,0 +1 @@ + -Yvirtpatmat -Xexperimental diff --git a/test/files/pos/virtpatmat_alts_subst.scala b/test/files/pos/virtpatmat_alts_subst.scala new file mode 100644 index 0000000000..e27c52f9c7 --- /dev/null +++ b/test/files/pos/virtpatmat_alts_subst.scala @@ -0,0 +1,6 @@ +case class Foo(s: String) { + def appliedType(tycon: Any) = + tycon match { + case Foo(sym @ ("NothingClass" | "AnyClass")) => println(sym) + } +} diff --git a/test/files/pos/virtpatmat_binding_opt.flags b/test/files/pos/virtpatmat_binding_opt.flags new file mode 100644 index 0000000000..9769db9257 --- /dev/null +++ b/test/files/pos/virtpatmat_binding_opt.flags @@ -0,0 +1 @@ + -Yvirtpatmat -Xexperimental diff --git a/test/files/pos/virtpatmat_binding_opt.scala b/test/files/pos/virtpatmat_binding_opt.scala new file mode 100644 index 0000000000..962e3d7dbe --- /dev/null +++ b/test/files/pos/virtpatmat_binding_opt.scala @@ -0,0 +1,11 @@ +class Test { + def combine = this match { + case that if that eq this => this // just return this + case that: Test2 => + println(that) + this + case _ => error("meh") + } +} + +class Test2 extends Test
\ No newline at end of file diff --git a/test/files/run/array-existential-bound.check b/test/files/run/array-existential-bound.check new file mode 100644 index 0000000000..f5cca843e3 --- /dev/null +++ b/test/files/run/array-existential-bound.check @@ -0,0 +1,4 @@ +2 +1000 +1000 +26 diff --git a/test/files/run/array-existential-bound.scala b/test/files/run/array-existential-bound.scala new file mode 100644 index 0000000000..bc442d39f7 --- /dev/null +++ b/test/files/run/array-existential-bound.scala @@ -0,0 +1,17 @@ +trait Fooz[Q <: Array[_]] { + def f0(x: Q) = x.length +} + +object Test extends Fooz[Array[Int]] { + val f1 = new Fooz[Array[String]] { } + val f2 = new Fooz[Array[Int]] { } + val f3 = new Fooz[Array[Any]] { } + val f4 = new Fooz[Array[_]] { } + + def main(args: Array[String]): Unit = { + println(f1.f0(Array[String]("a", "b"))) + println(f2.f0(1 to 1000 toArray)) + println(f3.f0((1 to 1000).toArray[Any])) + println(f4.f0('a' to 'z' toArray)) + } +} diff --git a/test/files/run/mixin-bridge-methods.scala b/test/files/run/mixin-bridge-methods.scala new file mode 100644 index 0000000000..e0340ebb12 --- /dev/null +++ b/test/files/run/mixin-bridge-methods.scala @@ -0,0 +1,14 @@ +trait Foo { + def getFoo() = "foo" +} + +class Sub extends Foo { + def getBar() = "bar" +} + +object Test { + def main(args: Array[String]): Unit = { + val ms = classOf[Sub].getDeclaredMethods + assert(ms forall (x => !x.isBridge), ms mkString " ") + } +} diff --git a/test/files/run/origins.scala b/test/files/run/origins.scala index ab873bca89..9dc6071c7b 100644 --- a/test/files/run/origins.scala +++ b/test/files/run/origins.scala @@ -1,4 +1,4 @@ -import scala.tools.nsc.util.Origins +import scala.reflect.internal.util.Origins package goxbox { object Socks { diff --git a/test/files/run/repl-power.check b/test/files/run/repl-power.check index 38e7532133..1e7b6f0cd8 100644 --- a/test/files/run/repl-power.check +++ b/test/files/run/repl-power.check @@ -2,15 +2,31 @@ Type in expressions to have them evaluated. Type :help for more information. scala> :power -** Power User mode enabled - BEEP BOOP SPIZ ** +** Power User mode enabled - BEEP WHIR GYVE ** ** :phase has been set to 'typer'. ** ** scala.tools.nsc._ has been imported ** -** global._ and definitions._ also imported ** -** Try :help, vals.<tab>, power.<tab> ** +** global._, definitions._ also imported ** +** Try :help, :vals, power.<tab> ** scala> // guarding against "error: reference to global is ambiguous" scala> global.emptyValDef // "it is imported twice in the same scope by ..." res0: $r.global.emptyValDef.type = private val _ = _ +scala> val tp = ArrayClass[scala.util.Random] // magic with manifests +tp: $r.global.Type = Array[scala.util.Random] + +scala> tp.memberType(Array_apply) // evidence +res1: $r.global.Type = (i: Int)scala.util.Random + +scala> val m = LIT(10) MATCH (CASE(LIT(5)) ==> FALSE, DEFAULT ==> TRUE) // treedsl +m: $r.treedsl.global.Match = +10 match { + case 5 => false + case _ => true +} + +scala> typed(m).tpe // typed is in scope +res2: $r.treedsl.global.Type = Boolean + scala> diff --git a/test/files/run/repl-power.scala b/test/files/run/repl-power.scala index 9f70ac4b68..27da3df106 100644 --- a/test/files/run/repl-power.scala +++ b/test/files/run/repl-power.scala @@ -5,6 +5,10 @@ object Test extends ReplTest { :power // guarding against "error: reference to global is ambiguous" global.emptyValDef // "it is imported twice in the same scope by ..." +val tp = ArrayClass[scala.util.Random] // magic with manifests +tp.memberType(Array_apply) // evidence +val m = LIT(10) MATCH (CASE(LIT(5)) ==> FALSE, DEFAULT ==> TRUE) // treedsl +typed(m).tpe // typed is in scope """.trim } diff --git a/test/files/run/t3758.scala b/test/files/run/t3758.scala new file mode 100644 index 0000000000..18750b0a9c --- /dev/null +++ b/test/files/run/t3758.scala @@ -0,0 +1,10 @@ +object Test { + def main(args: Array[String]): Unit = { + assert(classManifest[Array[String]].typeArguments contains classManifest[String]) + assert(classManifest[Array[Int]].typeArguments contains classManifest[Int]) + assert(classManifest[Array[Float]].typeArguments contains classManifest[Float]) + assert(manifest[Array[String]].typeArguments contains manifest[String]) + assert(manifest[Array[Int]].typeArguments contains manifest[Int]) + assert(manifest[Array[Float]].typeArguments contains manifest[Float]) + } +} diff --git a/test/files/run/t4024.scala b/test/files/run/t4024.scala index ef768beb99..7c62a3fc6e 100644 --- a/test/files/run/t4024.scala +++ b/test/files/run/t4024.scala @@ -5,5 +5,16 @@ object Test extends App { val m = x.getClass.getMethod("toString") assert(m.invoke(x, (Nil: List[AnyRef]): _*) == "abc") + + Test2.main(Array()) } + +object Test2 { + def main(args: Array[String]): Unit = { + val x = "abc" + val m = x.getClass.getMethod("toString") + m.invoke(x, Nil: _*) + m.invoke(x, Seq(): _*) + } +} diff --git a/test/files/run/t4871.check b/test/files/run/t4871.check new file mode 100644 index 0000000000..a60526a0f3 --- /dev/null +++ b/test/files/run/t4871.check @@ -0,0 +1,2 @@ +class Test$C +class Test$D diff --git a/test/files/run/t4871.scala b/test/files/run/t4871.scala new file mode 100644 index 0000000000..70d8b7145c --- /dev/null +++ b/test/files/run/t4871.scala @@ -0,0 +1,12 @@ +object Test { + class C + class D + + def main(args: Array[String]): Unit = { + val z: Class[C] = classOf + val z2: Class[D] = classOf[D] + + println(z) + println(z2) + } +} diff --git a/test/files/run/t5053.check b/test/files/run/t5053.check new file mode 100644 index 0000000000..5ec39bbdeb --- /dev/null +++ b/test/files/run/t5053.check @@ -0,0 +1,6 @@ +true +true +true +true +true +true diff --git a/test/files/run/t5053.scala b/test/files/run/t5053.scala new file mode 100644 index 0000000000..e46dad5ac6 --- /dev/null +++ b/test/files/run/t5053.scala @@ -0,0 +1,20 @@ +object Test extends App { + { + val (left, right) = Seq((1, "a"), (1, "a"), (1, "a"), (3, "c")).view.unzip + println(left.isInstanceOf[scala.collection.SeqViewLike[_,_,_]]) + val (l, m, r) = Seq((1, 1.0, "a"), (1, 1.0, "a"), (1, 1.0, "a"), (3, 3.0, "c")).view.unzip3 + println(l.isInstanceOf[scala.collection.SeqViewLike[_,_,_]]) + } + { + val (left, right) = Iterable((1, "a"), (1, "a"), (1, "a"), (3, "c")).view.unzip + println(left.isInstanceOf[scala.collection.IterableViewLike[_,_,_]]) + val (l, m, r) = Iterable((1, 1.0, "a"), (1, 1.0, "a"), (1, 1.0, "a"), (3, 3.0, "c")).view.unzip3 + println(l.isInstanceOf[scala.collection.IterableViewLike[_,_,_]]) + } + { + val (left, right) = Traversable((1, "a"), (1, "a"), (1, "a"), (3, "c")).view.unzip + println(left.isInstanceOf[scala.collection.TraversableViewLike[_,_,_]]) + val (l, m, r) = Traversable((1, 1.0, "a"), (1, 1.0, "a"), (1, 1.0, "a"), (3, 3.0, "c")).view.unzip3 + println(l.isInstanceOf[scala.collection.TraversableViewLike[_,_,_]]) + } +} diff --git a/test/files/run/t5239.check b/test/files/run/t5239.check deleted file mode 100644 index db5778f95b..0000000000 --- a/test/files/run/t5239.check +++ /dev/null @@ -1,13 +0,0 @@ -result = 2{Int(2)} -[[syntax trees at end of typer]]// Scala source: NoSourceFile -package <empty> { - final object __wrapper$1 extends Object { - def this(): object __wrapper$1 = { - __wrapper$1.super.this(); - () - }; - <static> def wrapper(): Int = 2 - } -} - -evaluated = 2 diff --git a/test/pending/run/t5266_1.check b/test/files/run/t5266_1.check index 3feac16a0b..3feac16a0b 100644 --- a/test/pending/run/t5266_1.check +++ b/test/files/run/t5266_1.check diff --git a/test/files/run/t5239.scala b/test/files/run/t5266_1.scala index 1f404196ba..18e288e685 100644 --- a/test/files/run/t5239.scala +++ b/test/files/run/t5266_1.scala @@ -4,17 +4,13 @@ import reflect.runtime.Mirror.ToolBox object Test extends App { val code = scala.reflect.Code.lift{ - 2 + def x = 2 + println(x) }; - val settings = new Settings - settings.Xprint.value = List("typer") - - val reporter = new ConsoleReporter(settings) + val reporter = new ConsoleReporter(new Settings) val toolbox = new ToolBox(reporter) val ttree = toolbox.typeCheck(code.tree) - println("result = " + toolbox.showAttributed(ttree)) - val evaluated = toolbox.runExpr(ttree) println("evaluated = " + evaluated) -} +}
\ No newline at end of file diff --git a/test/pending/run/t5266_2.check b/test/files/run/t5266_2.check index 3feac16a0b..3feac16a0b 100644 --- a/test/pending/run/t5266_2.check +++ b/test/files/run/t5266_2.check diff --git a/test/pending/run/t5266_2.scala b/test/files/run/t5266_2.scala index cd841da021..eb319583f8 100644 --- a/test/pending/run/t5266_2.scala +++ b/test/files/run/t5266_2.scala @@ -9,7 +9,7 @@ object Test extends App { println(y) }; - val reporter = new ConsoleReporter(settings) + val reporter = new ConsoleReporter(new Settings) val toolbox = new ToolBox(reporter) val ttree = toolbox.typeCheck(code.tree) val evaluated = toolbox.runExpr(ttree) diff --git a/test/files/run/t5293.scala b/test/files/run/t5293.scala new file mode 100644 index 0000000000..de1efaec4a --- /dev/null +++ b/test/files/run/t5293.scala @@ -0,0 +1,83 @@ + + + +import scala.collection.JavaConverters._ + + + +object Test extends App { + + def bench(label: String)(body: => Unit): Long = { + val start = System.nanoTime + + 0.until(10).foreach(_ => body) + + val end = System.nanoTime + + //println("%s: %s ms".format(label, (end - start) / 1000.0 / 1000.0)) + + end - start + } + + def benchJava(values: java.util.Collection[Int]) = { + bench("Java Set") { + val set = new java.util.HashSet[Int] + + set.addAll(values) + } + } + + def benchScala(values: Iterable[Int]) = { + bench("Scala Set") { + val set = new scala.collection.mutable.HashSet[Int] + + set ++= values + } + } + + def benchScalaSorted(values: Iterable[Int]) = { + bench("Scala Set sorted") { + val set = new scala.collection.mutable.HashSet[Int] + + set ++= values.toArray.sorted + } + } + + def benchScalaPar(values: Iterable[Int]) = { + bench("Scala ParSet") { + val set = new scala.collection.parallel.mutable.ParHashSet[Int] map { x => x } + + set ++= values + } + } + + val values = 0 until 50000 + val set = scala.collection.mutable.HashSet.empty[Int] + + set ++= values + + // warmup + for (x <- 0 until 5) { + benchJava(set.asJava) + benchScala(set) + benchScalaPar(set) + benchJava(set.asJava) + benchScala(set) + benchScalaPar(set) + } + + val javaset = benchJava(set.asJava) + val scalaset = benchScala(set) + val scalaparset = benchScalaPar(set) + + assert(scalaset < (javaset * 4)) + assert(scalaparset < (javaset * 4)) +} + + + + + + + + diff --git a/test/files/run/t5300.scala b/test/files/run/t5300.scala new file mode 100644 index 0000000000..073b29604a --- /dev/null +++ b/test/files/run/t5300.scala @@ -0,0 +1,7 @@ +object Test { + val pf: PartialFunction[Any, Unit] = { case _ => () } + + def main(args: Array[String]): Unit = { + pf orElse pf + } +} diff --git a/test/files/run/t5356.check b/test/files/run/t5356.check new file mode 100644 index 0000000000..21c4aef07b --- /dev/null +++ b/test/files/run/t5356.check @@ -0,0 +1,6 @@ +1 scala.runtime.RichInt +1 scala.runtime.RichInt +1 scala.math.BigInt +1 scala.runtime.RichDouble +1 scala.runtime.RichFloat +1 diff --git a/test/files/run/t5356.scala b/test/files/run/t5356.scala new file mode 100644 index 0000000000..f7696c6088 --- /dev/null +++ b/test/files/run/t5356.scala @@ -0,0 +1,12 @@ +object Test { + def f(x: { def toInt: Int }) = println(x.toInt + " " + x.getClass.getName) + + def main(args: Array[String]): Unit = { + f(1) + f(1.toInt) + f(BigInt(1)) + f(1d) + f(1f) + println((1: { def toInt: Int }).toInt) + } +} diff --git a/test/files/run/treePrint.scala b/test/files/run/treePrint.scala index 745c2150c2..e0332a705f 100644 --- a/test/files/run/treePrint.scala +++ b/test/files/run/treePrint.scala @@ -35,7 +35,7 @@ object Test { settings.Ycompacttrees.value = true val intp = new IMain(settings, new PrintWriter(new NullOutputStream)) - val power = Power(intp) + val power = new Power(intp, new ReplVals { }) intp.interpret("""def initialize = "Have to interpret something or we get errors." """) power trees code foreach println } diff --git a/test/files/run/type-currying.check b/test/files/run/type-currying.check new file mode 100644 index 0000000000..e5db238ca5 --- /dev/null +++ b/test/files/run/type-currying.check @@ -0,0 +1,27 @@ +Map(abc -> 55) +(a,0) +(b,1) +(c,2) +(d,3) +(e,4) +(f,5) +(g,6) +(h,7) +(i,8) +(j,9) +(k,10) +(l,11) +(m,12) +(n,13) +(o,14) +(p,15) +(q,16) +(r,17) +(s,18) +(t,19) +(u,20) +(v,21) +(w,22) +(x,23) +(y,24) +(z,25) diff --git a/test/files/run/type-currying.scala b/test/files/run/type-currying.scala new file mode 100644 index 0000000000..f9764c64f0 --- /dev/null +++ b/test/files/run/type-currying.scala @@ -0,0 +1,58 @@ +import scala.collection.{ mutable, immutable, generic } +import generic.CanBuildFrom + +object Partial { + type KnownContainer[CC[K, V] <: collection.Map[K, V]] = { + def values[V] : KnownValues[CC, V] + def apply[K] : KnownKeys[CC, K] + } + type KnownKeys[CC[K, V] <: collection.Map[K, V], K] = { + def apply[V](implicit cbf: CanBuildFrom[_, (K, V), CC[K, V]]): CC[K, V] + } + type KnownValues[CC[K, V] <: collection.Map[K, V], V] = { + def apply[K](implicit cbf: CanBuildFrom[_, (K, V), CC[K, V]]): CC[K, V] + } + + def apply[CC[K, V] <: collection.Map[K, V]] : KnownContainer[CC] = new { + def values[V] : KnownValues[CC, V] = new { + def apply[K](implicit cbf: CanBuildFrom[_, (K, V), CC[K, V]]) = cbf().result + } + def apply[K] = new { + def apply[V](implicit cbf: CanBuildFrom[_, (K, V), CC[K, V]]) = cbf().result + } + } +} + +object Test { + val m = Partial[immutable.TreeMap] + val m1 = m[String] + val m2 = m[Int][Int] + + val mutableBippy = Partial[mutable.HashMap][String][Int] + mutableBippy("abc") = 55 + + val immutableBippy = Partial[immutable.HashMap].values[Int] + def make[T](xs: T*) = immutableBippy[T] ++ xs.zipWithIndex + + val n0 = Partial[immutable.HashMap][String][Int] ++ Seq(("a", 1)) + val n1 = Partial.apply[immutable.HashMap].apply[String].apply[Int] ++ Seq(("a", 1)) + + def main(args: Array[String]): Unit = { + println(mutableBippy) + make('a' to 'z': _*).toList.sorted foreach println + assert(n0 == n1) + } +} + +class A { + object Foo { + def apply[T] = Bar + } + object Bar { + def apply() = Foo + } + + def f() = Foo + def g = f()[Int]()[String]() + def h = Foo[Foo.type]()[Foo.type]() +} diff --git a/test/files/run/virtpatmat_literal.scala b/test/files/run/virtpatmat_literal.scala index cb72b1d2a5..5bd6b30791 100644 --- a/test/files/run/virtpatmat_literal.scala +++ b/test/files/run/virtpatmat_literal.scala @@ -1,8 +1,9 @@ object Test extends App { + val a = 1 1 match { case 2 => println("FAILED") case 1 => println("OK") - case 1 => println("FAILED") + case `a` => println("FAILED") } val one = 1 diff --git a/test/files/run/virtpatmat_opt_sharing.check b/test/files/run/virtpatmat_opt_sharing.check new file mode 100644 index 0000000000..d00491fd7e --- /dev/null +++ b/test/files/run/virtpatmat_opt_sharing.check @@ -0,0 +1 @@ +1 diff --git a/test/files/run/virtpatmat_opt_sharing.flags b/test/files/run/virtpatmat_opt_sharing.flags new file mode 100644 index 0000000000..9769db9257 --- /dev/null +++ b/test/files/run/virtpatmat_opt_sharing.flags @@ -0,0 +1 @@ + -Yvirtpatmat -Xexperimental diff --git a/test/files/run/virtpatmat_opt_sharing.scala b/test/files/run/virtpatmat_opt_sharing.scala new file mode 100644 index 0000000000..119e3050ea --- /dev/null +++ b/test/files/run/virtpatmat_opt_sharing.scala @@ -0,0 +1,10 @@ +object Test extends App { + virtMatch() + def virtMatch() = { + List(1, 3, 4, 7) match { + case 1 :: 3 :: 4 :: 5 :: x => println("nope") + case 1 :: 3 :: 4 :: 6 :: x => println("nope") + case 1 :: 3 :: 4 :: 7 :: x => println(1) + } + } +}
\ No newline at end of file diff --git a/test/files/run/virtpatmat_unapplyprod.check b/test/files/run/virtpatmat_unapplyprod.check new file mode 100644 index 0000000000..2660ff8f96 --- /dev/null +++ b/test/files/run/virtpatmat_unapplyprod.check @@ -0,0 +1,4 @@ +(2,3) +(2,3) +(2,3) +List(true, false, true) diff --git a/test/files/run/virtpatmat_unapplyprod.flags b/test/files/run/virtpatmat_unapplyprod.flags new file mode 100644 index 0000000000..9769db9257 --- /dev/null +++ b/test/files/run/virtpatmat_unapplyprod.flags @@ -0,0 +1 @@ + -Yvirtpatmat -Xexperimental diff --git a/test/files/run/virtpatmat_unapplyprod.scala b/test/files/run/virtpatmat_unapplyprod.scala new file mode 100644 index 0000000000..441e5e3968 --- /dev/null +++ b/test/files/run/virtpatmat_unapplyprod.scala @@ -0,0 +1,23 @@ +object Test extends App { + case class Foo(x: Int, y: String) + + Foo(2, "3") match { + case Foo(x, y) => println((x, y)) + } + + case class FooSeq(x: Int, y: String, z: Boolean*) + + FooSeq(2, "3") match { + case FooSeq(x, y) => println((x, y)) + } + + FooSeq(2, "3", true, false, true) match { + case FooSeq(x, y) => println("nope") + case FooSeq(x, y, true, false, true) => println((x, y)) + } + + FooSeq(1, "a", true, false, true) match { + case FooSeq(1, "a") => println("nope") + case FooSeq(1, "a", x@_* ) => println(x.toList) + } +}
\ No newline at end of file diff --git a/test/files/run/xml-attribute.scala b/test/files/run/xml-attribute.scala new file mode 100644 index 0000000000..8b261acc94 --- /dev/null +++ b/test/files/run/xml-attribute.scala @@ -0,0 +1,33 @@ +import xml.Node + +object Test { + def main(args: Array[String]): Unit = { + val noAttr = <t/> + val attrNull = <t a={ null: String }/> + val attrNone = <t a={ None: Option[Seq[Node]] }/> + val preAttrNull = <t p:a={ null: String }/> + val preAttrNone = <t p:a={ None: Option[Seq[Node]] }/> + assert(noAttr == attrNull) + assert(noAttr == attrNone) + assert(noAttr == preAttrNull) + assert(noAttr == preAttrNone) + + val noAttrStr = "<t></t>" + assert(noAttr.toString() == noAttrStr) + assert(attrNull.toString() == noAttrStr) + assert(attrNone.toString() == noAttrStr) + assert(preAttrNull.toString() == noAttrStr) + assert(preAttrNone.toString() == noAttrStr) + + val xml1 = <t b="1" d="2"/> + val xml2 = <t a={ null: String } p:a={ null: String } b="1" c={ null: String } d="2"/> + val xml3 = <t b="1" c={ null: String } d="2" a={ null: String } p:a={ null: String }/> + assert(xml1 == xml2) + assert(xml1 == xml3) + + val xml1Str = "<t d=\"2\" b=\"1\"></t>" + assert(xml1.toString() == xml1Str) + assert(xml2.toString() == xml1Str) + assert(xml3.toString() == xml1Str) + } +} diff --git a/test/files/scalacheck/CheckEither.scala b/test/files/scalacheck/CheckEither.scala index a7e50877a7..0145d3321f 100644 --- a/test/files/scalacheck/CheckEither.scala +++ b/test/files/scalacheck/CheckEither.scala @@ -8,7 +8,7 @@ import org.scalacheck.Test.{Params, check} import org.scalacheck.ConsoleReporter.testStatsEx import Function.tupled -object CheckEither extends Properties("Either") { +object Test extends Properties("Either") { implicit def arbitraryEither[X, Y](implicit xa: Arbitrary[X], ya: Arbitrary[Y]): Arbitrary[Either[X, Y]] = Arbitrary[Either[X, Y]](oneOf(arbitrary[X].map(Left(_)), arbitrary[Y].map(Right(_)))) @@ -186,9 +186,3 @@ object CheckEither extends Properties("Either") { STest.checkProperties(STest.Params(testCallback = ConsoleReporter(0)), this) } } - -object Test { - def main(args: Array[String]): Unit = { - CheckEither.runTests() - } -} diff --git a/test/files/scalacheck/nan-ordering.scala b/test/files/scalacheck/nan-ordering.scala new file mode 100644 index 0000000000..2094a46e37 --- /dev/null +++ b/test/files/scalacheck/nan-ordering.scala @@ -0,0 +1,130 @@ +import org.scalacheck._ +import Gen._ +import Prop._ + +object Test extends Properties("NaN-Ordering") { + + val specFloats: Gen[Float] = oneOf( + Float.MaxValue, + Float.MinPositiveValue, + Float.MinValue, + Float.NaN, + Float.NegativeInfinity, + Float.PositiveInfinity, + -0.0f, + +0.0f + ) + + property("Float min") = forAll(specFloats, specFloats) { (d1, d2) => { + val mathmin = math.min(d1, d2) + val numericmin = d1 min d2 + mathmin == numericmin || mathmin.isNaN && numericmin.isNaN + } + } + + property("Float max") = forAll(specFloats, specFloats) { (d1, d2) => { + val mathmax = math.max(d1, d2) + val numericmax = d1 max d2 + mathmax == numericmax || mathmax.isNaN && numericmax.isNaN + } + } + + val numFloat = implicitly[Numeric[Float]] + + property("Float lt") = forAll(specFloats, specFloats) { (d1, d2) => numFloat.lt(d1, d2) == d1 < d2 } + + property("Float lteq") = forAll(specFloats, specFloats) { (d1, d2) => numFloat.lteq(d1, d2) == d1 <= d2 } + + property("Float gt") = forAll(specFloats, specFloats) { (d1, d2) => numFloat.gt(d1, d2) == d1 > d2 } + + property("Float gteq") = forAll(specFloats, specFloats) { (d1, d2) => numFloat.gteq(d1, d2) == d1 >= d2 } + + property("Float equiv") = forAll(specFloats, specFloats) { (d1, d2) => numFloat.equiv(d1, d2) == (d1 == d2) } + + property("Float reverse.min") = forAll(specFloats, specFloats) { (d1, d2) => { + val mathmin = math.min(d1, d2) + val numericmin = numFloat.reverse.min(d1, d2) + mathmin == numericmin || mathmin.isNaN && numericmin.isNaN + } + } + + property("Float reverse.max") = forAll(specFloats, specFloats) { (d1, d2) => { + val mathmax = math.max(d1, d2) + val numericmax = numFloat.reverse.max(d1, d2) + mathmax == numericmax || mathmax.isNaN && numericmax.isNaN + } + } + + property("Float reverse.lt") = forAll(specFloats, specFloats) { (d1, d2) => numFloat.reverse.lt(d1, d2) == d2 < d1 } + + property("Float reverse.lteq") = forAll(specFloats, specFloats) { (d1, d2) => numFloat.reverse.lteq(d1, d2) == d2 <= d1 } + + property("Float reverse.gt") = forAll(specFloats, specFloats) { (d1, d2) => numFloat.reverse.gt(d1, d2) == d2 > d1 } + + property("Float reverse.gteq") = forAll(specFloats, specFloats) { (d1, d2) => numFloat.reverse.gteq(d1, d2) == d2 >= d1 } + + property("Float reverse.equiv") = forAll(specFloats, specFloats) { (d1, d2) => numFloat.reverse.equiv(d1, d2) == (d1 == d2) } + + + val specDoubles: Gen[Double] = oneOf( + Double.MaxValue, + Double.MinPositiveValue, + Double.MinValue, + Double.NaN, + Double.NegativeInfinity, + Double.PositiveInfinity, + -0.0, + +0.0 + ) + + // ticket #5104 + property("Double min") = forAll(specDoubles, specDoubles) { (d1, d2) => { + val mathmin = math.min(d1, d2) + val numericmin = d1 min d2 + mathmin == numericmin || mathmin.isNaN && numericmin.isNaN + } + } + + property("Double max") = forAll(specDoubles, specDoubles) { (d1, d2) => { + val mathmax = math.max(d1, d2) + val numericmax = d1 max d2 + mathmax == numericmax || mathmax.isNaN && numericmax.isNaN + } + } + + val numDouble = implicitly[Numeric[Double]] + + property("Double lt") = forAll(specDoubles, specDoubles) { (d1, d2) => numDouble.lt(d1, d2) == d1 < d2 } + + property("Double lteq") = forAll(specDoubles, specDoubles) { (d1, d2) => numDouble.lteq(d1, d2) == d1 <= d2 } + + property("Double gt") = forAll(specDoubles, specDoubles) { (d1, d2) => numDouble.gt(d1, d2) == d1 > d2 } + + property("Double gteq") = forAll(specDoubles, specDoubles) { (d1, d2) => numDouble.gteq(d1, d2) == d1 >= d2 } + + property("Double equiv") = forAll(specDoubles, specDoubles) { (d1, d2) => numDouble.equiv(d1, d2) == (d1 == d2) } + + property("Double reverse.min") = forAll(specDoubles, specDoubles) { (d1, d2) => { + val mathmin = math.min(d1, d2) + val numericmin = numDouble.reverse.min(d1, d2) + mathmin == numericmin || mathmin.isNaN && numericmin.isNaN + } + } + + property("Double reverse.max") = forAll(specDoubles, specDoubles) { (d1, d2) => { + val mathmax = math.max(d1, d2) + val numericmax = numDouble.reverse.max(d1, d2) + mathmax == numericmax || mathmax.isNaN && numericmax.isNaN + } + } + + property("Double reverse.lt") = forAll(specDoubles, specDoubles) { (d1, d2) => numDouble.reverse.lt(d1, d2) == d2 < d1 } + + property("Double reverse.lteq") = forAll(specDoubles, specDoubles) { (d1, d2) => numDouble.reverse.lteq(d1, d2) == d2 <= d1 } + + property("Double reverse.gt") = forAll(specDoubles, specDoubles) { (d1, d2) => numDouble.reverse.gt(d1, d2) == d2 > d1 } + + property("Double reverse.gteq") = forAll(specDoubles, specDoubles) { (d1, d2) => numDouble.reverse.gteq(d1, d2) == d2 >= d1 } + + property("Double reverse.equiv") = forAll(specDoubles, specDoubles) { (d1, d2) => numDouble.reverse.equiv(d1, d2) == (d1 == d2) } +} diff --git a/test/files/scalacheck/range.scala b/test/files/scalacheck/range.scala index 56295f204c..72979115be 100644 --- a/test/files/scalacheck/range.scala +++ b/test/files/scalacheck/range.scala @@ -12,10 +12,16 @@ class Counter(r: Range) { if (cnt % 500000000L == 0L) { println("Working: %s %d %d" format (str, cnt, x)) } - if (cnt > (Int.MaxValue.toLong + 1) * 2) - error("Count exceeds maximum possible for an Int Range") - if ((r.step > 0 && last.exists(_ > x)) || (r.step < 0 && last.exists(_ < x))) - error("Range wrapped: %d %s" format (x, last.toString)) + if (cnt > (Int.MaxValue.toLong + 1) * 2) { + val msg = "Count exceeds maximum possible for an Int Range: %s" format str + println(msg) // exception is likely to be eaten by an out of memory error + sys error msg + } + if ((r.step > 0 && last.exists(_ > x)) || (r.step < 0 && last.exists(_ < x))) { + val msg = "Range %s wrapped: %d %s" format (str, x, last.toString) + println(msg) // exception is likely to be eaten by an out of memory error + sys error msg + } last = Some(x) } } @@ -23,29 +29,40 @@ class Counter(r: Range) { abstract class RangeTest(kind: String) extends Properties("Range "+kind) { def myGen: Gen[Range] - val genRange = for { - start <- arbitrary[Int] - end <- arbitrary[Int] - step <- Gen.choose(1, (start - end).abs + 1) - } yield if (start < end) Range(start, end, step) else Range(start, end, -step) - - val genReasonableSizeRange = for { - start <- choose(-Int.MinValue, Int.MaxValue) - end <- choose(-Int.MinValue, Int.MaxValue) + def genReasonableSizeRange = oneOf(genArbitraryRange, genBoundaryRange) + + def genArbitraryRange = for { + start <- choose(Int.MinValue, Int.MaxValue) + end <- choose(Int.MinValue, Int.MaxValue) step <- choose(-Int.MaxValue, Int.MaxValue) } yield Range(start, end, if (step == 0) 100 else step) - val genSmallRange = for { + def genBoundaryRange = for { + boundary <- oneOf(Int.MinValue, -1, 0, 1, Int.MaxValue) + isStart <- arbitrary[Boolean] + size <- choose(1, 100) + step <- choose(1, 101) + } yield { + val signum = if (boundary == 0) 1 else boundary.signum + if (isStart) Range(boundary, boundary - size * boundary.signum, - step * signum) + else Range(boundary - size * boundary.signum, boundary, step * signum) + } + + + def genSmallRange = for { start <- choose(-100, 100) end <- choose(-100, 100) step <- choose(1, 1) } yield if (start < end) Range(start, end, step) else Range(start, end, -step) - val genRangeByOne = for { - start <- arbitrary[Int] - end <- arbitrary[Int] - if (end.toLong - start.toLong).abs <= 10000000L - } yield if (start < end) Range(start, end) else Range(end, start) + def genRangeByOne = oneOf(genRangeOpenByOne, genRangeClosedByOne) + + def genRangeOpenByOne = for { + r <- oneOf(genSmallRange, genBoundaryRange) + if (r.end.toLong - r.start.toLong).abs <= 10000000L + } yield if (r.start < r.end) Range(r.start, r.end) else Range(r.end, r.start) + + def genRangeClosedByOne = for (r <- genRangeOpenByOne) yield r.start to r.end def str(r: Range) = "Range["+r.start+", "+r.end+", "+r.step+(if (r.isInclusive) "]" else ")") @@ -71,7 +88,8 @@ abstract class RangeTest(kind: String) extends Properties("Range "+kind) { def multiple(r: Range, x: Int) = (x.toLong - r.start) % r.step == 0 - property("foreach.step") = forAll(myGen) { r => + property("foreach.step") = forAllNoShrink(myGen) { r => +// println("foreach.step "+str(r)) var allValid = true val cnt = new Counter(r) // println("--------------------") @@ -84,6 +102,7 @@ abstract class RangeTest(kind: String) extends Properties("Range "+kind) { } property("foreach.inside.range") = forAll(myGen) { r => +// println("foreach.inside.range "+str(r)) var allValid = true var last: Option[Int] = None val cnt = new Counter(r) @@ -94,6 +113,7 @@ abstract class RangeTest(kind: String) extends Properties("Range "+kind) { } property("foreach.visited.size") = forAll(myGen) { r => +// println("foreach.visited.size "+str(r)) var visited = 0L val cnt = new Counter(r) r foreach { x => cnt(x) @@ -108,14 +128,17 @@ abstract class RangeTest(kind: String) extends Properties("Range "+kind) { } property("length") = forAll(myGen suchThat (r => expectedSize(r).toInt == expectedSize(r))) { r => +// println("length "+str(r)) (r.length == expectedSize(r)) :| str(r) } property("isEmpty") = forAll(myGen suchThat (r => expectedSize(r).toInt == expectedSize(r))) { r => +// println("isEmpty "+str(r)) (r.isEmpty == (expectedSize(r) == 0L)) :| str(r) } property("contains") = forAll(myGen, arbInt.arbitrary) { (r, x) => +// println("contains "+str(r)) // println("----------------") // println(str(r)) // println(x) @@ -126,11 +149,13 @@ abstract class RangeTest(kind: String) extends Properties("Range "+kind) { } property("take") = forAll(myGen suchThat (r => expectedSize(r).toInt == expectedSize(r)), arbInt.arbitrary) { (r, x) => +// println("take "+str(r)) val t = r take x (t.size == (0 max x min r.size) && t.start == r.start && t.step == r.step) :| str(r)+" / "+str(t)+": "+x } property("init") = forAll(myGen suchThat (r => expectedSize(r).toInt == expectedSize(r))) { r => +// println("init "+str(r)) (r.size == 0) || { val t = r.init (t.size + 1 == r.size) && (t.isEmpty || t.head == r.head) @@ -138,6 +163,7 @@ abstract class RangeTest(kind: String) extends Properties("Range "+kind) { } property("takeWhile") = forAll(myGen suchThat (r => expectedSize(r).toInt == expectedSize(r)), arbInt.arbitrary) { (r, x) => +// println("takeWhile "+str(r)) val t = (if (r.step > 0) r takeWhile (_ <= x) else r takeWhile(_ >= x)) if (r.size == 0) { (t.size == 0) :| str(r)+" / "+str(t)+": "+x @@ -148,6 +174,7 @@ abstract class RangeTest(kind: String) extends Properties("Range "+kind) { } property("reverse.toSet.equal") = forAll(myGen) { r => +// println("reverse.toSet.equal "+str(r)) val reversed = r.reverse val aresame = r.toSet == reversed.toSet if (!aresame) { @@ -157,7 +184,7 @@ abstract class RangeTest(kind: String) extends Properties("Range "+kind) { println(r.toSet) println(reversed.toSet) } - aresame + aresame :| str(r) } } @@ -178,11 +205,11 @@ object InclusiveRangeTest extends RangeTest("inclusive") { } object ByOneRangeTest extends RangeTest("byOne") { - override def myGen = genSmallRange + override def myGen = genRangeByOne } object InclusiveByOneRangeTest extends RangeTest("inclusiveByOne") { - override def myGen = for (r <- genSmallRange) yield r.inclusive + override def myGen = for (r <- genRangeByOne) yield r.inclusive } object SmallValuesRange extends RangeTest("smallValues") { @@ -207,9 +234,11 @@ object TooLargeRange extends Properties("Too Large Range") { object Test extends Properties("Range") { import org.scalacheck.{ Test => STest } - List(NormalRangeTest, InclusiveRangeTest, ByOneRangeTest, InclusiveByOneRangeTest, TooLargeRange) foreach { ps => - STest.checkProperties(STest.Params(testCallback = ConsoleReporter(0)), ps) - } + include(NormalRangeTest) + include(InclusiveRangeTest) + include(ByOneRangeTest) + include(InclusiveByOneRangeTest) + include(TooLargeRange) } /* Mini-benchmark diff --git a/test/partest.bat b/test/partest.bat index 0b3f5fbf33..4c97a53122 100755 --- a/test/partest.bat +++ b/test/partest.bat @@ -101,3 +101,4 @@ goto end :end
if "%OS%"=="Windows_NT" @endlocal
+exit /b %errorlevel%
diff --git a/test/pending/run/reify_closure1.check b/test/pending/run/reify_closure1.check new file mode 100644 index 0000000000..b2f7f08c17 --- /dev/null +++ b/test/pending/run/reify_closure1.check @@ -0,0 +1,2 @@ +10 +10 diff --git a/test/pending/run/reify_closure1.scala b/test/pending/run/reify_closure1.scala new file mode 100644 index 0000000000..825a38dc1d --- /dev/null +++ b/test/pending/run/reify_closure1.scala @@ -0,0 +1,20 @@ +import scala.tools.nsc.reporters._ +import scala.tools.nsc.Settings +import reflect.runtime.Mirror.ToolBox + +object Test extends App { + def foo[T](ys: List[T]): Int => Int = { + val fun: reflect.Code[Int => Int] = x => { + x + } + + val reporter = new ConsoleReporter(new Settings) + val toolbox = new ToolBox(reporter) + val ttree = toolbox.typeCheck(fun.tree) + val dyn = toolbox.runExpr(ttree) + dyn.asInstanceOf[Int => Int] + } + + println(foo(List(1, 2, 3))(10)) + println(foo(List(1, 2, 3, 4))(10)) +} diff --git a/test/pending/run/reify_closure2a.check b/test/pending/run/reify_closure2a.check new file mode 100644 index 0000000000..c1f3abd7e6 --- /dev/null +++ b/test/pending/run/reify_closure2a.check @@ -0,0 +1,2 @@ +11 +12 diff --git a/test/pending/run/reify_closure2a.scala b/test/pending/run/reify_closure2a.scala new file mode 100644 index 0000000000..b88bec005d --- /dev/null +++ b/test/pending/run/reify_closure2a.scala @@ -0,0 +1,20 @@ +import scala.tools.nsc.reporters._ +import scala.tools.nsc.Settings +import reflect.runtime.Mirror.ToolBox + +object Test extends App { + def foo(y: Int): Int => Int = { + val fun: reflect.Code[Int => Int] = x => { + x + y + } + + val reporter = new ConsoleReporter(new Settings) + val toolbox = new ToolBox(reporter) + val ttree = toolbox.typeCheck(fun.tree) + val dyn = toolbox.runExpr(ttree) + dyn.asInstanceOf[Int => Int] + } + + println(foo(1)(10)) + println(foo(2)(10)) +} diff --git a/test/pending/run/reify_closure2b.check b/test/pending/run/reify_closure2b.check new file mode 100644 index 0000000000..c1f3abd7e6 --- /dev/null +++ b/test/pending/run/reify_closure2b.check @@ -0,0 +1,2 @@ +11 +12 diff --git a/test/pending/run/reify_closure2b.scala b/test/pending/run/reify_closure2b.scala new file mode 100644 index 0000000000..e9fb40bede --- /dev/null +++ b/test/pending/run/reify_closure2b.scala @@ -0,0 +1,22 @@ +import scala.tools.nsc.reporters._ +import scala.tools.nsc.Settings +import reflect.runtime.Mirror.ToolBox + +object Test extends App { + def foo(y: Int): Int => Int = { + class Foo(y: Int) { + val fun: reflect.Code[Int => Int] = x => { + x + y + } + } + + val reporter = new ConsoleReporter(new Settings) + val toolbox = new ToolBox(reporter) + val ttree = toolbox.typeCheck(new Foo(y).fun.tree) + val dyn = toolbox.runExpr(ttree) + dyn.asInstanceOf[Int => Int] + } + + println(foo(1)(10)) + println(foo(2)(10)) +} diff --git a/test/pending/run/reify_closure3a.check b/test/pending/run/reify_closure3a.check new file mode 100644 index 0000000000..c1f3abd7e6 --- /dev/null +++ b/test/pending/run/reify_closure3a.check @@ -0,0 +1,2 @@ +11 +12 diff --git a/test/pending/run/reify_closure3a.scala b/test/pending/run/reify_closure3a.scala new file mode 100644 index 0000000000..6414fa58a3 --- /dev/null +++ b/test/pending/run/reify_closure3a.scala @@ -0,0 +1,22 @@ +import scala.tools.nsc.reporters._ +import scala.tools.nsc.Settings +import reflect.runtime.Mirror.ToolBox + +object Test extends App { + def foo(y: Int): Int => Int = { + def y1 = y + + val fun: reflect.Code[Int => Int] = x => { + x + y1 + } + + val reporter = new ConsoleReporter(new Settings) + val toolbox = new ToolBox(reporter) + val ttree = toolbox.typeCheck(fun.tree) + val dyn = toolbox.runExpr(ttree) + dyn.asInstanceOf[Int => Int] + } + + println(foo(1)(10)) + println(foo(2)(10)) +} diff --git a/test/pending/run/reify_closure3b.check b/test/pending/run/reify_closure3b.check new file mode 100644 index 0000000000..c1f3abd7e6 --- /dev/null +++ b/test/pending/run/reify_closure3b.check @@ -0,0 +1,2 @@ +11 +12 diff --git a/test/pending/run/reify_closure3b.scala b/test/pending/run/reify_closure3b.scala new file mode 100644 index 0000000000..5c4f3c81b9 --- /dev/null +++ b/test/pending/run/reify_closure3b.scala @@ -0,0 +1,24 @@ +import scala.tools.nsc.reporters._ +import scala.tools.nsc.Settings +import reflect.runtime.Mirror.ToolBox + +object Test extends App { + def foo(y: Int): Int => Int = { + class Foo(y: Int) { + def y1 = y + + val fun: reflect.Code[Int => Int] = x => { + x + y1 + } + } + + val reporter = new ConsoleReporter(new Settings) + val toolbox = new ToolBox(reporter) + val ttree = toolbox.typeCheck(new Foo(y).fun.tree) + val dyn = toolbox.runExpr(ttree) + dyn.asInstanceOf[Int => Int] + } + + println(foo(1)(10)) + println(foo(2)(10)) +} diff --git a/test/pending/run/reify_closure4a.check b/test/pending/run/reify_closure4a.check new file mode 100644 index 0000000000..c1f3abd7e6 --- /dev/null +++ b/test/pending/run/reify_closure4a.check @@ -0,0 +1,2 @@ +11 +12 diff --git a/test/pending/run/reify_closure4a.scala b/test/pending/run/reify_closure4a.scala new file mode 100644 index 0000000000..99e9d82706 --- /dev/null +++ b/test/pending/run/reify_closure4a.scala @@ -0,0 +1,22 @@ +import scala.tools.nsc.reporters._ +import scala.tools.nsc.Settings +import reflect.runtime.Mirror.ToolBox + +object Test extends App { + def foo(y: Int): Int => Int = { + val y1 = y + + val fun: reflect.Code[Int => Int] = x => { + x + y1 + } + + val reporter = new ConsoleReporter(new Settings) + val toolbox = new ToolBox(reporter) + val ttree = toolbox.typeCheck(fun.tree) + val dyn = toolbox.runExpr(ttree) + dyn.asInstanceOf[Int => Int] + } + + println(foo(1)(10)) + println(foo(2)(10)) +} diff --git a/test/pending/run/reify_closure4b.check b/test/pending/run/reify_closure4b.check new file mode 100644 index 0000000000..c1f3abd7e6 --- /dev/null +++ b/test/pending/run/reify_closure4b.check @@ -0,0 +1,2 @@ +11 +12 diff --git a/test/pending/run/reify_closure4b.scala b/test/pending/run/reify_closure4b.scala new file mode 100644 index 0000000000..24dfa9fe17 --- /dev/null +++ b/test/pending/run/reify_closure4b.scala @@ -0,0 +1,24 @@ +import scala.tools.nsc.reporters._ +import scala.tools.nsc.Settings +import reflect.runtime.Mirror.ToolBox + +object Test extends App { + def foo(y: Int): Int => Int = { + class Foo(y: Int) { + val y1 = y + + val fun: reflect.Code[Int => Int] = x => { + x + y1 + } + } + + val reporter = new ConsoleReporter(new Settings) + val toolbox = new ToolBox(reporter) + val ttree = toolbox.typeCheck(new Foo(y).fun.tree) + val dyn = toolbox.runExpr(ttree) + dyn.asInstanceOf[Int => Int] + } + + println(foo(1)(10)) + println(foo(2)(10)) +} diff --git a/test/pending/run/reify_closure5a.check b/test/pending/run/reify_closure5a.check new file mode 100644 index 0000000000..df9e19c591 --- /dev/null +++ b/test/pending/run/reify_closure5a.check @@ -0,0 +1,2 @@ +13 +14 diff --git a/test/pending/run/reify_closure5a.scala b/test/pending/run/reify_closure5a.scala new file mode 100644 index 0000000000..0ac53d5479 --- /dev/null +++ b/test/pending/run/reify_closure5a.scala @@ -0,0 +1,20 @@ +import scala.tools.nsc.reporters._ +import scala.tools.nsc.Settings +import reflect.runtime.Mirror.ToolBox + +object Test extends App { + def foo[T](ys: List[T]): Int => Int = { + val fun: reflect.Code[Int => Int] = x => { + x + ys.length + } + + val reporter = new ConsoleReporter(new Settings) + val toolbox = new ToolBox(reporter) + val ttree = toolbox.typeCheck(fun.tree) + val dyn = toolbox.runExpr(ttree) + dyn.asInstanceOf[Int => Int] + } + + println(foo(List(1, 2, 3))(10)) + println(foo(List(1, 2, 3, 4))(10)) +} diff --git a/test/pending/run/reify_closure5b.check b/test/pending/run/reify_closure5b.check new file mode 100644 index 0000000000..df9e19c591 --- /dev/null +++ b/test/pending/run/reify_closure5b.check @@ -0,0 +1,2 @@ +13 +14 diff --git a/test/pending/run/reify_closure5b.scala b/test/pending/run/reify_closure5b.scala new file mode 100644 index 0000000000..02eb771f0c --- /dev/null +++ b/test/pending/run/reify_closure5b.scala @@ -0,0 +1,22 @@ +import scala.tools.nsc.reporters._ +import scala.tools.nsc.Settings +import reflect.runtime.Mirror.ToolBox + +object Test extends App { + def foo[T](ys: List[T]): Int => Int = { + class Foo[T](ys: List[T]) { + val fun: reflect.Code[Int => Int] = x => { + x + ys.length + } + } + + val reporter = new ConsoleReporter(new Settings) + val toolbox = new ToolBox(reporter) + val ttree = toolbox.typeCheck(new Foo(ys).fun.tree) + val dyn = toolbox.runExpr(ttree) + dyn.asInstanceOf[Int => Int] + } + + println(foo(List(1, 2, 3))(10)) + println(foo(List(1, 2, 3, 4))(10)) +} diff --git a/test/pending/run/reify_closure6.check b/test/pending/run/reify_closure6.check new file mode 100644 index 0000000000..3526d04b0e --- /dev/null +++ b/test/pending/run/reify_closure6.check @@ -0,0 +1,3 @@ +first invocation = 15 +second invocation = 18 +q after second invocation = 2 diff --git a/test/pending/run/reify_closure6.scala b/test/pending/run/reify_closure6.scala new file mode 100644 index 0000000000..909071aa44 --- /dev/null +++ b/test/pending/run/reify_closure6.scala @@ -0,0 +1,26 @@ +import scala.tools.nsc.reporters._ +import scala.tools.nsc.Settings +import reflect.runtime.Mirror.ToolBox + +object Test extends App { + var q = 0 + def foo[T](ys: List[T]): Int => Int = { + val z = 1 + var y = 0 + val fun: reflect.Code[Int => Int] = x => { + y += 1 + q += 1 + x + ys.length * z + q + y + } + + val reporter = new ConsoleReporter(new Settings) + val toolbox = new ToolBox(reporter) + val ttree = toolbox.typeCheck(fun.tree) + val dyn = toolbox.runExpr(ttree) + dyn.asInstanceOf[Int => Int] + } + + println("first invocation = " + foo(List(1, 2, 3))(10)) + println("second invocation = " + foo(List(1, 2, 3, 4))(10)) + println("q after second invocation = " + q) +} diff --git a/test/pending/run/t5266_1.scala b/test/pending/run/t5266_1.scala deleted file mode 100644 index 06a81a04ea..0000000000 --- a/test/pending/run/t5266_1.scala +++ /dev/null @@ -1,23 +0,0 @@ -import scala.tools.nsc.reporters._ -import scala.tools.nsc.Settings -import reflect.runtime.Mirror.ToolBox - -object Test extends App { - val code = scala.reflect.Code.lift{ - def x = 2 - println(x) - }; - - val settings = new Settings - settings.debug.value = true - settings.Xshowtrees.value = true - settings.Xprint.value = List("typer") - settings.printtypes.value = true - settings.Ytyperdebug.value = true - - val reporter = new ConsoleReporter(settings) - val toolbox = new ToolBox(reporter) - val ttree = toolbox.typeCheck(code.tree) - val evaluated = toolbox.runExpr(ttree) - println("evaluated = " + evaluated) -}
\ No newline at end of file diff --git a/test/pending/run/t5334_1.scala b/test/pending/run/t5334_1.scala new file mode 100644 index 0000000000..c1eba89c2b --- /dev/null +++ b/test/pending/run/t5334_1.scala @@ -0,0 +1,15 @@ +import scala.tools.nsc.reporters._ +import scala.tools.nsc.Settings +import reflect.runtime.Mirror.ToolBox + +object Test extends App { + val code = scala.reflect.Code.lift{ + class C + new C + }; + + val reporter = new ConsoleReporter(new Settings) + val toolbox = new ToolBox(reporter) + val ttree = toolbox.typeCheck(code.tree) + toolbox.runExpr(ttree) +} diff --git a/test/pending/run/t5334_2.scala b/test/pending/run/t5334_2.scala new file mode 100644 index 0000000000..361b8c85f2 --- /dev/null +++ b/test/pending/run/t5334_2.scala @@ -0,0 +1,15 @@ +import scala.tools.nsc.reporters._ +import scala.tools.nsc.Settings +import reflect.runtime.Mirror.ToolBox + +object Test extends App { + val code = scala.reflect.Code.lift{ + class C + List((new C, new C)) + }; + + val reporter = new ConsoleReporter(new Settings) + val toolbox = new ToolBox(reporter) + val ttree = toolbox.typeCheck(code.tree) + toolbox.runExpr(ttree) +} diff --git a/test/scaladoc/resources/SI_5054.scala b/test/scaladoc/resources/SI_5054.scala deleted file mode 100644 index 17167303e4..0000000000 --- a/test/scaladoc/resources/SI_5054.scala +++ /dev/null @@ -1,10 +0,0 @@ -class SI_5054 { - - /** - * A simple comment - * - * @param lost a lost parameter - * @usecase def test(): Int - */ - def test(implicit lost: Int): Int = lost -}
\ No newline at end of file diff --git a/test/scaladoc/resources/SI_5054_q1.scala b/test/scaladoc/resources/SI_5054_q1.scala new file mode 100644 index 0000000000..02d9be8dd0 --- /dev/null +++ b/test/scaladoc/resources/SI_5054_q1.scala @@ -0,0 +1,9 @@ +class SI_5054_q1 { + /** + * A simple comment + * + * @param lost a lost parameter + * @usecase def test(): Int + */ + def test(implicit lost: Int): Int = lost +} diff --git a/test/scaladoc/resources/SI_5054_q2.scala b/test/scaladoc/resources/SI_5054_q2.scala new file mode 100644 index 0000000000..c873731e5b --- /dev/null +++ b/test/scaladoc/resources/SI_5054_q2.scala @@ -0,0 +1,9 @@ +class SI_5054_q2 { + /** + * A simple comment + * + * @param lost a lost parameter + * @usecase def test(): Int + */ + final def test(implicit lost: Int): Int = lost +} diff --git a/test/scaladoc/resources/SI_5054_q3.scala b/test/scaladoc/resources/SI_5054_q3.scala new file mode 100644 index 0000000000..be5d22ffdc --- /dev/null +++ b/test/scaladoc/resources/SI_5054_q3.scala @@ -0,0 +1,9 @@ +class SI_5054_q3 { + /** + * A simple comment + * + * @param lost a lost parameter + * @usecase def test(): Int + */ + implicit def test(implicit lost: Int): Int = lost +} diff --git a/test/scaladoc/resources/SI_5054_q4.scala b/test/scaladoc/resources/SI_5054_q4.scala new file mode 100644 index 0000000000..4e5e4865f1 --- /dev/null +++ b/test/scaladoc/resources/SI_5054_q4.scala @@ -0,0 +1,9 @@ +abstract class SI_5054_q4 { + /** + * A simple comment + * + * @param lost a lost parameter + * @usecase def test(): Int + */ + def test(implicit lost: Int): Int +} diff --git a/test/scaladoc/resources/SI_5054_q5.scala b/test/scaladoc/resources/SI_5054_q5.scala new file mode 100644 index 0000000000..05ba7488eb --- /dev/null +++ b/test/scaladoc/resources/SI_5054_q5.scala @@ -0,0 +1,9 @@ +trait SI_5054_q5 { + /** + * A simple comment + * + * @param lost a lost parameter + * @usecase def test(): Int + */ + def test(implicit lost: Int): Int = lost +} diff --git a/test/scaladoc/resources/SI_5054_q6.scala b/test/scaladoc/resources/SI_5054_q6.scala new file mode 100644 index 0000000000..607be654a5 --- /dev/null +++ b/test/scaladoc/resources/SI_5054_q6.scala @@ -0,0 +1,9 @@ +trait SI_5054_q6 { + /** + * A simple comment + * + * @param lost a lost parameter + * @usecase def test(): Int + */ + def test(implicit lost: Int): Int +} diff --git a/test/scaladoc/resources/SI_5054_q7.scala b/test/scaladoc/resources/SI_5054_q7.scala new file mode 100644 index 0000000000..1bd120e30c --- /dev/null +++ b/test/scaladoc/resources/SI_5054_q7.scala @@ -0,0 +1,22 @@ +trait SI_5054_q7 { + /** + * The full definition, either used with an implicit value or with an explicit one. + * + * Some more explanation on implicits... + * + * @param lost a lost parameter + * @return some integer + * @usecase def test1(): Int + * + * This takes the implicit value in scope. + * + * Example: `test1()` + * + * @usecase def test2(explicit: Int): Int + * + * This takes the explicit value passed. + * + * Example: `test2(3)` + */ + def test(implicit lost: Int): Int +} diff --git a/test/scaladoc/resources/SI_5287.scala b/test/scaladoc/resources/SI_5287.scala new file mode 100644 index 0000000000..141ab15325 --- /dev/null +++ b/test/scaladoc/resources/SI_5287.scala @@ -0,0 +1,17 @@ +trait SI_5287_A { + def method(implicit a: Int): Int = a +} + +trait SI_5287_B extends SI_5287_A { + override def method(implicit a: Int): Int = a + 1 +} + +trait SI_5287 extends SI_5287_B{ + /** + * Some explanation + * + * @usecase def method(): Int + * The usecase explanation + */ + override def method(implicit a: Int): Int = a + 3 +}
\ No newline at end of file diff --git a/test/scaladoc/scala/html.flags b/test/scaladoc/scala/html.flags new file mode 100644 index 0000000000..b2264ec4f4 --- /dev/null +++ b/test/scaladoc/scala/html.flags @@ -0,0 +1 @@ +-encoding UTF-8
\ No newline at end of file diff --git a/test/scaladoc/scala/html/HtmlFactoryTest.flags b/test/scaladoc/scala/html/HtmlFactoryTest.flags new file mode 100644 index 0000000000..b2264ec4f4 --- /dev/null +++ b/test/scaladoc/scala/html/HtmlFactoryTest.flags @@ -0,0 +1 @@ +-encoding UTF-8
\ No newline at end of file diff --git a/test/scaladoc/scala/html/HtmlFactoryTest.scala b/test/scaladoc/scala/html/HtmlFactoryTest.scala index c8dad4cf48..5b17affbf0 100644 --- a/test/scaladoc/scala/html/HtmlFactoryTest.scala +++ b/test/scaladoc/scala/html/HtmlFactoryTest.scala @@ -21,6 +21,9 @@ object XMLUtil { } object Test extends Properties("HtmlFactory") { + + final val RESOURCES = "test/scaladoc/resources/" + import scala.tools.nsc.doc.{DocFactory, Settings} import scala.tools.nsc.doc.model.IndexModelFactory import scala.tools.nsc.doc.html.HtmlFactory @@ -47,7 +50,7 @@ object Test extends Properties("HtmlFactory") { def createTemplates(basename: String) = { val result = scala.collection.mutable.Map[String, scala.xml.NodeSeq]() - createFactory.makeUniverse(List("test/scaladoc/resources/"+basename)) match { + createFactory.makeUniverse(List(RESOURCES+basename)) match { case Some(universe) => { val index = IndexModelFactory.makeIndex(universe) (new HtmlFactory(universe, index)).writeTemplates((page) => { @@ -61,7 +64,7 @@ object Test extends Properties("HtmlFactory") { } def createReferenceIndex(basename: String) = { - createFactory.makeUniverse(List("test/scaladoc/resources/"+basename)) match { + createFactory.makeUniverse(List(RESOURCES+basename)) match { case Some(universe) => { val index = IndexModelFactory.makeIndex(universe) val pages = index.firstLetterIndex.map({ @@ -81,6 +84,52 @@ object Test extends Properties("HtmlFactory") { val html = scala.stripSuffix(".scala") + ".html" createTemplates(scala)(html) } + + /** + * See checkTextOnly(scalaFile: String, checks: List[String]) + */ + def checkText1(scalaFile: String, check: String, debug: Boolean = true): Boolean = checkText(scalaFile, List(check), debug) + + /** + * This tests the text without the markup - ex: + * + * <h4 class="signature"> + * <span class="modifier_kind"> + * <span class="modifier">implicit</span> + * <span class="kind">def</span> + * </span> + * <span class="symbol"> + * <span class="name">test</span><span class="params">()</span><span class="result">: <span name="scala.Int" class="extype">Int</span></span> + * </span> + * </h4> + * + * becomes: + * + * implicit def test(): Int + * + * and is required to contain the text in the given checks + * + * NOTE: Comparison is done ignoring all whitespace + */ + def checkText(scalaFile: String, checks: List[String], debug: Boolean = true): Boolean = { + val htmlFile = scalaFile.stripSuffix(".scala") + ".html" + val htmlText = createTemplates(scalaFile)(htmlFile).text.replace('→',' ').replaceAll("\\s+","") + var result = true + + for (check <- checks) { + val checkText = check.replace('→',' ').replaceAll("\\s+","") + val checkValue = htmlText.contains(checkText) + if (debug && (!checkValue)) { + Console.err.println("Check failed: ") + Console.err.println("HTML: " + htmlText) + Console.err.println("Check: " + checkText) + } + result &&= checkValue + } + + result + } + def shortComments(root: scala.xml.Node) = XMLUtil.stripGroup(root).descendant.flatMap { @@ -377,20 +426,43 @@ object Test extends Properties("HtmlFactory") { createTemplate("SI_4898.scala") true } + + property("Use cases should override their original members") = + checkText1("SI_5054_q1.scala", """def test(): Int""") && + !checkText1("SI_5054_q1.scala", """def test(implicit lost: Int): Int""") + - property("Use cases should override their original members - valid until signature is added to html") = { - createTemplate("SI_5054.scala") match { - case node: scala.xml.Node => - node.toString.contains("A simple comment") && - ! node.toString.contains("a lost parameter") - case _ => false - } - } - + property("Use cases should keep their flags - final should not be lost") = + checkText1("SI_5054_q2.scala", """final def test(): Int""") + + property("Use cases should keep their flags - implicit should not be lost") = + checkText1("SI_5054_q3.scala", """implicit def test(): Int""") + + property("Use cases should keep their flags - real abstract should not be lost") = + checkText1("SI_5054_q4.scala", """abstract def test(): Int""") + + property("Use cases should keep their flags - traits should not be affected") = + checkText1("SI_5054_q5.scala", """def test(): Int""") + + property("Use cases should keep their flags - traits should not be affected") = + checkText1("SI_5054_q6.scala", """abstract def test(): Int""") + + property("Use case individual signature test") = + checkText("SI_5054_q7.scala", List( + """abstract def test2(explicit: Int): Int [use case] This takes the explicit value passed.""", + """abstract def test1(): Int [use case] This takes the implicit value in scope.""")) + + property("Display correct \"Definition classes\"") = + checkText1("SI_5287.scala", + """def method(): Int + [use case] The usecase explanation + [use case] The usecase explanation + Definition Classes SI_5287 SI_5287_B SI_5287_A""", debug=true) + // explanation appears twice, as small comment and full comment { val files = createTemplates("basic.scala") - println(files) + //println(files) property("class") = files.get("com/example/p1/Clazz.html") match { case Some(node: scala.xml.Node) => { |