diff options
author | Kristóf Marussy <kristof@marussy.com> | 2024-01-31 17:10:28 +0100 |
---|---|---|
committer | Kristóf Marussy <kristof@marussy.com> | 2024-01-31 18:45:13 +0100 |
commit | a2a92561f7b612b472b5b7e49a2d5ca86802092f (patch) | |
tree | b5124c3936cfaba4d046cfc3f4676af5b940d19c /subprojects/language/src/test | |
parent | refactor(language): module and node declarations (diff) | |
download | refinery-a2a92561f7b612b472b5b7e49a2d5ca86802092f.tar.gz refinery-a2a92561f7b612b472b5b7e49a2d5ca86802092f.tar.zst refinery-a2a92561f7b612b472b5b7e49a2d5ca86802092f.zip |
feat(language): validate module isolation
Diffstat (limited to 'subprojects/language/src/test')
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 | */ | ||
6 | package tools.refinery.language.tests.validation; | ||
7 | |||
8 | import com.google.inject.Inject; | ||
9 | import org.eclipse.xtext.testing.InjectWith; | ||
10 | import org.eclipse.xtext.testing.extensions.InjectionExtension; | ||
11 | import org.junit.jupiter.api.Test; | ||
12 | import org.junit.jupiter.api.extension.ExtendWith; | ||
13 | import org.junit.jupiter.params.ParameterizedTest; | ||
14 | import org.junit.jupiter.params.provider.Arguments; | ||
15 | import org.junit.jupiter.params.provider.MethodSource; | ||
16 | import tools.refinery.language.model.tests.utils.ProblemParseHelper; | ||
17 | import tools.refinery.language.tests.ProblemInjectorProvider; | ||
18 | import tools.refinery.language.validation.ProblemValidator; | ||
19 | |||
20 | import java.util.stream.Stream; | ||
21 | |||
22 | import static org.hamcrest.MatcherAssert.assertThat; | ||
23 | import static org.hamcrest.Matchers.*; | ||
24 | |||
25 | @ExtendWith(InjectionExtension.class) | ||
26 | @InjectWith(ProblemInjectorProvider.class) | ||
27 | class 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 | } | ||