aboutsummaryrefslogtreecommitdiffstats
path: root/subprojects/language/src/test
diff options
context:
space:
mode:
authorLibravatar Kristóf Marussy <kristof@marussy.com>2024-01-31 17:10:28 +0100
committerLibravatar Kristóf Marussy <kristof@marussy.com>2024-01-31 18:45:13 +0100
commita2a92561f7b612b472b5b7e49a2d5ca86802092f (patch)
treeb5124c3936cfaba4d046cfc3f4676af5b940d19c /subprojects/language/src/test
parentrefactor(language): module and node declarations (diff)
downloadrefinery-a2a92561f7b612b472b5b7e49a2d5ca86802092f.tar.gz
refinery-a2a92561f7b612b472b5b7e49a2d5ca86802092f.tar.zst
refinery-a2a92561f7b612b472b5b7e49a2d5ca86802092f.zip
feat(language): validate module isolation
Diffstat (limited to 'subprojects/language/src/test')
-rw-r--r--subprojects/language/src/test/java/tools/refinery/language/tests/validation/AssertionValidationTest.java1
-rw-r--r--subprojects/language/src/test/java/tools/refinery/language/tests/validation/ModuleValidationTest.java145
2 files changed, 145 insertions, 1 deletions
diff --git a/subprojects/language/src/test/java/tools/refinery/language/tests/validation/AssertionValidationTest.java b/subprojects/language/src/test/java/tools/refinery/language/tests/validation/AssertionValidationTest.java
index 82dea31b..1fb08845 100644
--- a/subprojects/language/src/test/java/tools/refinery/language/tests/validation/AssertionValidationTest.java
+++ b/subprojects/language/src/test/java/tools/refinery/language/tests/validation/AssertionValidationTest.java
@@ -82,7 +82,6 @@ class AssertionValidationTest {
82 "exists(n).", 82 "exists(n).",
83 "?exists(n).", 83 "?exists(n).",
84 "!exists(n).", 84 "!exists(n).",
85 "exists(*).",
86 "?exists(*).", 85 "?exists(*).",
87 "exists(Foo::new).", 86 "exists(Foo::new).",
88 "?exists(Foo::new).", 87 "?exists(Foo::new).",
diff --git a/subprojects/language/src/test/java/tools/refinery/language/tests/validation/ModuleValidationTest.java b/subprojects/language/src/test/java/tools/refinery/language/tests/validation/ModuleValidationTest.java
new file mode 100644
index 00000000..00ad051b
--- /dev/null
+++ b/subprojects/language/src/test/java/tools/refinery/language/tests/validation/ModuleValidationTest.java
@@ -0,0 +1,145 @@
1/*
2 * SPDX-FileCopyrightText: 2024 The Refinery Authors <https://refinery.tools/>
3 *
4 * SPDX-License-Identifier: EPL-2.0
5 */
6package tools.refinery.language.tests.validation;
7
8import com.google.inject.Inject;
9import org.eclipse.xtext.testing.InjectWith;
10import org.eclipse.xtext.testing.extensions.InjectionExtension;
11import org.junit.jupiter.api.Test;
12import org.junit.jupiter.api.extension.ExtendWith;
13import org.junit.jupiter.params.ParameterizedTest;
14import org.junit.jupiter.params.provider.Arguments;
15import org.junit.jupiter.params.provider.MethodSource;
16import tools.refinery.language.model.tests.utils.ProblemParseHelper;
17import tools.refinery.language.tests.ProblemInjectorProvider;
18import tools.refinery.language.validation.ProblemValidator;
19
20import java.util.stream.Stream;
21
22import static org.hamcrest.MatcherAssert.assertThat;
23import static org.hamcrest.Matchers.*;
24
25@ExtendWith(InjectionExtension.class)
26@InjectWith(ProblemInjectorProvider.class)
27class ModuleValidationTest {
28 @Inject
29 private ProblemParseHelper parseHelper;
30
31 @ParameterizedTest
32 @MethodSource
33 void invalidMultiObjectExistsTest(String invalidDeclaration) {
34 var problem = parseHelper.parse("""
35 module.
36
37 %s
38 """.formatted(invalidDeclaration));
39 var issues = problem.validate();
40 assertThat(issues, hasItem(hasProperty("issueCode",
41 is(ProblemValidator.UNSUPPORTED_ASSERTION_ISSUE))));
42 }
43
44 static Stream<Arguments> invalidMultiObjectExistsTest() {
45 return Stream.of(
46 Arguments.of("""
47 class Foo.
48 exists(Foo::new).
49 """),
50 Arguments.of("""
51 multi m.
52 exists(m).
53 """));
54 }
55
56 @Test
57 void invalidScopeTest() {
58 var problem = parseHelper.parse("""
59 module.
60
61 class Foo.
62 scope Foo += 1.
63 """);
64 var issues = problem.validate();
65 assertThat(issues, hasItem(hasProperty("issueCode",
66 is(ProblemValidator.INVALID_MULTIPLICITY_ISSUE))));
67 }
68
69 @Test
70 void invalidAssertionArgumentTest() {
71 var problem = parseHelper.parse("""
72 module.
73
74 class Foo.
75 Foo(foo1).
76 """);
77 var issues = problem.validate();
78 assertThat(issues, hasItem(allOf(
79 hasProperty("issueCode", is(ProblemValidator.UNSUPPORTED_ASSERTION_ISSUE)),
80 hasProperty("message", containsString("foo1")))));
81 }
82
83 @ParameterizedTest
84 @MethodSource
85 void validDeclarationTest(String validDeclaration) {
86 var problem = parseHelper.parse(validDeclaration);
87 var issues = problem.validate();
88 assertThat(issues, hasSize(0));
89 }
90
91 static Stream<Arguments> validDeclarationTest() {
92 return Stream.concat(
93 invalidMultiObjectExistsTest(),
94 Stream.of(
95 Arguments.of("""
96 class Foo.
97 scope Foo += 1.
98 """),
99 Arguments.of("""
100 module.
101
102 class Foo.
103 scope Foo = 1.
104 """),
105 Arguments.of("""
106 class Foo.
107 Foo(foo1).
108 """),
109 Arguments.of("""
110 module.
111
112 class Foo.
113 multi foo1.
114 Foo(foo1).
115 """),
116 Arguments.of("""
117 module.
118
119 class Foo.
120 atom foo1.
121 Foo(foo1).
122 """),
123 Arguments.of("""
124 module.
125
126 class Foo.
127 declare foo1.
128 Foo(foo1).
129 """),
130 Arguments.of("""
131 module.
132
133 enum Foo { foo1 }
134 Foo(foo1).
135 """),
136 Arguments.of("""
137 module.
138
139 class Foo.
140 Foo(Foo::new).
141 """)
142 )
143 );
144 }
145}