Search in sources :

Example 1 with Visibility

use of org.lflang.lf.Visibility in project lingua-franca by lf-lang.

the class LinguaFrancaValidationTest method testPreambleVisibility.

/**
 * Test warnings and errors for the target dependent preamble visibility qualifiers
 */
@Test
public void testPreambleVisibility() throws Exception {
    for (Target target : Target.values()) {
        for (Visibility visibility : Visibility.values()) {
            // Java 17:
            // Model model_reactor_scope = """
            // target %s;
            // reactor Foo {
            // %spreamble {==}
            // }
            // """.formatted(target, visibility != java.beans.Visibility.NONE ? visibility + " " : "");
            // Java 11:
            Model model_reactor_scope = parseWithoutError(String.join(System.getProperty("line.separator"), String.format("target %s;", target), "reactor Foo {", String.format("    %spreamble {==}", visibility != Visibility.NONE ? visibility + " " : ""), "}"));
            // Java 17:
            // Model model_file_scope = """
            // target %s;
            // %spreamble {==}
            // reactor Foo {
            // }
            // """.formatted(target, visibility != java.beans.Visibility.NONE ? visibility + " " : "");
            // Java 11:
            Model model_file_scope = parseWithoutError(String.join(System.getProperty("line.separator"), String.format("target %s;", target), String.format("    %spreamble {==}", visibility != Visibility.NONE ? visibility + " " : ""), "reactor Foo {", "}"));
            // Java 17:
            // Model model_no_preamble = """
            // target %s;
            // reactor Foo {
            // }
            // """.formatted(target);
            // Java 11:
            Model model_no_preamble = parseWithoutError(String.join(System.getProperty("line.separator"), String.format("target %s;", target), "reactor Foo {", "}"));
            validator.assertNoIssues(model_no_preamble);
            if (target == Target.CPP) {
                if (visibility == Visibility.NONE) {
                    validator.assertError(model_file_scope, LfPackage.eINSTANCE.getPreamble(), null, "Preambles for the C++ target need a visibility qualifier (private or public)!");
                    validator.assertError(model_reactor_scope, LfPackage.eINSTANCE.getPreamble(), null, "Preambles for the C++ target need a visibility qualifier (private or public)!");
                } else {
                    validator.assertNoIssues(model_file_scope);
                    validator.assertNoIssues(model_reactor_scope);
                }
            } else {
                if (visibility == Visibility.NONE) {
                    validator.assertNoIssues(model_file_scope);
                    validator.assertNoIssues(model_reactor_scope);
                } else {
                    validator.assertWarning(model_file_scope, LfPackage.eINSTANCE.getPreamble(), null, String.format("The %s qualifier has no meaning for the %s target. It should be removed.", visibility, target.name()));
                    validator.assertWarning(model_reactor_scope, LfPackage.eINSTANCE.getPreamble(), null, String.format("The %s qualifier has no meaning for the %s target. It should be removed.", visibility, target.name()));
                }
            }
        }
    }
}
Also used : Target(org.lflang.Target) Model(org.lflang.lf.Model) Visibility(org.lflang.lf.Visibility) Test(org.junit.jupiter.api.Test)

Aggregations

Test (org.junit.jupiter.api.Test)1 Target (org.lflang.Target)1 Model (org.lflang.lf.Model)1 Visibility (org.lflang.lf.Visibility)1