checkpoint
[sbp.git] / src / edu / berkeley / sbp / misc / RegressionTests.java
index 5a86bf1..943c611 100644 (file)
@@ -123,23 +123,21 @@ public class RegressionTests {
     }
 
     public static class TestCaseBuilder extends MetaGrammar {
-        public TestCase[] ts(Object o1, TestCase[] ts, Object o2) { return ts; }
-        public TestCase[] ts(TestCase[] ts) { return ts; }
-        public TestCase testcase(String input, String[] output, Union grammar) throws IOException {
-            return new TestCase(input, output,        grammar, false); }
-        public TestCase testcase(String input,                  Union grammar) throws IOException {
-            return new TestCase(input, new String[0], grammar, false); }
-        public TestCase tibcase(String input, String[] output, Union grammar) throws IOException {
-            return new TestCase(input, output,        grammar, true); }
-        public TestCase  tibcase(String input,                  Union grammar) throws IOException {
-            return new TestCase(input, new String[0], grammar, true); }
-        public MetaGrammar grammar(Object[] o) { return this; }
-        public Object walk(String tag, Object[] args) {
-            if ("grammar".equals(tag)) {
-                //System.out.println("\n" + this + "\n");
-                return done("s");
+        public Object walk(Tree<String> tree) {
+            try {
+                if ("grammar".equals(tree.head())) { walkChildren(tree); return done("s"); }
+                else if ("output".equals(tree.head())) return string(tree.children());
+                else if ("input".equals(tree.head())) return string(tree.children());
+                else if ("tibcase".equals(tree.head()) || "testcase".equals(tree.head())) {
+                    String input = string(tree.child(0));
+                    String[] output = tree.numChildren()>2 ? ((String[])walk(tree, 1)) : new String[0];
+                    Union grammar = (Union)walk(tree, tree.numChildren()-1);
+                    return new TestCase(input, output, grammar, "tibcase".equals(tree.head()));
+                } else if ("ts".equals(tree.head())) return walk(tree, 0);
+                else return super.walk(tree);
+            } catch (Exception e) {
+                throw new Error(e);
             }
-            else return super.walk(tag, args);
         }
     }