From 56c5ab26a8d9cee0abc4083087a3ec17fdec907b Mon Sep 17 00:00:00 2001 From: Jakub Skoczen Date: Fri, 14 Mar 2014 15:04:39 +0100 Subject: [PATCH] Add tests for failures --- .../java/org/z3950/zing/cql/CQLParserTest.java | 35 ++++++++++++-------- src/test/resources/regression/11/01.cql | 1 + src/test/resources/regression/11/01.xcql | 1 + src/test/resources/regression/11/02.cql | 1 + src/test/resources/regression/11/02.xcql | 1 + src/test/resources/regression/11/03.cql.disabled | 1 + src/test/resources/regression/11/04.cql.disabled | 1 + src/test/resources/regression/11/05.cql | 1 + src/test/resources/regression/11/05.xcql | 1 + src/test/resources/regression/11/06.cql | 1 + src/test/resources/regression/11/06.xcql | 1 + src/test/resources/regression/11/07.cql | 1 + src/test/resources/regression/11/07.xcql | 1 + src/test/resources/regression/11/08.cql | 1 + src/test/resources/regression/11/08.xcql | 1 + src/test/resources/regression/11/09.cql.disabled | 1 + src/test/resources/regression/11/10.cql.disabled | 1 + src/test/resources/regression/11/11.cql | 1 + src/test/resources/regression/11/11.xcql | 1 + src/test/resources/regression/11/12.cql | 1 + src/test/resources/regression/11/12.xcql | 29 ++++++++++++++++ src/test/resources/regression/11/name | 1 + 22 files changed, 70 insertions(+), 14 deletions(-) create mode 100644 src/test/resources/regression/11/01.cql create mode 100644 src/test/resources/regression/11/01.xcql create mode 100644 src/test/resources/regression/11/02.cql create mode 100644 src/test/resources/regression/11/02.xcql create mode 100644 src/test/resources/regression/11/03.cql.disabled create mode 100644 src/test/resources/regression/11/04.cql.disabled create mode 100644 src/test/resources/regression/11/05.cql create mode 100644 src/test/resources/regression/11/05.xcql create mode 100644 src/test/resources/regression/11/06.cql create mode 100644 src/test/resources/regression/11/06.xcql create mode 100644 src/test/resources/regression/11/07.cql create mode 100644 src/test/resources/regression/11/07.xcql create mode 100644 src/test/resources/regression/11/08.cql create mode 100644 src/test/resources/regression/11/08.xcql create mode 100644 src/test/resources/regression/11/09.cql.disabled create mode 100644 src/test/resources/regression/11/10.cql.disabled create mode 100644 src/test/resources/regression/11/11.cql create mode 100644 src/test/resources/regression/11/11.xcql create mode 100644 src/test/resources/regression/11/12.cql create mode 100644 src/test/resources/regression/11/12.xcql create mode 100644 src/test/resources/regression/11/name diff --git a/src/test/java/org/z3950/zing/cql/CQLParserTest.java b/src/test/java/org/z3950/zing/cql/CQLParserTest.java index 61b112b..2566e13 100644 --- a/src/test/java/org/z3950/zing/cql/CQLParserTest.java +++ b/src/test/java/org/z3950/zing/cql/CQLParserTest.java @@ -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 = ""; 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 index 0000000..5d56655 --- /dev/null +++ b/src/test/resources/regression/11/01.cql @@ -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 index 0000000..03b04df --- /dev/null +++ b/src/test/resources/regression/11/01.xcql @@ -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 index 0000000..200021d --- /dev/null +++ b/src/test/resources/regression/11/02.cql @@ -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 index 0000000..03b04df --- /dev/null +++ b/src/test/resources/regression/11/02.xcql @@ -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 index 0000000..daf9170 --- /dev/null +++ b/src/test/resources/regression/11/03.cql.disabled @@ -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 index 0000000..d7a7241 --- /dev/null +++ b/src/test/resources/regression/11/04.cql.disabled @@ -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 index 0000000..6a452c1 --- /dev/null +++ b/src/test/resources/regression/11/05.cql @@ -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 index 0000000..9acb4e1 --- /dev/null +++ b/src/test/resources/regression/11/05.xcql @@ -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 index 0000000..96c10c2 --- /dev/null +++ b/src/test/resources/regression/11/06.cql @@ -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 index 0000000..1a03f39 --- /dev/null +++ b/src/test/resources/regression/11/06.xcql @@ -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 index 0000000..31a777d --- /dev/null +++ b/src/test/resources/regression/11/07.cql @@ -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 index 0000000..ad3588c --- /dev/null +++ b/src/test/resources/regression/11/07.xcql @@ -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 index 0000000..6eaf1dc --- /dev/null +++ b/src/test/resources/regression/11/08.cql @@ -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 index 0000000..9acb4e1 --- /dev/null +++ b/src/test/resources/regression/11/08.xcql @@ -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 index 0000000..ba04d90 --- /dev/null +++ b/src/test/resources/regression/11/09.cql.disabled @@ -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 index 0000000..3381e47 --- /dev/null +++ b/src/test/resources/regression/11/10.cql.disabled @@ -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 index 0000000..ab692e6 --- /dev/null +++ b/src/test/resources/regression/11/11.cql @@ -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 index 0000000..03b04df --- /dev/null +++ b/src/test/resources/regression/11/11.xcql @@ -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 index 0000000..fa804d8 --- /dev/null +++ b/src/test/resources/regression/11/12.cql @@ -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 index 0000000..cfa7186 --- /dev/null +++ b/src/test/resources/regression/11/12.xcql @@ -0,0 +1,29 @@ + + + and + + + + cql.serverChoice + + = + + fish + + + + + + + illegal + urn:invalidPrefixLocation + + + cql.serverChoice + + = + + chips + + + diff --git a/src/test/resources/regression/11/name b/src/test/resources/regression/11/name new file mode 100644 index 0000000..2e6da96 --- /dev/null +++ b/src/test/resources/regression/11/name @@ -0,0 +1 @@ +FAILURES -- 1.7.10.4