use of de.be4.classicalb.core.parser.BParser in project probparsers by bendisposto.
the class PositionAspectTest method testComposedNode.
@Test
public void testComposedNode() throws Exception {
final String testMachine = "#EXPRESSION x+1";
final BParser parser = new BParser("testcase");
final Start startNode = parser.parse(testMachine, true);
// test top node
final PExpression expression = ((AExpressionParseUnit) startNode.getPParseUnit()).getExpression();
SourcePosition startPos = expression.getStartPos();
SourcePosition endPos = expression.getEndPos();
assertNotNull(startNode);
assertNotNull(endPos);
assertEquals(1, startPos.getLine());
assertEquals(13, startPos.getPos());
assertEquals(1, endPos.getLine());
assertEquals(16, endPos.getPos());
// test left child: 13-14
final PExpression leftExpr = ((AAddExpression) expression).getLeft();
startPos = leftExpr.getStartPos();
endPos = leftExpr.getEndPos();
assertNotNull(startNode);
assertNotNull(endPos);
assertEquals(1, startPos.getLine());
assertEquals(13, startPos.getPos());
assertEquals(1, endPos.getLine());
assertEquals(14, endPos.getPos());
// test right child: 15-16
final PExpression rightExpr = ((AAddExpression) expression).getRight();
startPos = rightExpr.getStartPos();
endPos = rightExpr.getEndPos();
assertNotNull(startNode);
assertNotNull(endPos);
assertEquals(1, startPos.getLine());
assertEquals(15, startPos.getPos());
assertEquals(1, endPos.getLine());
assertEquals(16, endPos.getPos());
}
use of de.be4.classicalb.core.parser.BParser in project probparsers by bendisposto.
the class PositionAspectTest method testNodeSubclassOfPositionedNode.
@Test
public void testNodeSubclassOfPositionedNode() throws Exception {
final String testMachine = "#EXPRESSION 1+2";
final BParser parser = new BParser("testcase");
final Start startNode = parser.parse(testMachine, true);
assertTrue(startNode instanceof PositionedNode);
}
use of de.be4.classicalb.core.parser.BParser in project probparsers by bendisposto.
the class ByteOrderMarkTests method testParsable.
@Test
public void testParsable() throws Exception {
final BParser parser = new BParser(machine.getName());
Start start = parser.parseFile(machine, false);
start.apply(new PositionTester());
assertNotNull(start);
}
use of de.be4.classicalb.core.parser.BParser in project probparsers by bendisposto.
the class DefinitionFilesTest method testNotExistingFile.
@Test
public void testNotExistingFile() {
final String testMachine = "MACHINE Test\nDEFINITIONS \"DefFile\"; def1 == xx\nEND";
try {
new BParser("testcase").parse(testMachine, false, new PlainFileContentProvider());
fail("Expected exception was not thrown");
} catch (final BCompoundException e) {
// EXPECTED
}
}
use of de.be4.classicalb.core.parser.BParser in project probparsers by bendisposto.
the class DefinitionFilesTest method testRealFiles.
/*
* test with real files
*/
@Test
public void testRealFiles() throws Exception {
final BParser parser = new BParser("testcase");
File machine = new File("src/test/resources/parsable/DefinitionFileTest.mch");
parser.parseFile(machine, false);
final IDefinitions definitions = parser.getDefinitions();
final APredicateDefinitionDefinition def1 = (APredicateDefinitionDefinition) definitions.getDefinition("GRD2");
assertEquals("GRD2", def1.getName().getText());
assertEquals(0, def1.getParameters().size());
assertTrue(def1.getRhs() instanceof PPredicate);
final APredicateDefinitionDefinition def2 = (APredicateDefinitionDefinition) definitions.getDefinition("GRD1");
assertEquals("GRD1", def2.getName().getText());
assertEquals(0, def2.getParameters().size());
assertTrue(def2.getRhs() instanceof PPredicate);
}
Aggregations