Add tests for failures
authorJakub Skoczen <jakub@indexdata.dk>
Fri, 14 Mar 2014 14:04:39 +0000 (15:04 +0100)
committerJakub Skoczen <jakub@indexdata.dk>
Fri, 14 Mar 2014 14:04:39 +0000 (15:04 +0100)
22 files changed:
src/test/java/org/z3950/zing/cql/CQLParserTest.java
src/test/resources/regression/11/01.cql [new file with mode: 0644]
src/test/resources/regression/11/01.xcql [new file with mode: 0644]
src/test/resources/regression/11/02.cql [new file with mode: 0644]
src/test/resources/regression/11/02.xcql [new file with mode: 0644]
src/test/resources/regression/11/03.cql.disabled [new file with mode: 0644]
src/test/resources/regression/11/04.cql.disabled [new file with mode: 0644]
src/test/resources/regression/11/05.cql [new file with mode: 0644]
src/test/resources/regression/11/05.xcql [new file with mode: 0644]
src/test/resources/regression/11/06.cql [new file with mode: 0644]
src/test/resources/regression/11/06.xcql [new file with mode: 0644]
src/test/resources/regression/11/07.cql [new file with mode: 0644]
src/test/resources/regression/11/07.xcql [new file with mode: 0644]
src/test/resources/regression/11/08.cql [new file with mode: 0644]
src/test/resources/regression/11/08.xcql [new file with mode: 0644]
src/test/resources/regression/11/09.cql.disabled [new file with mode: 0644]
src/test/resources/regression/11/10.cql.disabled [new file with mode: 0644]
src/test/resources/regression/11/11.cql [new file with mode: 0644]
src/test/resources/regression/11/11.xcql [new file with mode: 0644]
src/test/resources/regression/11/12.cql [new file with mode: 0644]
src/test/resources/regression/11/12.xcql [new file with mode: 0644]
src/test/resources/regression/11/name [new file with mode: 0644]

