Ejemplo n.º 1
0
  @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());
    }
  }
Ejemplo n.º 2
0
  @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());
    }
  }
Ejemplo n.º 3
0
  @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());
    }
  }
Ejemplo n.º 4
0
  @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());
    }
  }