about summary refs log tree commit diff
path: root/src/libutil/test-aterm.cc
diff options
context:
space:
mode:
authorEelco Dolstra <e.dolstra@tudelft.nl>2003-11-18T10·47+0000
committerEelco Dolstra <e.dolstra@tudelft.nl>2003-11-18T10·47+0000
commit8798fae30450a88c339c8f23d7e0c75f5df2ef1c (patch)
tree53d271e89ee3d04490a94a7ea82cf2dc3bbc3c30 /src/libutil/test-aterm.cc
parent45610ae675f6f8d6ecbd48c495cb7012b143d531 (diff)
* Source tree refactoring.
Diffstat (limited to 'src/libutil/test-aterm.cc')
-rw-r--r--src/libutil/test-aterm.cc66
1 files changed, 66 insertions, 0 deletions
diff --git a/src/libutil/test-aterm.cc b/src/libutil/test-aterm.cc
new file mode 100644
index 000000000000..325639ca4f30
--- /dev/null
+++ b/src/libutil/test-aterm.cc
@@ -0,0 +1,66 @@
+#include "aterm.hh"
+#include <iostream>
+
+
+void runTests()
+{
+    verbosity = lvlDebug;
+
+    ATMatcher pos;
+
+    ATerm t = ATmake("Call(Foo, Bar, \"xyz\")");
+    
+    debug(format("term: %1%") % t);
+
+    string fun, arg3;
+    ATerm lhs, rhs;
+
+    if (!(atMatch(pos, t) >> "Call" >> lhs >> rhs >> arg3))
+        throw Error("should succeed");
+    if (arg3 != "xyz") throw Error("bad 1");
+
+    if (!(atMatch(pos, t) >> fun >> lhs >> rhs >> arg3))
+        throw Error("should succeed");
+    if (fun != "Call") throw Error("bad 2");
+    if (arg3 != "xyz") throw Error("bad 3");
+
+    if (!(atMatch(pos, t) >> fun >> lhs >> rhs >> "xyz"))
+        throw Error("should succeed");
+
+    if (atMatch(pos, t) >> fun >> lhs >> rhs >> "abc")
+        throw Error("should fail");
+
+    if (atMatch(pos, t) >> "Call" >> lhs >> rhs >> "abc")
+        throw Error("should fail");
+
+    t = ATmake("X([A, B, C], \"abc\")");
+
+    ATerm t1, t2, t3;
+    if (atMatch(pos, t) >> "X" >> t1 >> t2 >> t3)
+        throw Error("should fail");
+    if (!(atMatch(pos, t) >> "X" >> t1 >> t2))
+        throw Error("should succeed");
+    ATermList ts;
+    if (!(atMatch(pos, t) >> "X" >> ts >> t2))
+        throw Error("should succeed");
+    if (ATgetLength(ts) != 3)
+        throw Error("bad");
+    if (atMatch(pos, t) >> "X" >> t1 >> ts)
+        throw Error("should fail");
+}
+
+
+int main(int argc, char * * argv)
+{
+    ATerm bottomOfStack;
+    ATinit(argc, argv, &bottomOfStack);
+
+    try {
+        runTests();
+    } catch (Error & e) {
+        printMsg(lvlError, format("error: %1%") % e.msg());
+        return 1;
+    }
+
+    return 0;
+}