Java Code Examples for org.eclipse.xtext.junit4.validation.AssertableDiagnostics#assertOK()

The following examples show how to use org.eclipse.xtext.junit4.validation.AssertableDiagnostics#assertOK() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: STextValidatorTest.java    From statecharts with Eclipse Public License 1.0 6 votes vote down vote up
@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);
}
 
Example 2
Source File: STextValidatorTest.java    From statecharts with Eclipse Public License 1.0 6 votes vote down vote up
@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);
	
}
 
Example 3
Source File: STextValidatorTest.java    From statecharts with Eclipse Public License 1.0 6 votes vote down vote up
@Test
public void checkReactionTriggerRegularEvent() {
	
	String scope = "interface : in event e  var x : integer  var y : integer  operation op():integer";
	
	EObject model = super.parseExpression("e", TransitionSpecification.class.getSimpleName(), scope);
	AssertableDiagnostics validationResult = tester.validate(model);
	validationResult.assertOK();
	
	model = super.parseExpression("x", TransitionSpecification.class.getSimpleName(), scope);
	validationResult = tester.validate(model);
	validationResult.assertError(TRIGGER_IS_NO_EVENT);
	
	model = super.parseExpression("e, x", TransitionSpecification.class.getSimpleName(), scope);
	validationResult = tester.validate(model);
	validationResult.assertError(TRIGGER_IS_NO_EVENT);
	
	model = super.parseExpression("op()", TransitionSpecification.class.getSimpleName(), scope);
	validationResult = tester.validate(model);
	validationResult.assertError(TRIGGER_IS_NO_EVENT);
	
	model = super.parseExpression("x, y", TransitionSpecification.class.getSimpleName(), scope);
	validationResult = tester.validate(model);
	validationResult.assertAll(errorMsg("Trigger 'x' is no event."), errorMsg("Trigger 'y' is no event."));
	
}
 
Example 4
Source File: STextValidatorTest.java    From statecharts with Eclipse Public License 1.0 6 votes vote down vote up
/**
 *
 * @see STextValidator#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();
}
 
Example 5
Source File: STextValidatorTest.java    From statecharts with Eclipse Public License 1.0 5 votes vote down vote up
@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(ExpressionsValidator.POSTFIX_ONLY_ON_VARIABLES_CODE);
}
 
Example 6
Source File: STextValidatorTest.java    From statecharts with Eclipse Public License 1.0 5 votes vote down vote up
@Test
@Ignore("Why should anyone do that anyways")
public void testMixedOptionalAndVarArgsParameters() {
	EObject model;
	String rule = Expression.class.getSimpleName();
	AssertableDiagnostics result;
	
	model = parseExpression("optOp4(3)", rule);
	result = tester.validate(model);
	result.assertOK();
	
	model = parseExpression("optOp4(3, 4)", rule);
	result = tester.validate(model);
	result.assertOK();
	
	model = parseExpression("optOp4(3, 4, 5, 6)", rule);
	result = tester.validate(model);
	result.assertOK();
	
	model = parseExpression("optOp4(3, 4, true)", rule);
	result = tester.validate(model);
	result.assertOK();
	
	model = parseExpression("optOp4(true)", rule);
	result = tester.validate(model);
	result.assertError(ITypeSystemInferrer.NOT_COMPATIBLE_CODE);
}
 
Example 7
Source File: STextValidatorTest.java    From statecharts with Eclipse Public License 1.0 5 votes vote down vote up
@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));
}
 
Example 8
Source File: STextValidatorTest.java    From statecharts with Eclipse Public License 1.0 5 votes vote down vote up
/**
 * @see STextValidator#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();
	
}
 
Example 9
Source File: STextValidatorTest.java    From statecharts with Eclipse Public License 1.0 5 votes vote down vote up
@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."));
}
 
Example 10
Source File: STextValidatorTest.java    From statecharts with Eclipse Public License 1.0 5 votes vote down vote up
/**
 *
 * @see STextValidator#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(STextValidator.ASSIGNMENT_EXPRESSION);
	expression = super.parseExpression("i += (j+=3) +4", Expression.class.getSimpleName(), context);
	validationResult = tester.validate(expression);
	validationResult.assertOK();
}
 
Example 11
Source File: STextValidatorTest.java    From statecharts with Eclipse Public License 1.0 5 votes vote down vote up
/**
 * @see STextValidator#checkFeatureCall(org.yakindu.sct.model.stext.stext.FeatureCall)
 * @see STextValidator#checkFeatureCall(TypedElementReferenceExpression)
 */
@Test
public void checkFeatureCall() {
	String scope = "interface if : in event a : integer";
	EObject model = super.parseExpression("if.a / raise if.a:1", TransitionSpecification.class.getSimpleName(),
			scope);
	AssertableDiagnostics validationResult = tester.validate(model);
	validationResult.assertOK();
}
 
Example 12
Source File: STextValidatorTest.java    From statecharts with Eclipse Public License 1.0 5 votes vote down vote up
/**
 * @see STextValidator#checkGuardHasBooleanExpression(org.yakindu.sct.model.stext.stext.ReactionTrigger)
 */
@Test
public void checkGuard() {
	EObject expression = super.parseExpression("[3 * 3]", ReactionTrigger.class.getSimpleName());
	AssertableDiagnostics validationResult = tester.validate(expression);
	validationResult.assertErrorContains(STextValidator.GUARD_EXPRESSION);
	String scope = "internal: var myInt : integer var myBool : boolean = true";
	expression = super.parseExpression("[myInt <= 5 || !myBool ]", ReactionTrigger.class.getSimpleName(), scope);
	validationResult = tester.validate(expression);
	validationResult.assertOK();
}
 
