aboutsummaryrefslogtreecommitdiff
path: root/src/test
diff options
context:
space:
mode:
authorGraydon Hoare <[email protected]>2010-07-15 23:58:13 -0700
committerGraydon Hoare <[email protected]>2010-07-15 23:58:13 -0700
commitde8a7dc7dc9dc0188a18c11511188c258bab6d99 (patch)
tree63ec65a79fa6263d06539ece353c4178a1802501 /src/test
parentFix a couple fails with wrong arg count (new arg from last gc change); expand... (diff)
parentSupport nested for-each loops. Closes #79. (diff)
downloadrust-de8a7dc7dc9dc0188a18c11511188c258bab6d99.tar.xz
rust-de8a7dc7dc9dc0188a18c11511188c258bab6d99.zip
Merge branch 'contrib'
Diffstat (limited to 'src/test')
-rw-r--r--src/test/run-pass/foreach-nested-2.rs38
-rw-r--r--src/test/run-pass/foreach-nested.rs23
2 files changed, 61 insertions, 0 deletions
diff --git a/src/test/run-pass/foreach-nested-2.rs b/src/test/run-pass/foreach-nested-2.rs
new file mode 100644
index 00000000..35487e7d
--- /dev/null
+++ b/src/test/run-pass/foreach-nested-2.rs
@@ -0,0 +1,38 @@
+// -*- rust -*-
+
+iter two() -> int {
+ put 0;
+ put 1;
+}
+
+iter range(int start, int stop) -> int {
+ let int i = start;
+ while (i < stop) {
+ put i;
+ i += 1;
+ }
+}
+
+fn main() {
+ let vec[int] a = vec(-1, -1, -1, -1, -1, -1, -1, -1);
+ let int p = 0;
+
+ for each (int i in two()) {
+ for each (int j in range(0, 2)) {
+ let int tmp = 10 * i + j;
+ for each (int k in range(0, 2)) {
+ a.(p) = 10 * tmp + k;
+ p += 1;
+ }
+ }
+ }
+
+ check (a.(0) == 0);
+ check (a.(1) == 1);
+ check (a.(2) == 10);
+ check (a.(3) == 11);
+ check (a.(4) == 100);
+ check (a.(5) == 101);
+ check (a.(6) == 110);
+ check (a.(7) == 111);
+}
diff --git a/src/test/run-pass/foreach-nested.rs b/src/test/run-pass/foreach-nested.rs
new file mode 100644
index 00000000..848adb26
--- /dev/null
+++ b/src/test/run-pass/foreach-nested.rs
@@ -0,0 +1,23 @@
+// -*- rust -*-
+
+iter two() -> int {
+ put 0;
+ put 1;
+}
+
+fn main() {
+ let vec[int] a = vec(-1, -1, -1, -1);
+ let int p = 0;
+
+ for each (int i in two()) {
+ for each (int j in two()) {
+ a.(p) = 10 * i + j;
+ p += 1;
+ }
+ }
+
+ check (a.(0) == 0);
+ check (a.(1) == 1);
+ check (a.(2) == 10);
+ check (a.(3) == 11);
+}