use of de.be4.classicalb.core.parser.Definitions 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);
}
use of de.be4.classicalb.core.parser.Definitions in project probparsers by bendisposto.
the class DefinitionFilesTest method testOneDefinitionFile.
@Test
public void testOneDefinitionFile() throws BCompoundException {
final String testMachine = "MACHINE Test\nDEFINITIONS \"DefFile\"; def1 == xx\nINVARIANT def2 = def3\nEND";
final BParser parser = new BParser("testcase");
parser.parse(testMachine, true, this);
final IDefinitions definitions = parser.getDefinitions();
final AExpressionDefinitionDefinition def1 = (AExpressionDefinitionDefinition) definitions.getDefinition("def1");
assertEquals("def1", def1.getName().getText());
assertEquals(0, def1.getParameters().size());
assertTrue(def1.getRhs() instanceof AIdentifierExpression);
final AExpressionDefinitionDefinition def2 = (AExpressionDefinitionDefinition) definitions.getDefinition("def2");
assertEquals("def2", def2.getName().getText());
assertEquals(0, def2.getParameters().size());
assertTrue(def2.getRhs() instanceof AIdentifierExpression);
}
use of de.be4.classicalb.core.parser.Definitions in project probparsers by bendisposto.
the class SyntaxErrorsDetectedOnTokenStreamTest method checkForDublicateAndInDefinitionsClause2.
@Test
public void checkForDublicateAndInDefinitionsClause2() throws Exception {
String s = "MACHINE Definitions \n DEFINITIONS\n foo == \n \n 1=1 \n& & 2=2 \nEND";
try {
getTreeAsString(s);
fail("Duplicate & was not detected.");
} catch (BCompoundException e) {
System.out.println(e.getMessage());
// there is no token available, hence the position is in the text
assertTrue(e.getMessage().contains("[6,6]"));
assertTrue(e.getMessage().contains("& &"));
}
}
use of de.be4.classicalb.core.parser.Definitions in project probparsers by bendisposto.
the class SyntaxErrorsDetectedOnTokenStreamTest method checkForDuplicateAnd.
@Test
public void checkForDuplicateAnd() throws Exception {
String s = "MACHINE Definitions\nPROPERTIES\n 1=1 &\n & 2 = 2 END";
try {
getTreeAsString(s);
fail("Duplicate & was not detected.");
} catch (BCompoundException e) {
System.out.println(e.getMessage());
final BLexerException ex = (BLexerException) e.getCause();
// checking the position of the second &
assertEquals(4, ex.getLastLine());
assertEquals(2, ex.getLastPos());
}
}
use of de.be4.classicalb.core.parser.Definitions in project probparsers by bendisposto.
the class SyntaxErrorsDetectedOnTokenStreamTest method checkForSingleLineCommentBetweenDuplicateAnd.
@Test
public void checkForSingleLineCommentBetweenDuplicateAnd() throws Exception {
String s = "MACHINE Definitions\nPROPERTIES 1=1 & // comment 1 comment \n & 2 = 2 END";
try {
getTreeAsString(s);
fail("Duplicate & was not detected.");
} catch (BCompoundException e) {
System.out.println(e.getMessage());
assertTrue(e.getMessage().contains("& &"));
}
}
Aggregations