summaryrefslogtreecommitdiff
path: root/test/files/run
diff options
context:
space:
mode:
authorAdriaan Moors <adriaan.moors@typesafe.com>2013-11-14 00:22:10 -0800
committerAdriaan Moors <adriaan.moors@typesafe.com>2013-11-14 00:40:12 -0800
commit5b532e927241bfaea4aa9b36e32ff3a0deb1ae15 (patch)
tree83730ba21561d6ee1d34beb0b579d1a1254d86d4 /test/files/run
parent69e62de87d80cf5b9d8c7f4eefcea0638fb2759d (diff)
downloadscala-5b532e927241bfaea4aa9b36e32ff3a0deb1ae15.tar.gz
scala-5b532e927241bfaea4aa9b36e32ff3a0deb1ae15.tar.bz2
scala-5b532e927241bfaea4aa9b36e32ff3a0deb1ae15.zip
Revived tests that once depended on xml
I was a bit overzealous in moving stuff over to scala-xml in 9c50dd5274 These were all compiler tests that accidentally touched on xml. I've tried to delicately decouple them so they can roam the scalac pastures as intended.
Diffstat (limited to 'test/files/run')
-rw-r--r--test/files/run/fors.check28
-rw-r--r--test/files/run/fors.scala84
-rw-r--r--test/files/run/repl-backticks.check2
-rw-r--r--test/files/run/repl-backticks.scala18
-rw-r--r--test/files/run/t1500.check3
-rw-r--r--test/files/run/t1500.scala46
-rw-r--r--test/files/run/t1501.check3
-rw-r--r--test/files/run/t1501.scala56
-rw-r--r--test/files/run/t4124.check4
-rw-r--r--test/files/run/t4124.scala24
10 files changed, 268 insertions, 0 deletions
diff --git a/test/files/run/fors.check b/test/files/run/fors.check
new file mode 100644
index 0000000000..b459f00b49
--- /dev/null
+++ b/test/files/run/fors.check
@@ -0,0 +1,28 @@
+
+testOld
+1 2 3
+2
+2
+3
+1 2 3
+1 2 3
+0 1 2 3 4 5 6 7 8 9
+0 2 4 6 8
+0 2 4 6 8
+a b c
+b c
+b c
+
+testNew
+3
+1 2 3
+1 2 3
+0 1 2 3 4 5 6 7 8 9
+0 2 4 6 8
+0 2 4 6 8
+0 2 4 6 8
+0 2 4 6 8
+0 2 4 6 8
+0 2 4 6 8
+0 2 4 6 8
+a b c
diff --git a/test/files/run/fors.scala b/test/files/run/fors.scala
new file mode 100644
index 0000000000..c778df3e24
--- /dev/null
+++ b/test/files/run/fors.scala
@@ -0,0 +1,84 @@
+//############################################################################
+// for-comprehensions (old and new syntax)
+//############################################################################
+
+//############################################################################
+
+object Test extends App {
+ val xs = List(1, 2, 3)
+ val ys = List('a, 'b, 'c)
+
+ def it = 0 until 10
+
+ val ar = "abc".toCharArray
+
+ /////////////////// old syntax ///////////////////
+
+ def testOld {
+ println("\ntestOld")
+
+ // lists
+ for (x <- xs) print(x + " "); println
+ for (x <- xs;
+ if x % 2 == 0) print(x + " "); println
+ for {x <- xs
+ if x % 2 == 0} print(x + " "); println
+ var n = 0
+ for (_ <- xs) n += 1; println(n)
+ for ((x, y) <- xs zip ys) print(x + " "); println
+ for (p @ (x, y) <- xs zip ys) print(p._1 + " "); println
+
+ // iterators
+ for (x <- it) print(x + " "); println
+ for (x <- it;
+ if x % 2 == 0) print(x + " "); println
+ for {x <- it
+ if x % 2 == 0} print(x + " "); println
+
+ // arrays
+ for (x <- ar) print(x + " "); println
+ for (x <- ar;
+ if x.toInt > 97) print(x + " "); println
+ for {x <- ar
+ if x.toInt > 97} print(x + " "); println
+
+ }
+
+ /////////////////// new syntax ///////////////////
+
+ def testNew {
+ println("\ntestNew")
+
+ // lists
+ var n = 0
+ for (_ <- xs) n += 1; println(n)
+ for ((x, y) <- xs zip ys) print(x + " "); println
+ for (p @ (x, y) <- xs zip ys) print(p._1 + " "); println
+
+ // iterators
+ for (x <- it) print(x + " "); println
+ for (x <- it if x % 2 == 0) print(x + " "); println
+ for (x <- it; if x % 2 == 0) print(x + " "); println
+ for (x <- it;
+ if x % 2 == 0) print(x + " "); println
+ for (x <- it
+ if x % 2 == 0) print(x + " "); println
+ for {x <- it
+ if x % 2 == 0} print(x + " "); println
+ for (x <- it;
+ y = 2
+ if x % y == 0) print(x + " "); println
+ for {x <- it
+ y = 2
+ if x % y == 0} print(x + " "); println
+
+ // arrays
+ for (x <- ar) print(x + " "); println
+
+ }
+
+ ////////////////////////////////////////////////////
+
+ testOld
+ testNew
+}
diff --git a/test/files/run/repl-backticks.check b/test/files/run/repl-backticks.check
new file mode 100644
index 0000000000..c0561abd7c
--- /dev/null
+++ b/test/files/run/repl-backticks.check
@@ -0,0 +1,2 @@
+import java.lang.Thread.`yield`
+import scala.`package`.Throwable
diff --git a/test/files/run/repl-backticks.scala b/test/files/run/repl-backticks.scala
new file mode 100644
index 0000000000..e40a8bc662
--- /dev/null
+++ b/test/files/run/repl-backticks.scala
@@ -0,0 +1,18 @@
+import scala.tools.nsc._
+
+object Test {
+ val testCode = """
+ import java.lang.Thread.`yield`
+ import scala.`package`.Throwable
+
+ `yield`
+ """
+
+ def main(args: Array[String]) {
+ val settings = new Settings()
+ settings.classpath.value = System.getProperty("java.class.path")
+ val repl = new interpreter.IMain(settings)
+ repl.interpret(testCode)
+ }
+}
+
diff --git a/test/files/run/t1500.check b/test/files/run/t1500.check
new file mode 100644
index 0000000000..94a169333b
--- /dev/null
+++ b/test/files/run/t1500.check
@@ -0,0 +1,3 @@
+defined class posingAs
+resolve: [A, B](x: A @posingAs[B])B
+x: Any = 7
diff --git a/test/files/run/t1500.scala b/test/files/run/t1500.scala
new file mode 100644
index 0000000000..30c026f70f
--- /dev/null
+++ b/test/files/run/t1500.scala
@@ -0,0 +1,46 @@
+import scala.tools.nsc._
+
+object Test {
+
+ /**
+ * Type inference overlooks constraints posed by type parameters in annotations on types.
+ */
+
+ val testCode = """
+
+ class posingAs[A] extends annotation.TypeConstraint
+
+ def resolve[A,B](x: A @posingAs[B]): B = x.asInstanceOf[B]
+
+ val x = resolve(7: @posingAs[Any])
+
+ """
+
+ def main(args: Array[String]) {
+
+ val settings = new Settings()
+ settings.classpath.value = System.getProperty("java.class.path")
+ val tool = new interpreter.IMain(settings)
+ val global = tool.global
+
+ import global._
+ import definitions._
+
+ object checker extends AnnotationChecker {
+
+ /** Check annotations to decide whether tpe1 <:< tpe2 */
+ def annotationsConform(tpe1: Type, tpe2: Type): Boolean = {
+
+ tpe1.annotations.forall(a1 => tpe2.annotations.forall(a2 => a1.atp <:< a2.atp))
+
+ }
+ }
+
+ global.addAnnotationChecker(checker)
+
+ tool.interpret(testCode)
+
+ }
+
+}
+
diff --git a/test/files/run/t1501.check b/test/files/run/t1501.check
new file mode 100644
index 0000000000..f0fa9112a5
--- /dev/null
+++ b/test/files/run/t1501.check
@@ -0,0 +1,3 @@
+defined class xyz
+loopWhile: [T](cond: => Boolean)(body: => Unit @xyz[T])Unit @xyz[T]
+test: ()Unit @xyz[Int]
diff --git a/test/files/run/t1501.scala b/test/files/run/t1501.scala
new file mode 100644
index 0000000000..ca6bf357fb
--- /dev/null
+++ b/test/files/run/t1501.scala
@@ -0,0 +1,56 @@
+import scala.tools.nsc._
+
+object Test {
+
+ /**
+ * ...
+ */
+
+ val testCode = """
+
+ class xyz[A] extends annotation.TypeConstraint
+
+ def loopWhile[T](cond: =>Boolean)(body: =>(Unit @xyz[T])): Unit @ xyz[T] = {{
+ if (cond) {{
+ body
+ loopWhile[T](cond)(body)
+ }}
+ }}
+
+ def test() = {{
+ var x = 7
+ loopWhile(x != 0) {{
+ x = x - 1
+ (): @xyz[Int]
+ }}
+ }}
+
+ """
+
+ def main(args: Array[String]) {
+ val settings = new Settings()
+ settings.classpath.value = System.getProperty("java.class.path")
+ val tool = new interpreter.IMain(settings)
+ val global = tool.global
+
+ import global._
+ import definitions._
+
+ object checker extends AnnotationChecker {
+
+ /** Check annotations to decide whether tpe1 <:< tpe2 */
+ def annotationsConform(tpe1: Type, tpe2: Type): Boolean = {
+
+ tpe1.annotations.forall(a1 => tpe2.annotations.forall(a2 => a1.atp <:< a2.atp))
+
+ }
+ }
+
+ global.addAnnotationChecker(checker)
+
+ tool.interpret(testCode)
+
+ }
+
+}
+
diff --git a/test/files/run/t4124.check b/test/files/run/t4124.check
new file mode 100644
index 0000000000..66a0092d93
--- /dev/null
+++ b/test/files/run/t4124.check
@@ -0,0 +1,4 @@
+hi
+hi
+bye
+bye
diff --git a/test/files/run/t4124.scala b/test/files/run/t4124.scala
new file mode 100644
index 0000000000..9f35b57ce3
--- /dev/null
+++ b/test/files/run/t4124.scala
@@ -0,0 +1,24 @@
+import xml.Node
+
+object Test extends App {
+ val body: Node = <elem>hi</elem>
+ println ((body: AnyRef, "foo") match {
+ case (node: Node, "bar") => "bye"
+ case (ser: Serializable, "foo") => "hi"
+ })
+
+ println ((body, "foo") match {
+ case (node: Node, "bar") => "bye"
+ case (ser: Serializable, "foo") => "hi"
+ })
+
+ println ((body: AnyRef, "foo") match {
+ case (node: Node, "foo") => "bye"
+ case (ser: Serializable, "foo") => "hi"
+ })
+
+ println ((body: AnyRef, "foo") match {
+ case (node: Node, "foo") => "bye"
+ case (ser: Serializable, "foo") => "hi"
+ })
+}