diff options
author | michelou <michelou@epfl.ch> | 2007-04-23 15:38:07 +0000 |
---|---|---|
committer | michelou <michelou@epfl.ch> | 2007-04-23 15:38:07 +0000 |
commit | bd7866c7940c41d5c4f3f88e09c7354126eabe15 (patch) | |
tree | 7b2a2bd12160cf920fac5fd7867218ded4f0967c /test/files | |
parent | 90c68e19144fa811671b8e1dc3ad0e7ecc5b487c (diff) | |
download | scala-bd7866c7940c41d5c4f3f88e09c7354126eabe15.tar.gz scala-bd7866c7940c41d5c4f3f88e09c7354126eabe15.tar.bz2 scala-bd7866c7940c41d5c4f3f88e09c7354126eabe15.zip |
updated self aliases, for-comprehensions
Diffstat (limited to 'test/files')
-rw-r--r-- | test/files/run/fors.check | 28 | ||||
-rw-r--r-- | test/files/run/fors.scala | 83 |
2 files changed, 111 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..cd84649c15 --- /dev/null +++ b/test/files/run/fors.scala @@ -0,0 +1,83 @@ +//############################################################################ +// for-comprehensions (old and new syntax) +//############################################################################ +// $Id: $ + +//############################################################################ + +object Test extends Application { + 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 (val x <- xs) print(x + " "); println + for (val x <- xs; + x % 2 == 0) print(x + " "); println + for {val x <- xs + x % 2 == 0} print(x + " "); println + var n = 0 + for (val _ <- xs) n += 1; println(n) + for (val (x, y) <- xs zip ys) print(x + " "); println + for (val p @ (x, y) <- xs zip ys) print(p._1 + " "); println + + // iterators + for (val x <- it) print(x + " "); println + for (val x <- it; + x % 2 == 0) print(x + " "); println + for {val x <- it + x % 2 == 0} print(x + " "); println + + // arrays + for (val x <- ar) print(x + " "); println + for (val x <- ar; + x.toInt > 97) print(x + " "); println + for {val x <- ar + 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; + val y = 2 + if x % y == 0) print(x + " "); println + for {x <- it + val y = 2 + if x % y == 0} print(x + " "); println + + // arrays + for (x <- ar) print(x + " "); println + } + + //////////////////////////////////////////////////// + + testOld + testNew +} |