Search in sources :

Example 11 with AssertableDiagnostics

use of org.eclipse.xtext.junit4.validation.AssertableDiagnostics in project statecharts by Yakindu.

the class STextJavaValidatorTest method checkNoAssignmentInGuard.

@Test
public void checkNoAssignmentInGuard() {
    String scope = "internal: var myInt : integer var myBool : boolean = true";
    EObject expression = super.parseExpression("[myBool = false]", ReactionTrigger.class.getSimpleName(), scope);
    AssertableDiagnostics validationResult = tester.validate(expression);
    validationResult.assertErrorContains(STextJavaValidator.GUARD_CONTAINS_ASSIGNMENT);
    expression = super.parseExpression("[myInt = 5]", ReactionTrigger.class.getSimpleName(), scope);
    validationResult = tester.validate(expression);
    Iterator<Diagnostic> diag = validationResult.getAllDiagnostics().iterator();
    while (diag.hasNext()) {
        Diagnostic d = diag.next();
        if (d.getMessage().equals(GUARD_EXPRESSION)) {
            assertEquals(STextJavaValidator.GUARD_EXPRESSION, d.getMessage());
        } else {
            assertEquals(STextJavaValidator.GUARD_CONTAINS_ASSIGNMENT, d.getMessage());
        }
    }
}
Also used : AssertableDiagnostics(org.eclipse.xtext.junit4.validation.AssertableDiagnostics) ReactionTrigger(org.yakindu.sct.model.stext.stext.ReactionTrigger) EObject(org.eclipse.emf.ecore.EObject) Diagnostic(org.eclipse.emf.common.util.Diagnostic) Test(org.junit.Test)

Example 12 with AssertableDiagnostics

use of org.eclipse.xtext.junit4.validation.AssertableDiagnostics in project statecharts by Yakindu.

the class STextJavaValidatorTest method checkReactionTrigger.

/**
 * @see STextJavaValidator#checkReactionTrigger(org.yakindu.sct.model.stext.stext.ReactionTrigger)
 */
@Test
public void checkReactionTrigger() {
    // ENTRY, EXIT not allowed in transitions
    String scope = "internal : event a : integer var myVar : integer";
    EObject model = super.parseExpression("entry / myVar = 5", TransitionSpecification.class.getSimpleName(), scope);
    AssertableDiagnostics validationResult = tester.validate(model);
    validationResult.assertError(ENTRY_EXIT_TRIGGER_NOT_ALLOWED);
    model = super.parseExpression("exit / myVar = 5", TransitionSpecification.class.getSimpleName(), scope);
    validationResult = tester.validate(model);
    validationResult.assertError(ENTRY_EXIT_TRIGGER_NOT_ALLOWED);
    model = super.parseExpression("oncycle / myVar = 5", TransitionSpecification.class.getSimpleName(), scope);
    validationResult = tester.validate(model);
    validationResult.assertOK();
    model = super.parseExpression("always / myVar = 5", TransitionSpecification.class.getSimpleName(), scope);
    validationResult = tester.validate(model);
    validationResult.assertOK();
}
Also used : AssertableDiagnostics(org.eclipse.xtext.junit4.validation.AssertableDiagnostics) EObject(org.eclipse.emf.ecore.EObject) TransitionSpecification(org.yakindu.sct.model.stext.stext.TransitionSpecification) Test(org.junit.Test)

Example 13 with AssertableDiagnostics

use of org.eclipse.xtext.junit4.validation.AssertableDiagnostics in project statecharts by Yakindu.

the class STextJavaValidatorTest method testOptionalParameter.

@Test
public void testOptionalParameter() {
    EObject model;
    String rule = Expression.class.getSimpleName();
    AssertableDiagnostics result;
    model = parseExpression("optOp1()", rule);
    result = tester.validate(model);
    result.assertOK();
    model = parseExpression("optOp1(3)", rule);
    result = tester.validate(model);
    result.assertOK();
    model = parseExpression("optOp1(true)", rule);
    result = tester.validate(model);
    result.assertError(ITypeSystemInferrer.NOT_COMPATIBLE_CODE);
}
Also used : AssertableDiagnostics(org.eclipse.xtext.junit4.validation.AssertableDiagnostics) EObject(org.eclipse.emf.ecore.EObject) Test(org.junit.Test)

Example 14 with AssertableDiagnostics

use of org.eclipse.xtext.junit4.validation.AssertableDiagnostics in project statecharts by Yakindu.

the class STextJavaValidatorTest method checkDeprecatedLocalEventDefinition.

@Test
public void checkDeprecatedLocalEventDefinition() {
    String decl = "internal: local event e1";
    EObject model = super.parseExpression(decl, InternalScope.class.getSimpleName());
    AssertableDiagnostics result = tester.validate(model);
    result.assertDiagnosticsCount(1);
    result.assertWarningContains(String.format(STextJavaValidator.DECLARATION_DEPRECATED, "local"));
}
Also used : AssertableDiagnostics(org.eclipse.xtext.junit4.validation.AssertableDiagnostics) EObject(org.eclipse.emf.ecore.EObject) InternalScope(org.yakindu.sct.model.stext.stext.InternalScope) Test(org.junit.Test)

Example 15 with AssertableDiagnostics

use of org.eclipse.xtext.junit4.validation.AssertableDiagnostics in project statecharts by Yakindu.

the class STextJavaValidatorTest method checkOperationArguments_TypedElementReferenceExpression.

/**
 * @see STextJavaValidator#checkOperationArguments_TypedElementReferenceExpression(TypedElementReferenceExpression)
 */
@Test
public void checkOperationArguments_TypedElementReferenceExpression() {
    String scope = "internal: operation myOperation(param1 : integer, param2: boolean)";
    EObject model = super.parseExpression("myOperation(5,true)", Expression.class.getSimpleName(), scope);
    AssertableDiagnostics validationResult = tester.validate(model);
    validationResult.assertOK();
}
Also used : AssertableDiagnostics(org.eclipse.xtext.junit4.validation.AssertableDiagnostics) Expression(org.yakindu.base.expressions.expressions.Expression) EObject(org.eclipse.emf.ecore.EObject) Test(org.junit.Test)

Aggregations

AssertableDiagnostics (org.eclipse.xtext.junit4.validation.AssertableDiagnostics)42 Test (org.junit.Test)42 EObject (org.eclipse.emf.ecore.EObject)38 AbstractSGenTest (org.yakindu.sct.generator.genmodel.test.util.AbstractSGenTest)11 GeneratorModel (org.yakindu.sct.model.sgen.GeneratorModel)11 InternalScope (org.yakindu.sct.model.stext.stext.InternalScope)7 Expression (org.yakindu.base.expressions.expressions.Expression)6 InterfaceScope (org.yakindu.sct.model.stext.stext.InterfaceScope)3 ReactionTrigger (org.yakindu.sct.model.stext.stext.ReactionTrigger)3 StatechartSpecification (org.yakindu.sct.model.stext.stext.StatechartSpecification)3 TransitionSpecification (org.yakindu.sct.model.stext.stext.TransitionSpecification)3 Scope (org.yakindu.sct.model.sgraph.Scope)2 ImportScope (org.yakindu.sct.model.stext.stext.ImportScope)2 ReactionEffect (org.yakindu.sct.model.stext.stext.ReactionEffect)2 Diagnostic (org.eclipse.emf.common.util.Diagnostic)1 Ignore (org.junit.Ignore)1