diff options
author | 2023-11-19 14:33:58 +0100 | |
---|---|---|
committer | 2023-11-19 14:41:17 +0100 | |
commit | add263cb783ba164c6353482690b53ec8743a648 (patch) | |
tree | 0a842960e27ad25d458c18f7bd9f8b4bf5b89b6c /subprojects/language/src/test | |
parent | feat(language): arity validation (diff) | |
download | refinery-add263cb783ba164c6353482690b53ec8743a648.tar.gz refinery-add263cb783ba164c6353482690b53ec8743a648.tar.zst refinery-add263cb783ba164c6353482690b53ec8743a648.zip |
feat(langauge): validate exists and equals
Diffstat (limited to 'subprojects/language/src/test')
-rw-r--r-- | subprojects/language/src/test/java/tools/refinery/language/tests/validation/AssertionValidationTest.java | 111 |
1 files changed, 111 insertions, 0 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 new file mode 100644 index 00000000..82dea31b --- /dev/null +++ b/subprojects/language/src/test/java/tools/refinery/language/tests/validation/AssertionValidationTest.java | |||
@@ -0,0 +1,111 @@ | |||
1 | /* | ||
2 | * SPDX-FileCopyrightText: 2023 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.ValueSource; | ||
15 | import tools.refinery.language.model.tests.utils.ProblemParseHelper; | ||
16 | import tools.refinery.language.tests.ProblemInjectorProvider; | ||
17 | import tools.refinery.language.validation.ProblemValidator; | ||
18 | |||
19 | import static org.hamcrest.MatcherAssert.assertThat; | ||
20 | import static org.hamcrest.Matchers.*; | ||
21 | import static org.hamcrest.Matchers.is; | ||
22 | |||
23 | @ExtendWith(InjectionExtension.class) | ||
24 | @InjectWith(ProblemInjectorProvider.class) | ||
25 | class AssertionValidationTest { | ||
26 | @Inject | ||
27 | private ProblemParseHelper parseHelper; | ||
28 | |||
29 | @Test | ||
30 | void invalidValueTest() { | ||
31 | var problem = parseHelper.parse(""" | ||
32 | class Foo. | ||
33 | |||
34 | Foo(n): 5. | ||
35 | """); | ||
36 | var issues = problem.validate(); | ||
37 | assertThat(issues, hasItem(hasProperty("issueCode", | ||
38 | is(ProblemValidator.INVALID_VALUE_ISSUE)))); | ||
39 | } | ||
40 | |||
41 | @ParameterizedTest | ||
42 | @ValueSource(strings = { | ||
43 | "default exists(n).", | ||
44 | "!exists(A).", | ||
45 | "exists(A): error.", | ||
46 | "exists(n): error.", | ||
47 | "!exists(*).", | ||
48 | "exists(*): error.", | ||
49 | "default equals(n, n).", | ||
50 | "equals(n, m).", | ||
51 | "?equals(n, m).", | ||
52 | "equals(n, m): error.", | ||
53 | "equals(A, B).", | ||
54 | "?equals(A, B).", | ||
55 | "equals(A, B): error.", | ||
56 | "!equals(n, n).", | ||
57 | "equals(n, n): error.", | ||
58 | "!equals(A, A).", | ||
59 | "equals(A, A): error.", | ||
60 | "?equals(n, *).", | ||
61 | "?equals(*, m).", | ||
62 | "equals(*, *).", | ||
63 | "!equals(*, *).", | ||
64 | "?equals(*, *).", | ||
65 | "equals(*, *): error." | ||
66 | }) | ||
67 | void invalidMultiObjectTest(String assertion) { | ||
68 | var problem = parseHelper.parse(""" | ||
69 | enum Bar { A, B } | ||
70 | |||
71 | %s | ||
72 | """.formatted(assertion)); | ||
73 | var issues = problem.validate(); | ||
74 | assertThat(issues, hasItem(hasProperty("issueCode", | ||
75 | is(ProblemValidator.UNSUPPORTED_ASSERTION_ISSUE)))); | ||
76 | } | ||
77 | |||
78 | @ParameterizedTest | ||
79 | @ValueSource(strings = { | ||
80 | "exists(A).", | ||
81 | "?exists(A).", | ||
82 | "exists(n).", | ||
83 | "?exists(n).", | ||
84 | "!exists(n).", | ||
85 | "exists(*).", | ||
86 | "?exists(*).", | ||
87 | "exists(Foo::new).", | ||
88 | "?exists(Foo::new).", | ||
89 | "!exists(Foo::new).", | ||
90 | "equals(A, A).", | ||
91 | "?equals(A, A).", | ||
92 | "!equals(A, B).", | ||
93 | "equals(n, n).", | ||
94 | "?equals(n, n).", | ||
95 | "!equals(n, m).", | ||
96 | "equals(Foo::new, Foo::new).", | ||
97 | "?equals(Foo::new, Foo::new)." | ||
98 | }) | ||
99 | void validMultiObjectTest(String assertion) { | ||
100 | var problem = parseHelper.parse(""" | ||
101 | class Foo. | ||
102 | |||
103 | enum Bar { A, B } | ||
104 | |||
105 | %s | ||
106 | """.formatted(assertion)); | ||
107 | var issues = problem.validate(); | ||
108 | assertThat(issues, not(hasItem(hasProperty("issueCode", | ||
109 | is(ProblemValidator.UNSUPPORTED_ASSERTION_ISSUE))))); | ||
110 | } | ||
111 | } | ||