aboutsummaryrefslogtreecommitdiffstats
path: root/subprojects/language/src/test/java/tools/refinery/language/tests/ProblemParsingTest.java
blob: 17ae5fbb4a7303ede27c1b3f3f6d3fa892d47220 (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
/*
 * SPDX-FileCopyrightText: 2021-2023 The Refinery Authors <https://refinery.tools/>
 *
 * SPDX-License-Identifier: EPL-2.0
 */
package tools.refinery.language.tests;

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 tools.refinery.language.model.tests.utils.ProblemParseHelper;

import static org.hamcrest.MatcherAssert.assertThat;
import static org.hamcrest.Matchers.empty;

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

	@Test
	void exampleTest() {
		var problem = parseHelper.parse("""
				class Family {
					contains Person[] members
				}

				class Person {
					Person[0..*] children opposite parent
					Person[0..1] parent opposite children
					TaxStatus taxStatus
				}

				enum TaxStatus {
					CHILD, STUDENT, ADULT, RETIRED
				}

				% A child cannot have any dependents.
				error invalidTaxStatus(Person p) <->
					taxStatus(p, CHILD), children(p, _q).

				atom family.
				Family(family).
				members(family, anne): true.
				members(family, bob).
				members(family, ciri).
				children(anne, ciri).
				?children(bob, ciri).
				taxStatus(anne, ADULT).
				""");
		assertThat(problem.getResourceErrors(), empty());
	}
}