use of csep.parser.Lexer in project coffeescript-eclipse by adamschmideg.
the class ParserTestBase method expect.
/**
* Parse and check for errors and warnings
* @param errorCount 1 means expect error(s)
* @param warningCount -1 means don't care about warnings
*/
protected void expect(CharSequence input, int errorCount, int warningCount) {
List<String> tokens = null;
//Assert::assertEquals('warnings ' + resource.warnings, 0, resource.warnings.size)
//Assert::assertEquals('errors ' + resource.errors, 0, resource.errors.size)
EObject parseResult = null;
EList<Diagnostic> errors = null;
EList<Diagnostic> warnings = null;
try {
Lexer lexer = new Lexer(input);
tokens = lexer.tokenizeToStrings();
InputStream in = getAsStream("" + input);
URI uri = URI.createURI("mytestmodel." + getCurrentFileExtension());
XtextResource resource = doGetResource(in, uri);
parseResult = getModel(resource);
errors = resource.getErrors();
warnings = resource.getWarnings();
if (errorCount == 0)
assertEquals("Errors: " + errors, 0, errors.size());
else if (errorCount > 0)
assertTrue("No errors", errors.size() > 0);
if (warningCount >= 0) {
assertEquals("Warnings: " + warnings, warningCount, warnings.size());
}
} catch (AssertionFailedError afe) {
if (logger.isDebugEnabled()) {
String debug = "" + this.getClass().getSimpleName() + " input: \n" + input + "\n";
debug += "Tokens: " + tokens + "\n" + Helper.stringify(parseResult);
for (Diagnostic d : errors) {
debug += "\tError: " + d + "\n";
}
for (Diagnostic d : warnings) {
debug += "\tWarning: " + d + "\n";
}
logger.debug(debug);
}
throw new AssertionError(afe);
} catch (Exception e) {
throw new RuntimeException(e);
}
}
Aggregations