diff options
Diffstat (limited to 'subprojects/language/src/test/java/tools/refinery/language/tests/serializer/ProblemSerializerTest.java')
-rw-r--r-- | subprojects/language/src/test/java/tools/refinery/language/tests/serializer/ProblemSerializerTest.java | 75 |
1 files changed, 69 insertions, 6 deletions
diff --git a/subprojects/language/src/test/java/tools/refinery/language/tests/serializer/ProblemSerializerTest.java b/subprojects/language/src/test/java/tools/refinery/language/tests/serializer/ProblemSerializerTest.java index 4a3a9ac2..65675b6b 100644 --- a/subprojects/language/src/test/java/tools/refinery/language/tests/serializer/ProblemSerializerTest.java +++ b/subprojects/language/src/test/java/tools/refinery/language/tests/serializer/ProblemSerializerTest.java | |||
@@ -156,6 +156,7 @@ class ProblemSerializerTest { | |||
156 | problem.getStatements().add(assertion); | 156 | problem.getStatements().add(assertion); |
157 | } | 157 | } |
158 | 158 | ||
159 | |||
159 | @Test | 160 | @Test |
160 | void implicitVariableTest() { | 161 | void implicitVariableTest() { |
161 | var pred = ProblemFactory.eINSTANCE.createPredicateDefinition(); | 162 | var pred = ProblemFactory.eINSTANCE.createPredicateDefinition(); |
@@ -227,15 +228,77 @@ class ProblemSerializerTest { | |||
227 | """); | 228 | """); |
228 | } | 229 | } |
229 | 230 | ||
231 | @Test | ||
232 | void unambiguousNameTest() { | ||
233 | createClassAndAssertion("Foo", "foo"); | ||
234 | |||
235 | assertSerializedResult(""" | ||
236 | class Foo { | ||
237 | Foo ref | ||
238 | } | ||
239 | |||
240 | ref(foo, foo). | ||
241 | """); | ||
242 | } | ||
243 | |||
244 | @Test | ||
245 | void ambiguousNameTest() { | ||
246 | createClassAndAssertion("Foo", "foo"); | ||
247 | createClassAndAssertion("Bar", "bar"); | ||
248 | |||
249 | assertSerializedResult(""" | ||
250 | class Foo { | ||
251 | Foo ref | ||
252 | } | ||
253 | |||
254 | Foo::ref(foo, foo). | ||
255 | |||
256 | class Bar { | ||
257 | Bar ref | ||
258 | } | ||
259 | |||
260 | Bar::ref(bar, bar). | ||
261 | """); | ||
262 | } | ||
263 | |||
264 | private void createClassAndAssertion(String className, String nodeName) { | ||
265 | var classDeclaration = ProblemFactory.eINSTANCE.createClassDeclaration(); | ||
266 | classDeclaration.setName(className); | ||
267 | var referenceDeclaration = ProblemFactory.eINSTANCE.createReferenceDeclaration(); | ||
268 | referenceDeclaration.setReferenceType(classDeclaration); | ||
269 | referenceDeclaration.setName("ref"); | ||
270 | classDeclaration.getFeatureDeclarations().add(referenceDeclaration); | ||
271 | problem.getStatements().add(classDeclaration); | ||
272 | var node = ProblemFactory.eINSTANCE.createNode(); | ||
273 | node.setName(nodeName); | ||
274 | problem.getNodes().add(node); | ||
275 | createBinaryAssertion(referenceDeclaration, node, node); | ||
276 | } | ||
277 | |||
278 | private void createBinaryAssertion(Relation relation, Node from, Node to) { | ||
279 | var assertion = ProblemFactory.eINSTANCE.createAssertion(); | ||
280 | assertion.setRelation(relation); | ||
281 | var fromArgument = ProblemFactory.eINSTANCE.createNodeAssertionArgument(); | ||
282 | fromArgument.setNode(from); | ||
283 | assertion.getArguments().add(fromArgument); | ||
284 | var toArgument = ProblemFactory.eINSTANCE.createNodeAssertionArgument(); | ||
285 | toArgument.setNode(to); | ||
286 | assertion.getArguments().add(toArgument); | ||
287 | var value = ProblemFactory.eINSTANCE.createLogicConstant(); | ||
288 | value.setLogicValue(LogicValue.TRUE); | ||
289 | assertion.setValue(value); | ||
290 | problem.getStatements().add(assertion); | ||
291 | } | ||
292 | |||
230 | private void assertSerializedResult(String expected) { | 293 | private void assertSerializedResult(String expected) { |
231 | String problemString; | 294 | String problemString; |
232 | try (var outputStream = new ByteArrayOutputStream()) { | 295 | try (var outputStream = new ByteArrayOutputStream()) { |
233 | resource.save(outputStream, Map.of()); | 296 | resource.save(outputStream, Map.of()); |
234 | problemString = outputStream.toString(); | 297 | problemString = outputStream.toString(); |
235 | } catch (IOException e) { | 298 | } catch (IOException e) { |
236 | throw new AssertionError("Failed to serialize problem", e); | 299 | throw new AssertionError("Failed to serialize problem", e); |
237 | } | 300 | } |
238 | // Nothing to handle in a test. | 301 | // Nothing to handle in a test. |
239 | 302 | ||
240 | assertThat(problemString.replace("\r\n", "\n"), equalTo(expected.replace("\r\n", "\n"))); | 303 | assertThat(problemString.replace("\r\n", "\n"), equalTo(expected.replace("\r\n", "\n"))); |
241 | } | 304 | } |