summary refs log tree commit diff
path: root/src/test
diff options
context:
space:
mode:
authorPaul Stansifer <paul.stansifer@gmail.com>2011-07-21 16:47:47 -0700
committerPaul Stansifer <paul.stansifer@gmail.com>2011-07-22 16:53:43 -0700
commite18d70fe12dcaa84e073f94922f625f3cebeea39 (patch)
treea801c745ed8b038f6900ec2cf2286da2f6bb0169 /src/test
parent4a6ccf3b0ff7a476aa8d692766214bc8ebdfc1dc (diff)
downloadrust-e18d70fe12dcaa84e073f94922f625f3cebeea39.tar.gz
rust-e18d70fe12dcaa84e073f94922f625f3cebeea39.zip
Implement Macro By Example.
Diffstat (limited to 'src/test')
-rw-r--r--src/test/compile-fail/macro-2.rs2
-rw-r--r--src/test/run-pass/macro-by-example-1.rs9
-rw-r--r--src/test/run-pass/macro-by-example-2.rs24
3 files changed, 34 insertions, 1 deletions
diff --git a/src/test/compile-fail/macro-2.rs b/src/test/compile-fail/macro-2.rs
index ea2dbb40992..45926bfefa8 100644
--- a/src/test/compile-fail/macro-2.rs
+++ b/src/test/compile-fail/macro-2.rs
@@ -1,5 +1,5 @@
 // xfail-stage0
-//error-pattern:expanded as an identifier
+//error-pattern:is an expr, expected an identifier
 fn main() {
   #macro([#mylambda(x, body), {fn f(int x) -> int {ret body}; f}]);
 
diff --git a/src/test/run-pass/macro-by-example-1.rs b/src/test/run-pass/macro-by-example-1.rs
new file mode 100644
index 00000000000..d557ce5d8c5
--- /dev/null
+++ b/src/test/run-pass/macro-by-example-1.rs
@@ -0,0 +1,9 @@
+fn main() {
+  #macro([#apply(f,[x,...]), f(x, ...)]);
+
+  fn add(int a, int b) -> int {
+    ret a+b;
+  }
+
+  assert(#apply(add, [1, 15]) == 16);
+}
\ No newline at end of file
diff --git a/src/test/run-pass/macro-by-example-2.rs b/src/test/run-pass/macro-by-example-2.rs
new file mode 100644
index 00000000000..95b8bd26263
--- /dev/null
+++ b/src/test/run-pass/macro-by-example-2.rs
@@ -0,0 +1,24 @@
+fn main() {
+    #macro([#zip_or_unzip([[x, ...], [y, ...]]), [[x, y], ...]],
+           [#zip_or_unzip([[xx, yy], ...]), [[xx, ...], [yy, ...]]]);
+
+
+    assert(#zip_or_unzip([[1,2,3,4],[5,6,7,8]]) == [[1,5],[2,6],[3,7],[4,8]]);
+    assert(#zip_or_unzip([[1,5],[2,6],[3,7],[4,8]]) == [[1,2,3,4],[5,6,7,8]]);
+
+
+    #macro([#nested([[[x, ...], ...], [[y, ...], ...]]),
+            [[[x, y], ...], ...]]);
+    assert(#nested([[[1,2,3,4,5], [7,8,9,10,11,12]],
+                    [[-1,-2,-3,-4,-5], [-7,-8,-9,-10,-11,-12]]])
+           ==
+           [[[1, -1], [2, -2], [3, -3], [4, -4], [5, -5]],
+            [[7, -7], [8, -8], [9, -9], [10, -10], [11, -11], [12, -12]]]);
+
+    #macro([#dup([y, [x, ...]]), [[y, x], ...]]);
+
+    assert(#dup([1,[1,2,3,4]]) == [[1,1], [1,2], [1,3], [1,4]]);
+
+
+
+}
\ No newline at end of file