aboutsummaryrefslogtreecommitdiffstats
path: root/subprojects/language/src/test/java/tools/refinery/language/tests/validation/AssertionValidationTest.java
blob: 82dea31b9845ee4ade4560506896193e2a7e07a1 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
/*
 * SPDX-FileCopyrightText: 2023 The Refinery Authors <https://refinery.tools/>
 *
 * SPDX-License-Identifier: EPL-2.0
 */
package tools.refinery.language.tests.validation;

import com.google.inject.Inject;
import org.eclipse.xtext.testing.InjectWith;
import org.eclipse.xtext.testing.extensions.InjectionExtension;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.extension.ExtendWith;
import org.junit.jupiter.params.ParameterizedTest;
import org.junit.jupiter.params.provider.ValueSource;
import tools.refinery.language.model.tests.utils.ProblemParseHelper;
import tools.refinery.language.tests.ProblemInjectorProvider;
import tools.refinery.language.validation.ProblemValidator;

import static org.hamcrest.MatcherAssert.assertThat;
import static org.hamcrest.Matchers.*;
import static org.hamcrest.Matchers.is;

@ExtendWith(InjectionExtension.class)
@InjectWith(ProblemInjectorProvider.class)
class AssertionValidationTest {
	@Inject
	private ProblemParseHelper parseHelper;

	@Test
	void invalidValueTest() {
		var problem = parseHelper.parse("""
				class Foo.

				Foo(n): 5.
				""");
		var issues = problem.validate();
		assertThat(issues, hasItem(hasProperty("issueCode",
				is(ProblemValidator.INVALID_VALUE_ISSUE))));
	}

	@ParameterizedTest
	@ValueSource(strings = {
			"default exists(n).",
			"!exists(A).",
			"exists(A): error.",
			"exists(n): error.",
			"!exists(*).",
			"exists(*): error.",
			"default equals(n, n).",
			"equals(n, m).",
			"?equals(n, m).",
			"equals(n, m): error.",
			"equals(A, B).",
			"?equals(A, B).",
			"equals(A, B): error.",
			"!equals(n, n).",
			"equals(n, n): error.",
			"!equals(A, A).",
			"equals(A, A): error.",
			"?equals(n, *).",
			"?equals(*, m).",
			"equals(*, *).",
			"!equals(*, *).",
			"?equals(*, *).",
			"equals(*, *): error."
	})
	void invalidMultiObjectTest(String assertion) {
		var problem = parseHelper.parse("""
				enum Bar { A, B }

				%s
				""".formatted(assertion));
		var issues = problem.validate();
		assertThat(issues, hasItem(hasProperty("issueCode",
				is(ProblemValidator.UNSUPPORTED_ASSERTION_ISSUE))));
	}

	@ParameterizedTest
	@ValueSource(strings = {
			"exists(A).",
			"?exists(A).",
			"exists(n).",
			"?exists(n).",
			"!exists(n).",
			"exists(*).",
			"?exists(*).",
			"exists(Foo::new).",
			"?exists(Foo::new).",
			"!exists(Foo::new).",
			"equals(A, A).",
			"?equals(A, A).",
			"!equals(A, B).",
			"equals(n, n).",
			"?equals(n, n).",
			"!equals(n, m).",
			"equals(Foo::new, Foo::new).",
			"?equals(Foo::new, Foo::new)."
	})
	void validMultiObjectTest(String assertion) {
		var problem = parseHelper.parse("""
				class Foo.

				enum Bar { A, B }

				%s
				""".formatted(assertion));
		var issues = problem.validate();
		assertThat(issues, not(hasItem(hasProperty("issueCode",
				is(ProblemValidator.UNSUPPORTED_ASSERTION_ISSUE)))));
	}
}