Search in sources :

Example 6 with AssertableDiagnostics

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

the class STextJavaValidatorTest method checkAssignmentExpression.

/**
 * @see STextJavaValidator#checkAssignmentExpression(org.yakindu.sct.model.stext.stext.AssignmentExpression)
 */
@Test
public void checkAssignmentExpression() {
    String context = "interface: var i : integer = 42 var j : integer =23";
    EObject expression = super.parseExpression("i += (i+=3) +4", Expression.class.getSimpleName(), context);
    AssertableDiagnostics validationResult = tester.validate(expression);
    validationResult.assertErrorContains(STextJavaValidator.ASSIGNMENT_EXPRESSION);
    expression = super.parseExpression("i += (j+=3) +4", Expression.class.getSimpleName(), context);
    validationResult = tester.validate(expression);
    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)

Example 7 with AssertableDiagnostics

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

the class STextJavaValidatorTest method checkReactionEffectActions.

/**
 * @see STextJavaValidator#checkReactionEffectActions(org.yakindu.sct.model.stext.stext.ReactionEffect)
 */
@Test
public void checkReactionEffectActions() {
    String s1 = "internal : var a : integer event e operation o () : void";
    String s2 = "interface if : var a : integer in event e operation o()";
    EObject model = super.parseExpression("a", ReactionEffect.class.getSimpleName(), s1);
    AssertableDiagnostics result = tester.validate(model);
    result.assertError(FEATURE_CALL_HAS_NO_EFFECT);
    model = super.parseExpression("1+3", ReactionEffect.class.getSimpleName(), s1);
    result = tester.validate(model);
    result.assertError(FEATURE_CALL_HAS_NO_EFFECT);
    model = super.parseExpression("valueof(e)", ReactionEffect.class.getSimpleName(), s1);
    result = tester.validate(model);
    result.assertError(FEATURE_CALL_HAS_NO_EFFECT);
    model = super.parseExpression("o()", ReactionEffect.class.getSimpleName(), s1);
    result = tester.validate(model);
    result.assertOK();
    model = super.parseExpression("if.a", ReactionEffect.class.getSimpleName(), s2);
    result = tester.validate(model);
    result.assertError(FEATURE_CALL_HAS_NO_EFFECT);
    model = super.parseExpression("valueof(if.e)", ReactionEffect.class.getSimpleName(), s2);
    result = tester.validate(model);
    result.assertError(FEATURE_CALL_HAS_NO_EFFECT);
    model = super.parseExpression("if.o", ReactionEffect.class.getSimpleName(), s2);
    result = tester.validate(model);
    result.assertOK();
}
Also used : AssertableDiagnostics(org.eclipse.xtext.junit4.validation.AssertableDiagnostics) EObject(org.eclipse.emf.ecore.EObject) ReactionEffect(org.yakindu.sct.model.stext.stext.ReactionEffect) Test(org.junit.Test)

Example 8 with AssertableDiagnostics

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

the class STextJavaValidatorTest method checkValueOfNoEvent.

@Test
public void checkValueOfNoEvent() {
    String decl = "interface: in event e1:integer var x:integer operation op():integer interface i: in event e2:integer var y:integer";
    EObject model = super.parseExpression("valueof(e1)", Expression.class.getSimpleName(), decl);
    AssertableDiagnostics result = tester.validate(model);
    result.assertOK();
    model = super.parseExpression("valueof(i.e2)", Expression.class.getSimpleName(), decl);
    result = tester.validate(model);
    result.assertOK();
    model = super.parseExpression("valueof(x)", Expression.class.getSimpleName(), decl);
    result = tester.validate(model);
    result.assertError(VALUE_OF_REQUIRES_EVENT);
    model = super.parseExpression("valueof(i.y)", Expression.class.getSimpleName(), decl);
    result = tester.validate(model);
    result.assertError(VALUE_OF_REQUIRES_EVENT);
    model = super.parseExpression("valueof(op())", Expression.class.getSimpleName(), decl);
    result = tester.validate(model);
    result.assertError(VALUE_OF_REQUIRES_EVENT);
}
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)

Example 9 with AssertableDiagnostics

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

the class STextJavaValidatorTest method testMultipleOptionalParameters.

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

Example 10 with AssertableDiagnostics

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

the class STextJavaValidatorTest method checkRaisingExpressionEvent.

@Test
public void checkRaisingExpressionEvent() {
    String scope = "interface : in event e  var x : integer  var y : integer  operation op():integer";
    EObject model = super.parseExpression("raise e", ReactionEffect.class.getSimpleName(), scope);
    AssertableDiagnostics validationResult = tester.validate(model);
    validationResult.assertOK();
    model = super.parseExpression("raise y", ReactionEffect.class.getSimpleName(), scope);
    validationResult = tester.validate(model);
    validationResult.assertAll(errorMsg("'y' is not an event."));
}
Also used : AssertableDiagnostics(org.eclipse.xtext.junit4.validation.AssertableDiagnostics) EObject(org.eclipse.emf.ecore.EObject) ReactionEffect(org.yakindu.sct.model.stext.stext.ReactionEffect) 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