Search in sources :

Example 61 with BCompoundException

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

the class SubstitutionTest method testParallelAssignWithNonIdentifier.

@Test
public void testParallelAssignWithNonIdentifier() throws BCompoundException {
    final String testMachine = "#SUBSTITUTION xx,yy,5  := 5, 3, zz";
    try {
        getTreeAsString(testMachine);
        fail("Expected exception");
    } catch (final BCompoundException e) {
    // final CheckException cause = (CheckException) e.getCause();
    // assertEquals(1, cause.getNodes().length);
    // assertNotNull(cause.getNodes()[0]);
    }
}
Also used : Ast2String(util.Ast2String) BCompoundException(de.be4.classicalb.core.parser.exceptions.BCompoundException) Test(org.junit.Test)

Example 62 with BCompoundException

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

the class AtelierBCompatibilityTest method testSysExtension.

@Test
public void testSysExtension() throws IOException, BCompoundException {
    String PATH = "src/test/resources/atelierb/sys_extension/";
    String file = PATH + "main.sys";
    File f = new File(file);
    BParser bparser = new BParser();
    Start ast = bparser.parseFile(f, false);
    assertNotNull(ast);
    RecursiveMachineLoader rml = new RecursiveMachineLoader(PATH, bparser.getContentProvider());
    rml.loadAllMachines(f, ast, bparser.getDefinitions());
}
Also used : Start(de.be4.classicalb.core.parser.node.Start) BParser(de.be4.classicalb.core.parser.BParser) File(java.io.File) Test(org.junit.Test)

Example 63 with BCompoundException

use of de.be4.classicalb.core.parser.exceptions.BCompoundException 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)

Example 64 with BCompoundException

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

the class DefinitionsTest method testParamsCount1.

@Test
public void testParamsCount1() {
    final String testMachine = "MACHINE Test\nDEFINITIONS\ndefExpr(x)==g(x)\nOPERATIONS\nop=BEGIN defExpr(x); defExpr END\nEND";
    try {
        getTreeAsString(testMachine);
        fail("Expected exception was not thrown");
    } catch (final BCompoundException e) {
        final CheckException cause = (CheckException) e.getCause();
        assertEquals(1, cause.getNodes().length);
        assertNotNull(cause.getNodes()[0]);
        assertEquals("Number of parameters doesn't match declaration of definition", cause.getLocalizedMessage());
    // IGNORE, is expected
    }
}
Also used : CheckException(de.be4.classicalb.core.parser.exceptions.CheckException) Helpers.getTreeAsString(util.Helpers.getTreeAsString) BCompoundException(de.be4.classicalb.core.parser.exceptions.BCompoundException) Test(org.junit.Test)

Example 65 with BCompoundException

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

the class DefinitionsTest method testExprOrSubst3.

@Test
public void testExprOrSubst3() {
    final String testMachine = "MACHINE Test\nDEFINITIONS\ndefExpr==g(x)\nOPERATIONS\nop=PRE defExpr=42 THEN defExpr END\nEND";
    try {
        getTreeAsString(testMachine);
        fail("Expected exception was not thrown");
    } catch (final BCompoundException e) {
        final CheckException cause = (CheckException) e.getCause();
        assertEquals("Expecting substitution here but found definition with type 'Expression'", cause.getLocalizedMessage());
    // IGNORE, is expected
    }
}
Also used : CheckException(de.be4.classicalb.core.parser.exceptions.CheckException) Helpers.getTreeAsString(util.Helpers.getTreeAsString) BCompoundException(de.be4.classicalb.core.parser.exceptions.BCompoundException) Test(org.junit.Test)

Aggregations

BCompoundException (de.be4.classicalb.core.parser.exceptions.BCompoundException)73 Test (org.junit.Test)64 Ast2String (util.Ast2String)62 Start (de.be4.classicalb.core.parser.node.Start)52 BParser (de.be4.classicalb.core.parser.BParser)29 CheckException (de.be4.classicalb.core.parser.exceptions.CheckException)19 File (java.io.File)15 BParseException (de.be4.classicalb.core.parser.exceptions.BParseException)9 IOException (java.io.IOException)8 ArrayList (java.util.ArrayList)8 ParsingBehaviour (de.be4.classicalb.core.parser.ParsingBehaviour)7 RecursiveMachineLoader (de.be4.classicalb.core.parser.analysis.prolog.RecursiveMachineLoader)7 BException (de.be4.classicalb.core.parser.exceptions.BException)7 Helpers.getTreeAsString (util.Helpers.getTreeAsString)7 BLexerException (de.be4.classicalb.core.parser.exceptions.BLexerException)5 PreParseException (de.be4.classicalb.core.parser.exceptions.PreParseException)5 LexerException (de.be4.classicalb.core.parser.lexer.LexerException)5 Node (de.be4.classicalb.core.parser.node.Node)5 ASTProlog (de.be4.classicalb.core.parser.analysis.prolog.ASTProlog)4 IPrologTermOutput (de.prob.prolog.output.IPrologTermOutput)4