Example 13
Source File: STextValidatorTest.java    From statecharts with Eclipse Public License 1.0 5 votes vote down vote up
@Test
public void checkAnnotations() {
	String scope;
	StatechartSpecification model;
	AssertableDiagnostics validationResult;
	
	scope = "@EventDriven";
	model = (StatechartSpecification) super.parseExpression(scope, StatechartSpecification.class.getSimpleName());
	validationResult = tester.validate(model);
	validationResult.assertOK();
	
	scope = "@CycleBased(200)";
	model = (StatechartSpecification) super.parseExpression(scope, StatechartSpecification.class.getSimpleName());
	validationResult = tester.validate(model);
	validationResult.assertOK();
	
	scope = "@CycleBased(200)\n" + "@EventDriven";
	model = (StatechartSpecification) super.parseExpression(scope, StatechartSpecification.class.getSimpleName());
	validationResult = tester.validate(model);
	validationResult.assertErrorContains(CONTRADICTORY_ANNOTATIONS.split("%s")[0]);
	
	scope = "@ParentFirstExecution";
	model = (StatechartSpecification) super.parseExpression(scope, StatechartSpecification.class.getSimpleName());
	validationResult = tester.validate(model);
	validationResult.assertOK();
	
	scope = "@ChildFirstExecution";
	model = (StatechartSpecification) super.parseExpression(scope, StatechartSpecification.class.getSimpleName());
	validationResult = tester.validate(model);
	validationResult.assertOK();
	
	scope = "@ParentFirstExecution\n" + "@ChildFirstExecution";
	model = (StatechartSpecification) super.parseExpression(scope, StatechartSpecification.class.getSimpleName());
	validationResult = tester.validate(model);
	validationResult.assertErrorContains(CONTRADICTORY_ANNOTATIONS.split("%s")[0]);
}
 
Example 14
Source File: STextValidatorTest.java    From statecharts with Eclipse Public License 1.0 5 votes vote down vote up
/**
 * @see STextValidator#checkAnnotationArguments(org.yakindu.sct.model.stext.stext.AnnotationDefinition)
 */
@Test
public void checkAnnotationArguments() {
	String scope = "@CycleBased";
	EObject model = super.parseExpression(scope, StatechartSpecification.class.getSimpleName());
	AssertableDiagnostics validationResult = tester.validate(model);
	validationResult.assertError(STextValidator.ERROR_WRONG_NUMBER_OF_ARGUMENTS_CODE);
	;
	
	scope = "@EventDriven";
	model = super.parseExpression(scope, StatechartSpecification.class.getSimpleName());
	validationResult = tester.validate(model);
	validationResult.assertOK();
}
 
Example 15
Source File: STextValidatorTest.java    From statecharts with Eclipse Public License 1.0 5 votes vote down vote up
@Test
public void checkOperationNamedParameters() {
	String scope = "internal: operation myOperation(param1 : integer, param2 : boolean)";
	EObject model = super.parseExpression(scope, InternalScope.class.getSimpleName());
	AssertableDiagnostics validationResult = tester.validate(model);
	validationResult.assertOK();
	
	model = super.parseExpression("myOperation(5, true)", Expression.class.getSimpleName(), scope);
	validationResult = tester.validate(model);
	validationResult.assertOK();
	model = super.parseExpression("myOperation(5, param2 = true)", Expression.class.getSimpleName(), scope);
	validationResult = tester.validate(model);
	validationResult.assertOK();
	model = super.parseExpression("myOperation(param1 = 5, true)", Expression.class.getSimpleName(), scope);
	validationResult = tester.validate(model);
	validationResult.assertOK();
	model = super.parseExpression("myOperation(param1 = 5, param2 = true)", Expression.class.getSimpleName(),
			scope);
	validationResult = tester.validate(model);
	validationResult.assertOK();
	model = super.parseExpression("myOperation(param2 = true, param1 = 5)", Expression.class.getSimpleName(),
			scope);
	validationResult = tester.validate(model);
	validationResult.assertOK();
	
	model = super.parseExpression("myOperation(param2 = true)", Expression.class.getSimpleName(), scope);
	validationResult = tester.validate(model);
	validationResult.assertError(ERROR_WRONG_NUMBER_OF_ARGUMENTS_CODE);
	
	model = super.parseExpression("myOperation(param1 = 5)", Expression.class.getSimpleName(), scope);
	validationResult = tester.validate(model);
	validationResult.assertError(ERROR_WRONG_NUMBER_OF_ARGUMENTS_CODE);
	
}
 
Example 16
Source File: STextValidatorTest.java    From statecharts with Eclipse Public License 1.0 5 votes vote down vote up
/**
 * @see STextValidator#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();
}
 
Example 17
Source File: STextValidatorTest.java    From statecharts with Eclipse Public License 1.0 5 votes vote down vote up
/**
 * @see STextValidator#checkOperationArguments_FeatureCall(org.yakindu.sct.model.stext.stext.FeatureCall)
 */
@Test
public void checkOperationArguments_FeatureCall() {
	String scope = "interface if : operation myOperation(param1 : integer, param2: boolean";
	EObject model = super.parseExpression("if.myOperation(5,true)", Expression.class.getSimpleName(), scope);
	AssertableDiagnostics validationResult = tester.validate(model);
	validationResult.assertOK();
}
 
Example 18
Source File: STextValidatorTest.java    From statecharts with Eclipse Public License 1.0 5 votes vote down vote up
@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();
	
}
 
Example 19
Source File: STextValidatorTest.java    From statecharts with Eclipse Public License 1.0 4 votes vote down vote up
/**
 * @see STextValidator#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);
	
}
 
Example 20
Source File: STextValidatorTest.java    From statecharts with Eclipse Public License 1.0 4 votes vote down vote up
@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"));
}