aboutsummaryrefslogtreecommitdiffstats
path: root/language/src/test/java/org/eclipse/viatra/solver/language/tests/ProblemParsingTest.xtend
blob: 11bfc6d9979477981f1ba5cebc8d21b8633ddab4 (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
/*
 * generated by Xtext 2.26.0.M1
 */
package org.eclipse.viatra.solver.language.tests

import com.google.inject.Inject
import org.eclipse.viatra.solver.language.model.problem.Problem
import org.eclipse.xtext.testing.InjectWith
import org.eclipse.xtext.testing.extensions.InjectionExtension
import org.eclipse.xtext.testing.util.ParseHelper
import org.junit.jupiter.api.Test
import org.junit.jupiter.api.^extension.ExtendWith

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

@ExtendWith(InjectionExtension)
@InjectWith(ProblemInjectorProvider)
class ProblemParsingTest {
	@Inject
	ParseHelper<Problem> parseHelper
	
	@Inject
	extension ProblemTestUtil
	
	@Test
	def void exampleTest() {
		val it = parseHelper.parse('''
			class Family {
				contains Person[] members
			}
			
			class Person {
				Person[0..*] children opposite parent
				Person[0..1] parent opposite children
				int age
				TaxStatus taxStatus
			}
			
			enum TaxStatus {
				child, student, adult, retired
			}
			
			% A child cannot have any dependents.
			error invalidTaxStatus(Person p) <->
				taxStatus(p, child), children(p, _q).
			
			unique family.
			Family(family).
			members(family, anne): true.
			members(family, bob).
			members(family, ciri).
			children(anne, ciri).
			?children(bob, ciri).
			taxStatus(anne, adult).
			age(anne, 35).
			bobAge: 27.
			age(bob, bobAge).
			!age(ciri, bobAge).
		''')
		assertThat(errors, empty)
	}
}