Search in sources :

Example 26 with AMachineParseUnit

use of de.be4.eventb.core.parser.node.AMachineParseUnit in project probparsers by bendisposto.

the class CommentTest method testInvariantsAndMultiComments.

@Test
public void testInvariantsAndMultiComments() throws BException {
    final String input = "machine InvariantsAndMultiComments invariants\n" + "@inv1 1=1\n" + "@inv2 2=2\n" + "/*inv2\ncomment*/\n" + "end";
    final Start rootNode = parseInput(input, false);
    final AMachineParseUnit parseUnit = (AMachineParseUnit) rootNode.getPParseUnit();
    final LinkedList<PInvariant> invariants = parseUnit.getInvariants();
    assertEquals(2, invariants.size());
    AInvariant invariant = (AInvariant) invariants.get(0);
    assertEquals(0, invariant.getComments().size());
    assertEquals("inv1", invariant.getName().getText());
    assertEquals("1=1", invariant.getPredicate().getText());
    invariant = (AInvariant) invariants.get(1);
    final LinkedList<TComment> comments = invariant.getComments();
    assertEquals(1, comments.size());
    assertEquals("inv2\ncomment", comments.get(0).getText());
    assertEquals("inv2", invariant.getName().getText());
    assertEquals("2=2", invariant.getPredicate().getText());
}
Also used : Start(de.be4.eventb.core.parser.node.Start) PInvariant(de.be4.eventb.core.parser.node.PInvariant) AInvariant(de.be4.eventb.core.parser.node.AInvariant) TComment(de.be4.eventb.core.parser.node.TComment) AMachineParseUnit(de.be4.eventb.core.parser.node.AMachineParseUnit) Test(org.junit.Test)

Example 27 with AMachineParseUnit

use of de.be4.eventb.core.parser.node.AMachineParseUnit in project probparsers by bendisposto.

the class CommentTest method testMultiLineComment.

@Test
public void testMultiLineComment() throws Exception {
    final Start rootNode = parseInput("machine MultiLineComment invariants @inv1 asdf\n/* First line\n  Second line*/\nend", false);
    final AMachineParseUnit parseUnit = (AMachineParseUnit) rootNode.getPParseUnit();
    final LinkedList<PInvariant> invariants = parseUnit.getInvariants();
    final AInvariant invariant = (AInvariant) invariants.get(0);
    // correct comment content?
    final LinkedList<TComment> comments = invariant.getComments();
    assertEquals(1, comments.size());
    final StringTokenizer tokenizer = new StringTokenizer(comments.get(0).getText(), "\n\r");
    assertEquals(2, tokenizer.countTokens());
    assertEquals("First line", tokenizer.nextToken());
    assertEquals("  Second line", tokenizer.nextToken());
    // correct invariant label?
    assertEquals("inv1", invariant.getName().getText());
    // correct string representation for predicate?
    assertEquals("asdf", invariant.getPredicate().getText());
}
Also used : StringTokenizer(java.util.StringTokenizer) Start(de.be4.eventb.core.parser.node.Start) PInvariant(de.be4.eventb.core.parser.node.PInvariant) AInvariant(de.be4.eventb.core.parser.node.AInvariant) TComment(de.be4.eventb.core.parser.node.TComment) AMachineParseUnit(de.be4.eventb.core.parser.node.AMachineParseUnit) Test(org.junit.Test)

Example 28 with AMachineParseUnit

use of de.be4.eventb.core.parser.node.AMachineParseUnit in project probparsers by bendisposto.

the class CommentTest method testMultipleComments1.

@Test
public void testMultipleComments1() throws Exception {
    final Start rootNode = parseInput("machine MultipleComments1" + "// line1\n" + "/* line2\nline3*/" + "// line4\n" + "\nend", false);
    final AMachineParseUnit parseUnit = (AMachineParseUnit) rootNode.getPParseUnit();
    final LinkedList<TComment> comments = parseUnit.getComments();
    assertEquals(3, comments.size());
    assertEquals("line1", comments.get(0).getText());
    assertEquals("line2\nline3", comments.get(1).getText());
    assertEquals("line4", comments.get(2).getText());
}
Also used : Start(de.be4.eventb.core.parser.node.Start) TComment(de.be4.eventb.core.parser.node.TComment) AMachineParseUnit(de.be4.eventb.core.parser.node.AMachineParseUnit) Test(org.junit.Test)

Example 29 with AMachineParseUnit

use of de.be4.eventb.core.parser.node.AMachineParseUnit in project probparsers by bendisposto.

the class SourcePositionsTest method testGetEndLine.

@Test
public void testGetEndLine() throws Exception {
    final Start root = parser.parse("machine\nTestMachine\n\nvariables\nx\n\nend", false);
    final AMachineParseUnit parseUnit = (AMachineParseUnit) root.getPParseUnit();
    assertEquals(7, ((PositionedNode) parseUnit).getEndPos().getLine());
    final LinkedList<PVariable> variables = parseUnit.getVariables();
    assertEquals(5, ((PositionedNode) variables.get(0)).getEndPos().getLine());
}
Also used : Start(de.be4.eventb.core.parser.node.Start) PositionedNode(de.hhu.stups.sablecc.patch.PositionedNode) PVariable(de.be4.eventb.core.parser.node.PVariable) AMachineParseUnit(de.be4.eventb.core.parser.node.AMachineParseUnit) Test(org.junit.Test)

Aggregations

Test (org.junit.Test)28 AMachineParseUnit (de.be4.eventb.core.parser.node.AMachineParseUnit)14 Start (de.be4.eventb.core.parser.node.Start)14 AMachineParseUnit (de.be4.eventbalg.core.parser.node.AMachineParseUnit)14 Start (de.be4.eventbalg.core.parser.node.Start)14 TComment (de.be4.eventb.core.parser.node.TComment)6 TComment (de.be4.eventbalg.core.parser.node.TComment)6 StringTokenizer (java.util.StringTokenizer)6 AInvariant (de.be4.eventb.core.parser.node.AInvariant)5 PInvariant (de.be4.eventb.core.parser.node.PInvariant)5 AInvariant (de.be4.eventbalg.core.parser.node.AInvariant)5 PInvariant (de.be4.eventbalg.core.parser.node.PInvariant)5 PVariable (de.be4.eventb.core.parser.node.PVariable)3 PVariable (de.be4.eventbalg.core.parser.node.PVariable)3 AEvent (de.be4.eventb.core.parser.node.AEvent)2 AVariable (de.be4.eventb.core.parser.node.AVariable)2 AEvent (de.be4.eventbalg.core.parser.node.AEvent)2 AVariable (de.be4.eventbalg.core.parser.node.AVariable)2 PositionedNode (de.hhu.stups.sablecc.patch.PositionedNode)2 AAction (de.be4.eventb.core.parser.node.AAction)1