Search in sources :

Example 26 with AssertableDiagnostics

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

the class STextJavaValidatorTest method checkExternalValueDefinitionExpression.

@Test
public void checkExternalValueDefinitionExpression() {
    String decl = "internal: var external v1:integer";
    EObject model = super.parseExpression(decl, InternalScope.class.getSimpleName());
    AssertableDiagnostics result = tester.validate(model);
    result.assertDiagnosticsCount(1);
    result.assertWarningContains(String.format(STextJavaValidator.DECLARATION_DEPRECATED, "external"));
}
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 27 with AssertableDiagnostics

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

the class STextJavaValidatorTest method checkOperationNamedParameters.

@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);
}
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 28 with AssertableDiagnostics

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

the class STextJavaValidatorTest method checkImportExists.

@Test
public void checkImportExists() {
    Scope context = (Scope) parseExpression("import: \"does.not.exist\"", ImportScope.class.getSimpleName());
    AssertableDiagnostics validationResult = tester.validate(context);
    validationResult.assertErrorContains(String.format(STextValidationMessages.IMPORT_NOT_RESOLVED_MSG, "does.not.exist"));
}
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 29 with AssertableDiagnostics

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

the class STextJavaValidatorTest method testMixedOptionalParameters.

@Test
public void testMixedOptionalParameters() {
    EObject model;
    String rule = Expression.class.getSimpleName();
    AssertableDiagnostics result;
    model = parseExpression("optOp3(3)", rule);
    result = tester.validate(model);
    result.assertOK();
    model = parseExpression("optOp3(3, 4)", rule);
    result = tester.validate(model);
    result.assertOK();
    model = parseExpression("optOp3(3, 4, true)", rule);
    result = tester.validate(model);
    result.assertError(ERROR_WRONG_NUMBER_OF_ARGUMENTS_CODE);
    model = parseExpression("optOp3()", rule);
    result = tester.validate(model);
    result.assertError(ERROR_WRONG_NUMBER_OF_ARGUMENTS_CODE);
    model = parseExpression("optOp3(3, true)", rule);
    result = tester.validate(model);
    result.assertError(ITypeSystemInferrer.NOT_COMPATIBLE_CODE);
}
Also used : AssertableDiagnostics(org.eclipse.xtext.junit4.validation.AssertableDiagnostics) EObject(org.eclipse.emf.ecore.EObject) Test(org.junit.Test)

Example 30 with AssertableDiagnostics

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

the class SGenJavaValidatorTest method checkDeprecatedParameters.

/**
 * @see SGenJavaValidator#checkDeprecatedParameters(GeneratorEntry)
 */
@Test
public void checkDeprecatedParameters() {
    EObject model = parseExpression("GeneratorModel for yakindu::java { statechart Example { feature Outlet {targetFolder = \"src-gen\"  targetProject = \"TestProject\" }}}", GeneratorModel.class.getSimpleName());
    if (!(model instanceof GeneratorModel)) {
        fail("Model is of the wrong type");
    } else {
        GeneratorModel genModel = (GeneratorModel) model;
        genModel.getEntries().get(0).getFeatures().get(0).getType().getParameters().get(0).setDeprecated(true);
        AssertableDiagnostics result = tester.validate(genModel);
        result.assertAny(new MsgPredicate(DEPRECATED));
    }
}
Also used : AssertableDiagnostics(org.eclipse.xtext.junit4.validation.AssertableDiagnostics) EObject(org.eclipse.emf.ecore.EObject) GeneratorModel(org.yakindu.sct.model.sgen.GeneratorModel) AbstractSGenTest(org.yakindu.sct.generator.genmodel.test.util.AbstractSGenTest) 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