summaryrefslogtreecommitdiff
path: root/test/files/run
diff options
context:
space:
mode:
authorJames Iry <jamesiry@gmail.com>2013-11-18 07:59:56 -0800
committerJames Iry <jamesiry@gmail.com>2013-11-18 07:59:56 -0800
commit8d094c930fc570dcc7f4978777f9af03d5e47e5a (patch)
treee227987c7552b4fd2c25caed23d5bee843e00d6c /test/files/run
parent490b82b78e040259ffeb6ef2fe9690f92117922f (diff)
parent5b532e927241bfaea4aa9b36e32ff3a0deb1ae15 (diff)
downloadscala-8d094c930fc570dcc7f4978777f9af03d5e47e5a.tar.gz
scala-8d094c930fc570dcc7f4978777f9af03d5e47e5a.tar.bz2
scala-8d094c930fc570dcc7f4978777f9af03d5e47e5a.zip
Merge pull request #3135 from adriaanm/revive-xml-tests
Revived tests that once depended on xml
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"
+ })
+}