Search in sources :

Example 16 with Definitions

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);
}
Also used : APredicateDefinitionDefinition(de.be4.classicalb.core.parser.node.APredicateDefinitionDefinition) IDefinitions(de.be4.classicalb.core.parser.IDefinitions) BParser(de.be4.classicalb.core.parser.BParser) PPredicate(de.be4.classicalb.core.parser.node.PPredicate) File(java.io.File) Test(org.junit.Test)

Example 17 with Definitions

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);
}
Also used : AIdentifierExpression(de.be4.classicalb.core.parser.node.AIdentifierExpression) IDefinitions(de.be4.classicalb.core.parser.IDefinitions) AExpressionDefinitionDefinition(de.be4.classicalb.core.parser.node.AExpressionDefinitionDefinition) BParser(de.be4.classicalb.core.parser.BParser) Test(org.junit.Test)

Example 18 with Definitions

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("& &"));
    }
}
Also used : Ast2String(util.Ast2String) BCompoundException(de.be4.classicalb.core.parser.exceptions.BCompoundException) Test(org.junit.Test)

Example 19 with Definitions

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());
    }
}
Also used : BLexerException(de.be4.classicalb.core.parser.exceptions.BLexerException) Ast2String(util.Ast2String) BCompoundException(de.be4.classicalb.core.parser.exceptions.BCompoundException) Test(org.junit.Test)

Example 20 with Definitions

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("& &"));
    }
}
Also used : Ast2String(util.Ast2String) BCompoundException(de.be4.classicalb.core.parser.exceptions.BCompoundException) Test(org.junit.Test)

Aggregations

Test (org.junit.Test)19 Ast2String (util.Ast2String)17 BCompoundException (de.be4.classicalb.core.parser.exceptions.BCompoundException)16 BParser (de.be4.classicalb.core.parser.BParser)6 Token (de.be4.classicalb.core.preparser.node.Token)6 PreParseException (de.be4.classicalb.core.parser.exceptions.PreParseException)5 AExpressionDefinitionDefinition (de.be4.classicalb.core.parser.node.AExpressionDefinitionDefinition)5 IDefinitions (de.be4.classicalb.core.parser.IDefinitions)4 BLexerException (de.be4.classicalb.core.parser.exceptions.BLexerException)4 HashSet (java.util.HashSet)4 Definitions (de.be4.classicalb.core.parser.Definitions)3 Start (de.be4.classicalb.core.parser.node.Start)3 TIdentifierLiteral (de.be4.classicalb.core.parser.node.TIdentifierLiteral)3 File (java.io.File)3 IOException (java.io.IOException)3 ArrayList (java.util.ArrayList)3 CheckException (de.be4.classicalb.core.parser.exceptions.CheckException)2 AIdentifierExpression (de.be4.classicalb.core.parser.node.AIdentifierExpression)2 APredicateDefinitionDefinition (de.be4.classicalb.core.parser.node.APredicateDefinitionDefinition)2 ASubstitutionDefinitionDefinition (de.be4.classicalb.core.parser.node.ASubstitutionDefinitionDefinition)2