Search in sources :

Example 21 with AssertableDiagnostics

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

the class STextJavaValidatorTest method checkVariableDefinition.

/**
 * @see STextJavaValidator#checkVariableDefinition(org.yakindu.sct.model.stext.stext.VariableDefinition)
 */
@Test
public void checkVariableDefinition() {
    Scope context = (Scope) parseExpression("interface if : var i : void", InterfaceScope.class.getSimpleName());
    AssertableDiagnostics validationResult = tester.validate(context);
    validationResult.assertErrorContains(STextTypeInferrer.VARIABLE_VOID_TYPE);
}
Also used : AssertableDiagnostics(org.eclipse.xtext.junit4.validation.AssertableDiagnostics) Scope(org.yakindu.sct.model.sgraph.Scope) InternalScope(org.yakindu.sct.model.stext.stext.InternalScope) ImportScope(org.yakindu.sct.model.stext.stext.ImportScope) InterfaceScope(org.yakindu.sct.model.stext.stext.InterfaceScope) Test(org.junit.Test)

Example 22 with AssertableDiagnostics

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

the class STextJavaValidatorTest method checkVarArgParameterIsLast.

/**
 * @see STextJavaValidator#checkVarArgParameterIsLast(Operation)
 */
@Test
public void checkVarArgParameterIsLast() {
    String scope = "internal: operation myOperation(param1... : integer)" + "operation myOperation2(param0 : string, param1 ... : integer)";
    EObject model = super.parseExpression(scope, InternalScope.class.getSimpleName());
    AssertableDiagnostics validationResult = tester.validate(model);
    validationResult.assertOK();
    model = super.parseExpression("myOperation()", Expression.class.getSimpleName(), scope);
    validationResult = tester.validate(model);
    validationResult.assertOK();
    model = super.parseExpression("myOperation(5)", Expression.class.getSimpleName(), scope);
    validationResult = tester.validate(model);
    validationResult.assertOK();
    model = super.parseExpression("myOperation(5,5,5)", Expression.class.getSimpleName(), scope);
    validationResult = tester.validate(model);
    validationResult.assertOK();
    model = super.parseExpression("myOperation2('')", Expression.class.getSimpleName(), scope);
    validationResult = tester.validate(model);
    validationResult.assertOK();
    model = super.parseExpression("myOperation2('',5)", Expression.class.getSimpleName(), scope);
    validationResult = tester.validate(model);
    validationResult.assertOK();
    model = super.parseExpression("myOperation2('',5,5,5)", Expression.class.getSimpleName(), scope);
    validationResult = tester.validate(model);
    validationResult.assertOK();
    model = super.parseExpression("myOperation2('','')", Expression.class.getSimpleName(), scope);
    validationResult = tester.validate(model);
    validationResult.assertErrorContains("Incompatible types string and integer.");
    scope = "internal: operation myOperation(param1... : integer, param2...: integer)";
    model = super.parseExpression(scope, InternalScope.class.getSimpleName());
    validationResult = tester.validate(model);
    validationResult.assertError(ERROR_VAR_ARGS_LAST_CODE);
    scope = "internal: operation myOperation2(param1 ... : integer, param0 : string)";
    model = super.parseExpression(scope, InternalScope.class.getSimpleName());
    validationResult = tester.validate(model);
    validationResult.assertError(ERROR_VAR_ARGS_LAST_CODE);
}
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 23 with AssertableDiagnostics

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

the class STextJavaValidatorTest method checkPostFixOperatorOnlyOnVariables.

@Test
public void checkPostFixOperatorOnlyOnVariables() {
    EObject model = super.parseExpression("ABC.intVar++", Expression.class.getSimpleName(), interfaceScope());
    AssertableDiagnostics validationResult = tester.validate(model);
    validationResult.assertOK();
    model = super.parseExpression("intVar++", Expression.class.getSimpleName(), internalScope());
    validationResult = tester.validate(model);
    validationResult.assertOK();
    model = super.parseExpression("5++", Expression.class.getSimpleName(), interfaceScope());
    validationResult = tester.validate(model);
    validationResult.assertError(ExpressionsJavaValidator.POSTFIX_ONLY_ON_VARIABLES_CODE);
}
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 24 with AssertableDiagnostics

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

