Package net.sf.lapg.test

Examples of net.sf.lapg.test.TestNotifier


      new TestLexem(1, 0, "number", "[0-9]+"),
      new TestLexem(2, 0, "empty", "()"),
  };

  public void testGenerator() {
    LexerTables lt = LexicalBuilder.compile(INPUT1, new ProcessingStatusAdapter(new TestNotifier(), 0));
    for(TestLexem tl : INPUT1) {
      for(String s : tl.getSamples()) {
        int res = nextToken(lt, s);
        Assert.assertEquals("For "+s+" Expected " + tl.getRegexp()+ ";",tl.index, res);
      }
View Full Code Here


      }
    }
  }

  public void testLexGeneratorReporting() {
    TestNotifier notifier = new TestNotifier(
        "",
        "lexemtest,3: empty: lexem is empty\n" +
        "lexemtest,1: two lexems are identical: string and number\n");
    LexicalBuilder.compile(ERRINPUT, new ProcessingStatusAdapter(notifier, 0));
    notifier.assertDone();

  }
View Full Code Here

public class AnnotationsTest extends LapgTestCase {

  public void testAllAnnotations() {
    Grammar g = SyntaxUtil.parseSyntax("syntax1annotated", openStream("syntax1annotated", TESTCONTAINER),
        new TestNotifier(), new HashMap<String, Object>());
    Assert.assertNotNull(g);

    Rule[] listItemRules = rulesForName(g.getRules(), "list_item");
    Assert.assertEquals(2, listItemRules.length);
View Full Code Here

    Assert.assertTrue(refval instanceof Symbol);
    Assert.assertTrue(refval == s);
  }

  public void testBadAnnotations() {
    TestNotifier notifier = new TestNotifier("", "notexistingsym cannot be resolved\n"
        + "redeclaration of annotation `name' for non-terminal: tempanno, skipped\n");
    Grammar g = SyntaxUtil.parseSyntax("syntax1errannotated", openStream("syntax1errannotated", TESTCONTAINER),
        notifier, new HashMap<String, Object>());
    Assert.assertNull(g);
  }
View Full Code Here

    Assert.assertEquals(expected, actual);
  }

  public void testCheckSimple1() {
    Grammar g = SyntaxUtilOld.parseSyntax("syntax1", openStream("syntax1", TESTCONTAINER), new TestNotifier(),
        new HashMap<String, String>());
    Assert.assertNotNull(g);
    Assert.assertEquals(0, g.getEoi().getIndex());

    Symbol[] syms = g.getSymbols();
    Assert.assertEquals(7, syms.length);
    Assert.assertEquals("eoi", syms[0].getName());
    Assert.assertEquals("identifier", syms[1].getName());
    Assert.assertEquals("Licon", syms[2].getName());
    Assert.assertEquals("_skip", syms[3].getName()); // TODO do not
    // collect skip
    // symbols
    Assert.assertEquals("input", syms[4].getName());
    Assert.assertEquals("list", syms[5].getName());
    Assert.assertEquals("list_item", syms[6].getName());

    Rule[] rules = g.getRules();
    Assert.assertEquals(5, rules.length);
    Assert.assertEquals("input", rules[0].getLeft().getName());
    Assert.assertEquals("list", rules[0].getRight()[0].getTarget().getName());
    Assert.assertEquals(1, rules[0].getRight().length);

    Lexem[] lexems = g.getLexems();
    Assert.assertEquals(3, lexems.length);
    Assert.assertEquals("@?[a-zA-Z_][A-Za-z_0-9]*", lexems[0].getRegexp());
    Assert.assertEquals("([1-9][0-9]*|0[0-7]*|0[xX][0-9a-fA-F]+)([uU](l|L|ll|LL)?|(l|L|ll|LL)[uU]?)?", lexems[1]
        .getRegexp());
    Assert.assertEquals("[\\t\\r\\n ]+", lexems[2].getRegexp());
    Assert.assertEquals(" continue; ", lexems[2].getAction().getContents());

    checkGenTables(g, "syntax1.tbl", new TestNotifier());
  }
