@Test public void testUnknownCommandFailsParsing_3() throws Exception { ScriptWrapper wrapper = new ScriptWrapper(); wrapper.addLine(""); wrapper.addLine("Meh 1"); wrapper.addLine("Echo \"hello\""); wrapper.addLine("If true"); wrapper.addLine(" Meh 2"); wrapper.addLine(" Meh 3"); try { parser.parse(wrapper.toString()); // System.out.println(parserResult.getContent()); Assert.fail("unknown command should result in ParserException"); } catch (HulaParserException e) { // expected behaviour System.out.println(e.getErrors()); Assert.assertEquals("wrong number of errors", 4, e.getErrors().size()); assertError(e, 0, 2, "Meh 1", "unknown.command"); assertError(e, 1, 5, "Meh 2", "unknown.command"); assertError(e, 2, 6, "Meh 3", "unknown.command"); assertError(e, 3, 4, "If true", "missing.end.statement"); } }
@Test public void testUnknownCommandFailsParsing_2() throws Exception { ScriptWrapper wrapper = new ScriptWrapper(); wrapper.addLine("Meh 1"); wrapper.addLine("Echo \"hello\""); wrapper.addLine("Meh 2"); wrapper.addLine("Meh 3"); try { HulaExecutable parserResult = parser.parse(wrapper.toString()); System.out.println(parserResult.getContent()); Assert.fail("unknown command should result in ParserException"); } catch (HulaParserException e) { // expected behaviour Assert.assertEquals("wrong number of errors", 3, e.getErrors().size()); assertError(e, 0, 1, "Meh 1", "unknown.command"); assertError(e, 1, 3, "Meh 2", "unknown.command"); assertError(e, 2, 4, "Meh 3", "unknown.command"); } }
@Test public void testParserValidatesGeneratedCode() throws Exception { ScriptWrapper wrapper = new ScriptWrapper(); wrapper.addLine("Echo hello"); wrapper.addLine("ProduceJunkCode"); wrapper.addLine("Echo goodbye"); try { parser.parse(wrapper.toString()); Assert.fail("unknown command should result in ParserException"); } catch (HulaParserException e) { List<ParseError> errors = e.getErrors(); ParseError error = errors.get(0); // expected behaviour Assert.assertEquals("missing line number", -1, error.getLineNumber()); Assert.assertEquals("missing command line", null, error.getCommandLine()); Assert.assertEquals("missing error code", "unknown.parse.error", error.getErrorCode()); } }
@Test public void testUnknownCommandFailsParsing() throws Exception { ScriptWrapper wrapper = new ScriptWrapper(); wrapper.addLine("Meh"); // parse try { parser.parse(wrapper.toString()); Assert.fail("unknown command should result in ParserException"); } catch (HulaParserException e) { List<ParseError> errors = e.getErrors(); ParseError error = errors.get(0); // expected behaviour Assert.assertEquals("missing line number", 1, error.getLineNumber()); Assert.assertEquals("missing command line", "Meh", error.getCommandLine()); Assert.assertEquals("missing error code", "unknown.command", error.getErrorCode()); } }
@Test public void testSuperfluousEndFailsParsing_2() throws Exception { ScriptWrapper wrapper = new ScriptWrapper(); wrapper.addLine("End"); // parse try { HulaExecutable parserResult = parser.parse(wrapper.toString()); System.out.println(parserResult.getContent()); Assert.fail("additional end statement should result in ParserException"); } catch (HulaParserException e) { List<ParseError> errors = e.getErrors(); ParseError error = errors.get(0); // expected behaviour Assert.assertEquals("missing line number", 1, error.getLineNumber()); Assert.assertEquals("missing command line", "End", error.getCommandLine()); Assert.assertEquals("missing error code", "unnecessary.end.statement", error.getErrorCode()); } }
@Test public void testMissingEndFailsParsing_2() throws Exception { ScriptWrapper wrapper = new ScriptWrapper(); wrapper.addLine("Loop $names as name"); wrapper.addLine(" Set value=$name"); // parse try { parser.parse(wrapper.toString()); Assert.fail("missing end statement should result in ParserException"); } catch (HulaParserException e) { List<ParseError> errors = e.getErrors(); ParseError error = errors.get(0); // expected behaviour Assert.assertEquals("missing line number", 1, error.getLineNumber()); Assert.assertEquals("missing command line", "Loop $names as name", error.getCommandLine()); Assert.assertEquals("missing error code", "missing.end.statement", error.getErrorCode()); } }