From 5b532e927241bfaea4aa9b36e32ff3a0deb1ae15 Mon Sep 17 00:00:00 2001 From: Adriaan Moors Date: Thu, 14 Nov 2013 00:22:10 -0800 Subject: 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. --- test/files/run/fors.scala | 84 +++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 84 insertions(+) create mode 100644 test/files/run/fors.scala (limited to 'test/files/run/fors.scala') 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 +} -- cgit v1.2.3