|
@@ -284,18 +284,76 @@ public class STextJavaValidatorTest extends AbstractSTextTest {
|
|
|
*/
|
|
|
@Test
|
|
|
public void checkVariableDefinitionInitialValue() {
|
|
|
- // Success
|
|
|
- EObject model = super.parseExpression(
|
|
|
- "interface: var myBool : boolean = !true", null,
|
|
|
- StatechartSpecification.class.getSimpleName());
|
|
|
- AssertableDiagnostics result = tester.validate(model);
|
|
|
- result.assertDiagnosticsCount(0);
|
|
|
- // Fail
|
|
|
- model = super.parseExpression("interface: var myBool : boolean = 5",
|
|
|
- null, StatechartSpecification.class.getSimpleName());
|
|
|
- result = tester.validate(model);
|
|
|
+
|
|
|
+ // Success boolean
|
|
|
+ checkExpressionSuccess("interface: var myBool : boolean = !true");
|
|
|
+ // Success integer
|
|
|
+ checkExpressionSuccess("interface: var myInt : integer = 5");
|
|
|
+ // Success real
|
|
|
+ checkExpressionSuccess("interface: var myReal : real = 0.5");
|
|
|
+ // Success string
|
|
|
+ checkExpressionSuccess("interface: var myString : string = \"text\"");
|
|
|
+
|
|
|
+ String errorMsg = "Can not assign a value of type "
|
|
|
+ + "'%s' to a variable of type '%s'";
|
|
|
+
|
|
|
+ // Fail boolean 1
|
|
|
+ checkErrorMessageForExpression("interface: var myBool : boolean = 5",
|
|
|
+ String.format(errorMsg, "integer", "boolean"));
|
|
|
+ // Fail boolean 2
|
|
|
+ checkErrorMessageForExpression("interface: var myBool : boolean = 0.5",
|
|
|
+ String.format(errorMsg, "real", "boolean"));
|
|
|
+ // Fail boolean 3
|
|
|
+ checkErrorMessageForExpression(
|
|
|
+ "interface: var myBool : boolean = \"text\"",
|
|
|
+ String.format(errorMsg, "string", "boolean"));
|
|
|
+ // Fail integer 1
|
|
|
+ checkErrorMessageForExpression("interface: var myInt : integer = true",
|
|
|
+ String.format(errorMsg, "boolean", "integer"));
|
|
|
+ // Fail integer 2
|
|
|
+ checkErrorMessageForExpression("interface: var myInt : integer = 0.5",
|
|
|
+ String.format(errorMsg, "real", "integer"));
|
|
|
+ // Fail integer 3
|
|
|
+ checkErrorMessageForExpression(
|
|
|
+ "interface: var myInt : integer = \"text\"",
|
|
|
+ String.format(errorMsg, "string", "integer"));
|
|
|
+ // Fail real 1
|
|
|
+ checkErrorMessageForExpression("interface: var myReal : real = true",
|
|
|
+ String.format(errorMsg, "boolean", "real"));
|
|
|
+ // Fail real 2
|
|
|
+ checkErrorMessageForExpression(
|
|
|
+ "interface: var myReal : real = \"text\"",
|
|
|
+ String.format(errorMsg, "string", "real"));
|
|
|
+ // Fail String 1
|
|
|
+ checkErrorMessageForExpression("interface: var myString : string = 5",
|
|
|
+ String.format(errorMsg, "integer", "string"));
|
|
|
+ // Fail String 2
|
|
|
+ checkErrorMessageForExpression(
|
|
|
+ "interface: var myString : string = 0.5",
|
|
|
+ String.format(errorMsg, "real", "string"));
|
|
|
+ // Fail String 3
|
|
|
+ checkErrorMessageForExpression(
|
|
|
+ "interface: var myString : string = true",
|
|
|
+ String.format(errorMsg, "boolean", "string"));
|
|
|
+
|
|
|
+ }
|
|
|
+
|
|
|
+ private void checkErrorMessageForExpression(String expression,
|
|
|
+ String errorMessage) {
|
|
|
+ AssertableDiagnostics result = tester.validate(getModel(expression));
|
|
|
result.assertDiagnosticsCount(1);
|
|
|
- result.assertErrorContains("Can not assign a value of type 'integer' to a variable of type 'boolean'");
|
|
|
+ result.assertErrorContains(errorMessage);
|
|
|
+ }
|
|
|
+
|
|
|
+ private void checkExpressionSuccess(String expression) {
|
|
|
+
|
|
|
+ AssertableDiagnostics result = tester.validate(getModel(expression));
|
|
|
+ result.assertDiagnosticsCount(0);
|
|
|
+ }
|
|
|
+
|
|
|
+ private EObject getModel(String expression) {
|
|
|
+ return super.parseExpression(expression, null,
|
|
|
+ StatechartSpecification.class.getSimpleName());
|
|
|
}
|
|
|
|
|
|
/**
|