add support for test cases which do not expand their result
authoradam <adam@megacz.com>
Sun, 9 Sep 2007 03:54:51 +0000 (23:54 -0400)
committeradam <adam@megacz.com>
Sun, 9 Sep 2007 03:54:51 +0000 (23:54 -0400)
darcs-hash:20070909035451-5007d-386dc39111d15d695849b6df41656411e097def3.gz

src/edu/berkeley/sbp/GSS.java
src/edu/berkeley/sbp/misc/RegressionTests.java
tests/testcase.g

index 7c1fb19..27eb279 100644 (file)
@@ -113,7 +113,7 @@ class GSS {
         public boolean        isFrontier() { return hash!=null; }
 
         /** perform all shift operations, adding promoted nodes to <tt>next</tt> */
-        private void shift(Phase next, Forest result) throws ParseFailed {
+        private void shift(Phase next, Forest f) throws ParseFailed {
             this.next = next;
             // this massively improves GC performance
             if (prev != null) {
@@ -130,7 +130,9 @@ class GSS {
                         finalResult.merge(r.getForest());
                 }
                 if (token == null) continue;
-                n.state().invokeShifts(token, this, new Result(result, n, null));
+                Result result = new Result(f, null, null);
+                result.addParent(n);
+                n.state().invokeShifts(token, this, result);
             }
             numNewNodes = next==null ? 0 : next.hash.size();
             viewPos = this.pos;
@@ -189,6 +191,7 @@ class GSS {
                 if (!state.canReduce(token)) return false;
             } while(false);
             Node n = new Node(Phase.this, result, state, fromEmptyReduction);  // ALLOC
+            /** FIXME: this null-result can be used to notice bogus/dead states */
             for(Object s : state.conjunctStates)
                 newNode(new Result(null, n, null), (State)s, fromEmptyReduction);
             return !n.state().doomed();
index eae22d1..0246395 100644 (file)
@@ -88,9 +88,10 @@ public class RegressionTests {
             Tree tt = r2.expand1();
             for(int i=0; i<tt.size(); i++) {
                 Tree t = tt.child(i);
-                String[] expect = new String[t.child(2).size()];
-                for(int j=0; j<t.child(2).size(); j++)
-                    expect[j] = stringifyChildren(t.child(2).child(j));
+                String[] expect = !"ignore output;".equals(t.child(2).head()) ? new String[t.child(2).size()] : null;
+                if (expect != null)
+                    for(int j=0; j<t.child(2).size(); j++)
+                        expect[j] = stringifyChildren(t.child(2).child(j));
                 cases.add(new TestCase(stringifyChildren(t.child(0)),
                                        stringifyChildren(t.child(1)),
                                        expect,
@@ -135,12 +136,13 @@ public class RegressionTests {
             this.name = name;
             this.jav = jav;
             this.input = input;
-            this.output = output==null ? new String[0] : output;
+            this.output = output;
             this.grammar = grammar;
         }
         public String toString() {
             String ret = "testcase {\n" + "  input \""+input+"\";\n";
-            for(String s : output) ret += "  output \""+s+"\";\n";
+            if (output != null)
+                for(String s : output) ret += "  output \""+s+"\";\n";
             ret += grammar +"\n}\n";
             return ret;
         }
@@ -164,6 +166,10 @@ public class RegressionTests {
                 System.out.println(parser);
             }
 
+            if (output==null) {
+                System.out.println("\r\033[32mDONE\033[0m "+name);
+                return true;
+            }
             Iterable<Tree<String>> results =
                 res==null ? new HashSet<Tree<String>>() : res.expand();
 
index 5307361..b25251d 100644 (file)
@@ -6,7 +6,7 @@ Output     = "output" grammar.Quoted ";" /ws
 Outputs::  = Output */ ws
 TestCase:: = "testcase" grammar.Quoted "{"
                      Input
-                     Outputs
+                     (^"ignore output;" | Outputs)
                      (SubGrammar:: grammar.Grammar)
                 "}" /ws
 ws         = grammar.ws