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

The following examples show how to use org.eclipse.xtext.junit4.validation.AssertableDiagnostics#assertErrorContains() . 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 checkNoAssignmentInGuard() {
	String scope = "internal: var myInt : integer var myBool : boolean = true";
	EObject expression = super.parseExpression("[myBool = false]", ReactionTrigger.class.getSimpleName(), scope);
	AssertableDiagnostics validationResult = tester.validate(expression);
	validationResult.assertErrorContains(STextValidator.GUARD_CONTAINS_ASSIGNMENT);
	expression = super.parseExpression("[myInt = 5]", ReactionTrigger.class.getSimpleName(), scope);
	validationResult = tester.validate(expression);
	Iterator<Diagnostic> diag = validationResult.getAllDiagnostics().iterator();
	while (diag.hasNext()) {
		Diagnostic d = diag.next();
		if (d.getMessage().equals(GUARD_EXPRESSION)) {
			assertEquals(STextValidator.GUARD_EXPRESSION, d.getMessage());
		} else {
			assertEquals(STextValidator.GUARD_CONTAINS_ASSIGNMENT, d.getMessage());
		}
	}
	expression = super.parseExpression("[myInt++ > 10]", ReactionTrigger.class.getSimpleName(), scope);
	validationResult = tester.validate(expression);
	validationResult.assertErrorContains(STextValidator.GUARD_CONTAINS_ASSIGNMENT);
}
 
Example 2
Source File: STextValidatorTest.java    From statecharts with Eclipse Public License 1.0 6 votes vote down vote up
/**
 * @see STextValidator#checkEventDefinition(org.yakindu.sct.model.stext.stext.EventDefinition)
 */
@Test
public void checkEventDefinition() {
	// No local declarations in interface scope
	EObject model = super.parseExpression("interface MyInterface: event Event1",
			InterfaceScope.class.getSimpleName());
	AssertableDiagnostics result = tester.validate(model);
	result.assertErrorContains(LOCAL_DECLARATIONS);
	// No in declarations in internal scope
	model = super.parseExpression("internal: in event Event1", InternalScope.class.getSimpleName());
	result = tester.validate(model);
	result.assertDiagnosticsCount(1);
	result.assertErrorContains(STextValidator.IN_OUT_DECLARATIONS);
	// No out declarations in internal scope
	model = super.parseExpression("internal: out event Event1", InternalScope.class.getSimpleName());
	result = tester.validate(model);
	result.assertDiagnosticsCount(1);
	result.assertErrorContains(IN_OUT_DECLARATIONS);
}
 
Example 3
Source File: STextValidatorTest.java    From statecharts with Eclipse Public License 1.0 5 votes vote down vote up
/**
 * @see STextValidator#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);
}
 
Example 4
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 5
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 6
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 7
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 8
Source File: STextValidatorTest.java    From statecharts with Eclipse Public License 1.0 4 votes vote down vote up
@Test
public void checkTimeEventSpecValueExpression() {
	EObject expression = super.parseExpression("after true s", ReactionTrigger.class.getSimpleName());
	AssertableDiagnostics validationResult = tester.validate(expression);
	validationResult.assertErrorContains(STextValidator.TIME_EXPRESSION);
}
 
Example 9
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);
	
}