Minres / CoreDSL

Xtext project to parse CoreDSL files
Apache License 2.0
14 stars 2 forks source link

Analyzer Tests and Fixes (Round 4) #84

Closed AtomCrafty closed 1 year ago

AtomCrafty commented 1 year ago

The test framework now allows you to specify semantic expectations.


An example using direct expectations: The first two parameters specify which AST node is passed as it in the lambda. The last parameter is a short description of the expected state.

'''
    if(true)
    if(true){}
    else{}
'''
.testStatements()
.expect(IfStatement, 1, [it.elseBody === null], "The outer if statement has no else branch")
.expect(IfStatement, 2, [it.elseBody !== null], "The inner if statement has an else branch")
.run();

An example using type and value expectations. The first parameter can specify which ISA's analysis results should be used. In this case we can pass null because there is only one ISA (added by testStatements).

'''
    switch(0) {
        case 0: break;
        case 1 - 1: break;
        case 0 * 25: break;
    }
'''
.testStatements()
.expectType(null, IntegerConstant, 1, IntegerType.bool)
.expectValue(null, InfixExpression, 3, 0)
.expectValue(null, InfixExpression, 4, 0)
.expectError(IssueCodes.SwitchDuplicateCaseSection, 3)
.expectError(IssueCodes.SwitchDuplicateCaseSection, 4)
.run();