index 61b112b..2566e13 100644 (file)
@@ -75,26 +75,33 @@ public class CQLParserTest {
           reader = new BufferedReader(new InputStreamReader(is));
           String input = reader.readLine();
           out.println("Query: "+input);
-          CQLParser parser = new CQLParser();
-          CQLNode parsed = parser.parse(input);
-          String xcql = parsed.toXCQL();
+          String result;
+          try {
+            CQLParser parser = new CQLParser();
+            CQLNode parsed = parser.parse(input);
+            result = parsed.toXCQL();
+          } catch (CQLParseException pe) {
+            result = pe.getMessage() + "\n";
+          }
           out.println("Parsed:");
-          out.println(xcql);
+          out.println(result);
           //read the expected xcql output
+          String expected = "<expected result file not found>";
           String prefix = file.substring(0, file.length()-4);
-          reader2 = new BufferedReader(new InputStreamReader(
-            this.getClass().getResourceAsStream("/regression/"+dir+"/"+prefix+".xcql")));
-          StringBuilder sb = new StringBuilder();
-          String line;
-          while ((line = reader2.readLine()) != null) {
-            sb.append(line).append("\n");
+          InputStream is2 = this.getClass()
+            .getResourceAsStream("/regression/"+dir+"/"+prefix+".xcql");
+          if (is2 != null) {
+            reader2 = new BufferedReader(new InputStreamReader(is2));
+            StringBuilder sb = new StringBuilder();
+            String line;
+            while ((line = reader2.readLine()) != null) {
+              sb.append(line).append("\n");
+            }
+            expected = sb.toString();
           }
-          String expected = sb.toString();
           out.println("Expected: ");
           out.println(expected);
-          assertEquals("Assertion failure for "+dir+"/"+file, expected, xcql);
-        } catch (CQLParseException pe) {
-          fail("Parsing failed with: "+pe.toString());
+          assertEquals("Assertion failure for "+dir+"/"+file, expected, result);
         } finally {
           if (reader != null) reader.close();
           if (reader2 != null) reader2.close();
diff --git a/src/test/resources/regression/11/01.cql b/src/test/resources/regression/11/01.cql
new file mode 100644 (file)
index 0000000..5d56655
--- /dev/null
@@ -0,0 +1 @@
+cat or
diff --git a/src/test/resources/regression/11/01.xcql b/src/test/resources/regression/11/01.xcql
new file mode 100644 (file)
index 0000000..03b04df
--- /dev/null
@@ -0,0 +1 @@
+expected index or term, got EOF
diff --git a/src/test/resources/regression/11/02.cql b/src/test/resources/regression/11/02.cql
new file mode 100644 (file)
index 0000000..200021d
--- /dev/null
@@ -0,0 +1 @@
+index any
diff --git a/src/test/resources/regression/11/02.xcql b/src/test/resources/regression/11/02.xcql
new file mode 100644 (file)
index 0000000..03b04df
--- /dev/null
@@ -0,0 +1 @@
+expected index or term, got EOF
diff --git a/src/test/resources/regression/11/03.cql.disabled b/src/test/resources/regression/11/03.cql.disabled
new file mode 100644 (file)
index 0000000..daf9170
--- /dev/null
@@ -0,0 +1 @@
+index any/wrong term
diff --git a/src/test/resources/regression/11/04.cql.disabled b/src/test/resources/regression/11/04.cql.disabled
new file mode 100644 (file)
index 0000000..d7a7241
--- /dev/null
@@ -0,0 +1 @@
+a prox/wrong b
diff --git a/src/test/resources/regression/11/05.cql b/src/test/resources/regression/11/05.cql
new file mode 100644 (file)
index 0000000..6a452c1
--- /dev/null
@@ -0,0 +1 @@
+()
diff --git a/src/test/resources/regression/11/05.xcql b/src/test/resources/regression/11/05.xcql
new file mode 100644 (file)
index 0000000..9acb4e1
--- /dev/null
@@ -0,0 +1 @@
+expected index or term, got ')'
diff --git a/src/test/resources/regression/11/06.cql b/src/test/resources/regression/11/06.cql
new file mode 100644 (file)
index 0000000..96c10c2
--- /dev/null
@@ -0,0 +1 @@
+(a
diff --git a/src/test/resources/regression/11/06.xcql b/src/test/resources/regression/11/06.xcql
new file mode 100644 (file)
index 0000000..1a03f39
--- /dev/null
@@ -0,0 +1 @@
+expected ')', got EOF
diff --git a/src/test/resources/regression/11/07.cql b/src/test/resources/regression/11/07.cql
new file mode 100644 (file)
index 0000000..31a777d
--- /dev/null
@@ -0,0 +1 @@
+ndex any fish)
diff --git a/src/test/resources/regression/11/07.xcql b/src/test/resources/regression/11/07.xcql
new file mode 100644 (file)
index 0000000..ad3588c
--- /dev/null
@@ -0,0 +1 @@
+junk after end: ')'
diff --git a/src/test/resources/regression/11/08.cql b/src/test/resources/regression/11/08.cql
new file mode 100644 (file)
index 0000000..6eaf1dc
--- /dev/null
@@ -0,0 +1 @@
+(cat any dog or ())
diff --git a/src/test/resources/regression/11/08.xcql b/src/test/resources/regression/11/08.xcql
new file mode 100644 (file)
index 0000000..9acb4e1
--- /dev/null
@@ -0,0 +1 @@
+expected index or term, got ')'
diff --git a/src/test/resources/regression/11/09.cql.disabled b/src/test/resources/regression/11/09.cql.disabled
new file mode 100644 (file)
index 0000000..ba04d90
--- /dev/null
@@ -0,0 +1 @@
+title = ("illegal parentheses")
diff --git a/src/test/resources/regression/11/10.cql.disabled b/src/test/resources/regression/11/10.cql.disabled
new file mode 100644 (file)
index 0000000..3381e47
--- /dev/null
@@ -0,0 +1 @@
+"quoted" any "illegal quotes"
diff --git a/src/test/resources/regression/11/11.cql b/src/test/resources/regression/11/11.cql
new file mode 100644 (file)
index 0000000..ab692e6
--- /dev/null
@@ -0,0 +1 @@
+> illegal="urn:missingQuery"
diff --git a/src/test/resources/regression/11/11.xcql b/src/test/resources/regression/11/11.xcql
new file mode 100644 (file)
index 0000000..03b04df
--- /dev/null
@@ -0,0 +1 @@
+expected index or term, got EOF
diff --git a/src/test/resources/regression/11/12.cql b/src/test/resources/regression/11/12.cql
new file mode 100644 (file)
index 0000000..fa804d8
--- /dev/null
@@ -0,0 +1 @@
+"fish" and > illegal="urn:invalidPrefixLocation" "chips"
diff --git a/src/test/resources/regression/11/12.xcql b/src/test/resources/regression/11/12.xcql
new file mode 100644 (file)
index 0000000..cfa7186
--- /dev/null
@@ -0,0 +1,29 @@
+<triple>
+  <boolean>
+    <value>and</value>
+  </boolean>
+  <leftOperand>
+    <searchClause>
+      <index>cql.serverChoice</index>
+      <relation>
+        <value>=</value>
+      </relation>
+      <term>fish</term>
+    </searchClause>
+  </leftOperand>
+  <rightOperand>
+    <searchClause>
+      <prefixes>
+        <prefix>
+          <name>illegal</name>
+          <identifier>urn:invalidPrefixLocation</identifier>
+        </prefix>
+      </prefixes>
+      <index>cql.serverChoice</index>
+      <relation>
+        <value>=</value>
+      </relation>
+      <term>chips</term>
+    </searchClause>
+  </rightOperand>
+</triple>
diff --git a/src/test/resources/regression/11/name b/src/test/resources/regression/11/name
new file mode 100644 (file)
index 0000000..2e6da96
--- /dev/null
@@ -0,0 +1 @@
+FAILURES