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();
}
}
+ /**
+ * Test the integrity of the parser as follows:
+ * - Generate a random tree with CQLGenerator
+ * - Serialize it
+ * - Canonicalise it by running through the parser
+ * - Compare the before-and-after versions.
+ * Since the CQLGenerator output is in canonical form anyway, the
+ * before-and-after versions should be identical. This process exercises
+ * the comprehensiveness and bullet-proofing of the parser, as well as
+ * the accuracy of the rendering.
+ * @throws IOException
+ * @throws MissingParameterException
+ */
@Test
public void testRandomQueries() throws IOException, MissingParameterException {
out.println("Testing the parser using 100 randomly generated queries...");
}
}
-
//helper methods follow
//TODO move to masterkey-common