View Full Code Here

    checkGenTables(g, "syntax1.tbl", new TestNotifier());
  }

  public void testCheckSimple2() {
    Grammar g = SyntaxUtilOld.parseSyntax("syntax2", openStream("syntax2", TESTCONTAINER), new TestNotifier(),
        new HashMap<String, String>());
    Assert.assertNotNull(g);
    Assert.assertEquals(0, g.getEoi().getIndex());

    Symbol[] syms = g.getSymbols();
    Assert.assertEquals(9, syms.length);
    Assert.assertEquals("eoi", syms[0].getName());
    Assert.assertEquals("a", syms[1].getName());
    Assert.assertEquals("b", syms[2].getName());
    Assert.assertEquals("'('", syms[3].getName());
    Assert.assertEquals("')'", syms[4].getName());
    Assert.assertEquals("input", syms[5].getName());
    Assert.assertEquals("list", syms[6].getName());
    Assert.assertEquals("item", syms[7].getName());
    Assert.assertEquals("listopt", syms[8].getName());
    Assert.assertEquals(8, g.getRules().length);
    Assert.assertEquals("  ${for a in b}..!..$$  ", g.getRules()[7].getAction().getContents());

    checkGenTables(g, "syntax2.tbl", new TestNotifier());
  }
View Full Code Here

    checkGenTables(g, "syntax2.tbl", new TestNotifier());
  }

  public void testCheckCSharpGrammar() {
    Grammar g = SyntaxUtilOld.parseSyntax("syntax_cs", openStream("syntax_cs", TESTCONTAINER), new TestNotifier(),
        new HashMap<String, String>());
    Assert.assertNotNull(g);

    TestNotifier er = new TestNotifier(
        "syntax_cs,3: symbol `error` is useless\n" + "syntax_cs,44: symbol `Lfixed` is useless\n"
            + "syntax_cs,76: symbol `Lstackalloc` is useless\n"
            + "syntax_cs,149: symbol `comment` is useless\n" + "syntax_cs,155: symbol `'/*'` is useless\n"
            + "syntax_cs,157: symbol `anysym1` is useless\n" + "syntax_cs,159: symbol `'*/'` is useless\n",

        "input: using_directivesopt attributesopt modifiersopt Lclass ID class_baseopt '{' attributesopt modifiersopt operator_declarator '{' Lif '(' expression ')' embedded_statement\n"
            + "shift/reduce conflict (next: Lelse)\n"
            + "    embedded_statement ::= Lif '(' expression ')' embedded_statement\n"
            + "\n"
            + "conflicts: 1 shift/reduce and 0 reduce/reduce\n");

    checkGenTables(g, "syntax_cs.tbl", er);
    er.assertDone();

    Assert.assertTrue(g.getTemplates().startsWith("\n//#define DEBUG_syntax"));
  }
View Full Code Here

    Assert.assertTrue(g.getTemplates().startsWith("\n//#define DEBUG_syntax"));
  }

  public void testLapgGrammar() {
    Grammar g = SyntaxUtilOld.parseSyntax("syntax_lapg", openStream("syntax_lapg", TESTCONTAINER),
        new TestNotifier(), new HashMap<String, String>());
    Assert.assertNotNull(g);

    checkGenTables(g, "syntax_lapg.tbl", new TestNotifier());
  }
View Full Code Here

    checkGenTables(g, "syntax_lapg.tbl", new TestNotifier());
  }

  public void testLapgTemplatesGrammar() {
    Grammar g = SyntaxUtilOld.parseSyntax("syntax_tpl", openStream("syntax_tpl", TESTCONTAINER),
        new TestNotifier(), new HashMap<String, String>());
    Assert.assertNotNull(g);

    checkGenTables(g, "syntax_tpl.tbl", new TestNotifier());
  }
View Full Code Here

    checkGenTables(g, "syntax_tpl.tbl", new TestNotifier());
  }

  public void testNewTemplatesGrammar() {
    Grammar g = SyntaxUtil.parseSyntax("syntax_tpl", openStream("syntax_tpl", TESTCONTAINER), new TestNotifier(),
        new HashMap<String, Object>());
    Grammar go = SyntaxUtilOld.parseSyntax("syntax_tpl", openStream("syntax_tpl", TESTCONTAINER),
        new TestNotifier(), new HashMap<String, String>());
    Assert.assertNotNull(g);

    sortGrammar((LiGrammar) g, go);
    checkGenTables(g, "syntax_tpl.tbl", new TestNotifier());
  }
View Full Code Here

TOP

Related Classes of net.sf.lapg.test.TestNotifier

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.