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);
}
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);
}
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);
}
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();
}
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"));
}
Aggregations