the class STextJavaValidatorTest method checkLeftHandAssignment.

@Test
public void checkLeftHandAssignment() {
    String scope = "interface if : operation myOperation() : boolean event Event1 : boolean var myVar : boolean";
    EObject model = super.parseExpression("3 = 3", Expression.class.getSimpleName(), scope);
    AssertableDiagnostics validationResult = tester.validate(model);
    validationResult.assertErrorContains(ERROR_LEFT_HAND_ASSIGNMENT_MSG);
    // Check for referenced elements in interface
    model = super.parseExpression("if.myOperation() = true", Expression.class.getSimpleName(), scope);
    validationResult = tester.validate(model);
    validationResult.assertErrorContains(ERROR_LEFT_HAND_ASSIGNMENT_MSG);
    model = super.parseExpression("if.Event1 = true", Expression.class.getSimpleName(), scope);
    validationResult = tester.validate(model);
    validationResult.assertErrorContains(ERROR_LEFT_HAND_ASSIGNMENT_MSG);
    model = super.parseExpression("if.myVar = true", Expression.class.getSimpleName(), scope);
    validationResult = tester.validate(model);
    validationResult.assertOK();
    // check for internal referenced elements
    scope = "internal : operation myOperation() : integer event Event1 : integer var myVar : integer";
    model = super.parseExpression("myOperation() = 5", Expression.class.getSimpleName(), scope);
    validationResult = tester.validate(model);
    validationResult.assertErrorContains(ERROR_LEFT_HAND_ASSIGNMENT_MSG);
    model = super.parseExpression("Event1 = true", Expression.class.getSimpleName(), scope);
    validationResult = tester.validate(model);
    validationResult.assertErrorContains(ERROR_LEFT_HAND_ASSIGNMENT_MSG);
    model = super.parseExpression("myVar = 5", Expression.class.getSimpleName(), scope);
    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)

Example 25 with AssertableDiagnostics

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

the class STextJavaValidatorTest method testDuplicateNames.

@Test
public void testDuplicateNames() {
    EObject model;
    AssertableDiagnostics result;
    String scope;
    scope = "interface: var x: integer var x: integer";
    model = super.parseExpression(scope, StatechartSpecification.class.getSimpleName());
    result = tester.validate(model);
    result.assertAll(errorMsg("Duplicate"), errorMsg("Duplicate"));
    scope = "interface: var x: integer internal: var x: integer";
    model = super.parseExpression(scope, StatechartSpecification.class.getSimpleName());
    result = tester.validate(model);
    result.assertAll(errorMsg("Duplicate"), errorMsg("Duplicate"));
    scope = "interface: var x: integer interface d: var x: integer";
    model = super.parseExpression(scope, StatechartSpecification.class.getSimpleName());
    result = tester.validate(model);
    result.assertOK();
    scope = "interface: var x: integer interface x: var d: integer";
    model = super.parseExpression(scope, StatechartSpecification.class.getSimpleName());
    result = tester.validate(model);
    result.assertAll(errorMsg("Duplicate"), errorMsg("Duplicate"));
    scope = "interface: var x: integer var X: integer";
    model = super.parseExpression(scope, StatechartSpecification.class.getSimpleName());
    result = tester.validate(model);
    result.assertAll(warningMsg("Duplicate"), warningMsg("Duplicate"));
    scope = "interface: var x: integer interface X: var d: integer";
    model = super.parseExpression(scope, StatechartSpecification.class.getSimpleName());
    result = tester.validate(model);
    result.assertOK();
    scope = "interface: " + "var X: integer " + "var x: integer " + "" + "var d: integer " + " " + "interface D: " + "var x: integer " + " " + "interface x: " + "var i: integer";
    model = super.parseExpression(scope, StatechartSpecification.class.getSimpleName());
    result = tester.validate(model);
    result.assertAll(warningMsg("Duplicate"), warningMsg("Duplicate"), errorMsg("Duplicate"), errorMsg("Duplicate"));
}
Also used : AssertableDiagnostics(org.eclipse.xtext.junit4.validation.AssertableDiagnostics) 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