Commit 9b86ba17 authored by René Schöne's avatar René Schöne
Browse files

Add test case for generated constructors.

parent 1afaf270
Pipeline #5074 passed with stage
in 2 minutes and 24 seconds
......@@ -153,6 +153,13 @@ test.dependsOn compileRelationTest
compileRelationTest.dependsOn doublePreprocessRelationTest
doublePreprocessRelationTest.dependsOn preprocessRelationTest
task compileConstructorTest(type: RelastTest) {
relastFiles 'src/test/jastadd/constructors/Constructors.relast'
grammarName = 'src/test/jastadd/constructors/Constructors'
packageName = 'constructors.ast'
moreInputFiles 'src/test/jastadd/constructors/Constructors.jrag'
task compileDefaultNamesTest(type: RelastTest) {
relastFiles 'src/test/jastadd/relations/Relations.relast'
grammarName = 'src/test/jastadd/relations/Relations3'
aspect NTAs {
syn A S.getS4() = new A();
syn List<A> S.getS5List() = new List<>();
syn Opt<A> S.getS6Opt() = new Opt<>();
syn String S.getS7() = "";
syn long S.getS8() = 1L;
syn A B.getB4() = new A();
syn List<A> B.getB5List() = new List<>();
syn Opt<A> B.getB6Opt() = new Opt<>();
syn String B.getB7() = "";
syn long B.getB8() = 1L;
S ::= S1:A S2:A* [S3:A] /S4:A/ /S5:A*/ /[S6:A]/ /<S7>/ /<S8:long>/;
B : S ::= B1:A B2:A* [B3:A] /B4:A/ /B5:A*/ /[B6:A]/ /<B7>/ /<B8:long>/;
rel A.r1 -> X;
rel S.r2* <-> Y.r2;
rel B.r3? -> X;
package org.jastadd.relast.tests;
import constructors.ast.*;
import org.junit.jupiter.api.Assertions;
import org.junit.jupiter.api.Test;
import java.util.ArrayList;
* Testing generated constructors.
* @author rschoene - Initial contribution
public class ConstructorsTest {
public void testX() {
X x = new X();
Assertions.assertEquals(1, numberOfConstructors(X.class));
public void testY() {
Y y0 = new Y();
Y y1 = new Y(new S());
Assertions.assertEquals(2, numberOfConstructors(Y.class));
public void testA() {
A a0 = new A();
A a1 = new A(new X());
Assertions.assertEquals(2, numberOfConstructors(A.class));
public void testS() {
A a = new A();
S s0 = new S();
S s1 = new S(a, new List<>(), new Opt<>());
S s2 = new S(a, new List<>(), new Opt<>(), new ArrayList<>());
Assertions.assertEquals(3, numberOfConstructors(S.class));
public void testB() {
A a = new A();
B b0 = new B();
B b1 = new B(a, new List<>(), new Opt<>(), a, new List<>(), new Opt<>());
B b2 = new B(a, new List<>(), new Opt<>(), new ArrayList<>(), a, new List<>(), new Opt<>(), null);
Assertions.assertEquals(3, numberOfConstructors(B.class));
private int numberOfConstructors(Class<?> clazz) {
return clazz.getConstructors().length;
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment