Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 12 additions & 12 deletions src/test/java/org/z3950/zing/cql/CQLNodeVisitorTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,6 @@
import org.junit.Test;
import static org.junit.Assert.*;

import static java.lang.System.*;

/**
*
* @author jakub
Expand Down Expand Up @@ -40,7 +38,6 @@ public void testPrefixVisitor() {
String cql = "((x=a and y=b) or z=c)";
String epxected = "@or @and @attr 1=x a @attr 1=y b @attr 1=z c";
CQLParser p = new CQLParser(CQLParser.V1POINT2);
out.println("Parsing " + cql);
try {
CQLNode n = p.parse(cql);
CQLNodeVisitor v = new CQLDefaultNodeVisitor() {
Expand All @@ -57,6 +54,12 @@ public void onBooleanNodeStart(CQLBooleanNode node) {
case OR:
op = "@or";
break;
case PROX:
op = "@prox";
break;
case NOT:
op = "@not";
break;
}
actual += op + " ";
}
Expand All @@ -73,12 +76,11 @@ public String toString() {
}
};
n.traverse(v);
out.println(v);
assertEquals(epxected, v.toString());
assertEquals("Query: " + cql, epxected, v.toString());
} catch (CQLParseException ex) {
fail(ex.getMessage());
fail("Query: " + cql + "\n" + ex.getMessage());
} catch (IOException ex) {
fail(ex.getMessage());
fail("Query: " + cql + "\n" + ex.getMessage());
}
}

Expand All @@ -87,7 +89,6 @@ public void testInfixVisitor() {
String cql = "((x=a and y=b) or z=c)";
String epxected = "((x:a OG y:b) ELLER z:c)";
CQLParser p = new CQLParser(CQLParser.V1POINT2);
out.println("Parsing " + cql);
try {
CQLNode n = p.parse(cql);
CQLNodeVisitor v = new CQLDefaultNodeVisitor() {
Expand Down Expand Up @@ -128,12 +129,11 @@ public String toString() {
}
};
n.traverse(v);
out.println(v);
assertEquals(epxected, v.toString());
assertEquals("Query: " + cql, epxected, v.toString());
} catch (CQLParseException ex) {
fail(ex.getMessage());
fail("Query: " + cql + "\n" + ex.getMessage());
} catch (IOException ex) {
fail(ex.getMessage());
fail("Query: " + cql + "\n" + ex.getMessage());
}
}
}
19 changes: 5 additions & 14 deletions src/test/java/org/z3950/zing/cql/CQLParserTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,6 @@
import org.junit.Test;

import static org.junit.Assert.*;
import static java.lang.System.out;

/**
*
Expand Down Expand Up @@ -52,7 +51,6 @@ public void tearDown() {
*/
@Test
public void testRegressionQueries() throws IOException {
System.out.println("Testing the parser using pre-canned regression queries...");
// we might be running the test from within the jar
// list all resource dirs, then traverse them
String[] dirs = getResourceListing(this.getClass(), "regression");
Expand All @@ -61,13 +59,11 @@ public void testRegressionQueries() throws IOException {
for (String file : files) {
if (!file.endsWith(".cql"))
continue;
out.println("Parsing " + dir + "/" + file);
InputStream is = this.getClass().getResourceAsStream("/regression/" + dir + "/" + file);
BufferedReader reader = null, reader2 = null;
try {
reader = new BufferedReader(new InputStreamReader(is));
String input = reader.readLine();
out.println("Query: " + input);
String result;
try {
CQLParser parser = new CQLParser();
Expand All @@ -76,8 +72,6 @@ public void testRegressionQueries() throws IOException {
} catch (CQLParseException pe) {
result = pe.getMessage() + "\n";
}
out.println("Parsed:");
out.println(result);
// read the expected xcql output
String expected = "<expected result file not found>";
String prefix = file.substring(0, file.length() - 4);
Expand All @@ -92,9 +86,8 @@ public void testRegressionQueries() throws IOException {
}
expected = sb.toString();
}
out.println("Expected: ");
out.println(expected);
assertEquals("Assertion failure for " + dir + "/" + file, expected, result);
assertEquals("Regression query " + dir + "/" + file + "\nQuery: " + input,
expected, result);
} finally {
if (reader != null)
reader.close();
Expand All @@ -121,7 +114,6 @@ public void testRegressionQueries() throws IOException {
*/
@Test
public void testRandomQueries() throws IOException, MissingParameterException {
out.println("Testing the parser using 100 randomly generated queries...");
Properties params = new Properties();
InputStream is = getClass().getResourceAsStream("/generate.properties");
if (is == null)
Expand All @@ -132,14 +124,14 @@ public void testRandomQueries() throws IOException, MissingParameterException {
for (int i = 0; i < 1000; i++) {
CQLNode random = generator.generate();
String expected = random.toCQL();
out.println("Generated query: " + expected);
CQLParser parser = new CQLParser();
try {
CQLNode parsed = parser.parse(expected);
String result = parsed.toCQL();
assertEquals(expected, result);
assertEquals("Generated query " + (i + 1) + "\nQuery: " + expected, expected, result);
} catch (CQLParseException pe) {
fail("Generated query failed to parse: " + pe.getMessage());
fail("Generated query " + (i + 1) + " failed to parse: " + expected
+ "\n" + pe.getMessage());
}
}
}
Expand Down Expand Up @@ -205,7 +197,6 @@ public void testMakeOID() {
};
int i = 0;
for (String oid : oids) {
out.println("Testing OID: " + oid);
byte[] encoded = CQLNode.makeOID(oid);
for (int j = 0; j < expected[i].length && j < encoded.length; j++) {
assertEquals("Byte " + j + " of OID " + oid, expected[i][j], encoded[j] & 0xff);
Expand Down
Loading