Search in sources :

Example 11 with Definitions

use of de.be4.classicalb.core.parser.Definitions in project probparsers by bendisposto.

the class DefinitionsErrorsTest method checkForErrorPositionInDefinitionWithMultilineComments.

@Test
public void checkForErrorPositionInDefinitionWithMultilineComments() throws Exception {
    String s = "MACHINE Definitions \n DEFINITIONS \n foo == 1=1\n /* \n comment\n comment2\n comment3 \n */\n&& 1=1 \nEND";
    System.out.println(s);
    try {
        getTreeAsString(s);
        fail("Invalid definition was not detected.");
    } catch (BCompoundException e) {
        System.out.println(e.getMessage());
        assertTrue(e.getMessage().contains("[9,2]"));
    }
}
Also used : Ast2String(util.Ast2String) BCompoundException(de.be4.classicalb.core.parser.exceptions.BCompoundException) Test(org.junit.Test)

Example 12 with Definitions

use of de.be4.classicalb.core.parser.Definitions in project probparsers by bendisposto.

the class DefinitionsErrorsTest method checkForInvalidFormula3.

@Test
public void checkForInvalidFormula3() throws Exception {
    String s = "MACHINE Definitions \n DEFINITIONS\n foo(xx) == (xx : OBJECTS -->(1..card(OBJECTS))\n; \nEND";
    try {
        getTreeAsString(s);
        fail("Invalid formula 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("[4,1]"));
        assertTrue(e.getMessage().contains("expecting: ')'"));
    }
}
Also used : Ast2String(util.Ast2String) BCompoundException(de.be4.classicalb.core.parser.exceptions.BCompoundException) Test(org.junit.Test)

Example 13 with Definitions

use of de.be4.classicalb.core.parser.Definitions in project probparsers by bendisposto.

the class DefinitionsErrorsTest method checkForInvalidFormula2.

@Test
public void checkForInvalidFormula2() throws Exception {
    String s = "MACHINE Definitions \n DEFINITIONS\n foo == \n 1=; \nEND";
    try {
        getTreeAsString(s);
        fail("Invalid formula 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("[4,4]"));
    }
}
Also used : Ast2String(util.Ast2String) BCompoundException(de.be4.classicalb.core.parser.exceptions.BCompoundException) Test(org.junit.Test)

Example 14 with Definitions

use of de.be4.classicalb.core.parser.Definitions in project probparsers by bendisposto.

the class DefinitionFilesTest method testRecursiveReference.

// TODO test two files
/*
	 * test recursive references from def file to def file
	 */
@Test
public void testRecursiveReference() throws Exception {
    final String testMachine = "MACHINE Test\nDEFINITIONS \"DefFile1\"; def1 == xx; def02 == aa\nEND";
    final BParser parser = new BParser("testcase");
    parser.parse(testMachine, false, 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);
    String ident = Utils.getTIdentifierListAsString(((AIdentifierExpression) def1.getRhs()).getIdentifier());
    assertEquals("xx", ident);
    final AExpressionDefinitionDefinition def2 = (AExpressionDefinitionDefinition) definitions.getDefinition("def2");
    assertEquals("def2", def2.getName().getText());
    assertEquals(0, def2.getParameters().size());
    assertTrue(def2.getRhs() instanceof AIdentifierExpression);
    ident = Utils.getTIdentifierListAsString(((AIdentifierExpression) def2.getRhs()).getIdentifier());
    assertEquals("yy", ident);
    final AExpressionDefinitionDefinition def3 = (AExpressionDefinitionDefinition) definitions.getDefinition("def3");
    assertEquals("def3", def3.getName().getText());
    assertEquals(0, def3.getParameters().size());
    assertTrue(def3.getRhs() instanceof AIdentifierExpression);
    ident = Utils.getTIdentifierListAsString(((AIdentifierExpression) def3.getRhs()).getIdentifier());
    // definition in outer def file should overwrite the one in referenced
    // def file
    assertEquals("bb", ident);
}
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 15 with Definitions

use of de.be4.classicalb.core.parser.Definitions in project probparsers by bendisposto.

the class DefinitionsErrorsTest method checkForInvalidExpression.

@Test
public void checkForInvalidExpression() throws Exception {
    String s = "MACHINE Definitions \n DEFINITIONS \n foo == 1 + \nEND";
    try {
        getTreeAsString(s);
        fail("Invalid definition was not detected.");
    } catch (BCompoundException e) {
        System.out.println(e.getMessage());
        assertTrue(e.getMessage().contains("[4,1]"));
    }
}
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