Skip to content
Snippets Groups Projects
Commit 87ede88c authored by René Schöne's avatar René Schöne
Browse files

3.0.0

- prepare new release
- remove deprecated inclusion/exclusion
parent 88264e06
No related branches found
No related tags found
1 merge request!133.0.1
......@@ -54,9 +54,6 @@ IntrinsicTokenMethod : TokenMethod ::= <Refined:boolean> ;
AttributeMethod : TokenMethod ;
BuildConfig ::= StyleInformation
GlobalPatternCollection:PatternCollection
ExcludeTypePattern:TypePatternCollectionMapping*
IncludeTypePattern:TypePatternCollectionMapping*
<IncludeRelationMethod:IncludeRelationMethod>
<IncludeChildMethod:IncludeChildMethod>
<IncludeAttributeMethod:IncludeAttributeMethod>
......@@ -65,8 +62,6 @@ BuildConfig ::= StyleInformation
<IncludeEmptyString:boolean>
<ExcludeNullNodes:boolean>
<Debug:boolean>;
TypePatternCollectionMapping ::= <TypeRegex> PatternCollection ;
PatternCollection ::= <TokenPattern> <ChildPattern> <RelationPattern> <AttributePattern> <NonterminalAttributePattern> ;
StyleInformation ::= <ComputedColor>;
PrintConfig ::= Header*
......
......@@ -47,7 +47,7 @@ public class FeatureTestMain {
// .customPreamble("hide empty members")
.enableDebug()
.customPreamble("title My fancy title")
.includeChildWhen((parentNode, childNode, contextName) -> {
.includeChild((parentNode, childNode, contextName) -> {
if (parentNode instanceof A && ((A) parentNode).getName().equals("A2")) {
return false;
}
......@@ -56,9 +56,9 @@ public class FeatureTestMain {
}
return !contextName.equals("MyC");
})
.includeRelationsWhen((sourceNode, targetNode, roleName) ->
.includeRelation((sourceNode, targetNode, roleName) ->
!(sourceNode instanceof B) || !((B) sourceNode).getName().equals("B6.1.1"))
.includeAttributeWhen((node, attributeName, isNTA, supplier) -> {
.includeAttribute((node, attributeName, isNTA, supplier) -> {
switch (attributeName) {
case "referenceAttr":
case "collectBs":
......
......@@ -198,7 +198,8 @@ public class TestExcluded {
c.setBiA1(a);
}));
List<DumpNode> nodes = TestUtils.dumpModel(root, db -> db.excludeTokens(TOKEN_LABEL_UNWANTED));
List<DumpNode> nodes = TestUtils.dumpModel(root, db -> db.includeToken((node, tokenName, value) ->
!tokenName.equals(TOKEN_LABEL_UNWANTED)));
assertThat(nodes).flatExtracting(NAME_EXTRACTOR).containsExactlyInAnyOrder(ROOT_NAME, A_NAME, C_NAME);
DumpNode actualC = findByName(nodes, C_NAME);
assertThat(valueTokens(actualC)).containsOnly(
......@@ -218,7 +219,8 @@ public class TestExcluded {
c.setBiA1(a);
}));
List<DumpNode> nodes = TestUtils.dumpModel(root, db -> db.excludeTokens(TOKEN_LABEL_UNWANTED, TOKEN_LABEL_RAW_REFERENCE));
List<DumpNode> nodes = TestUtils.dumpModel(root, db -> db.includeToken((node, tokenName, value) ->
!tokenName.equals(TOKEN_LABEL_UNWANTED) && !tokenName.equals(TOKEN_LABEL_RAW_REFERENCE)));
assertThat(nodes).flatExtracting(NAME_EXTRACTOR).containsExactlyInAnyOrder(ROOT_NAME, A_NAME, C_NAME);
DumpNode actualC = findByName(nodes, C_NAME);
assertThat(valueTokens(actualC)).containsOnly(
......@@ -238,7 +240,8 @@ public class TestExcluded {
c.setBiA1(a);
}));
List<DumpNode> nodes = TestUtils.dumpModel(root, db -> db.excludeTokens("bi.*"));
List<DumpNode> nodes = TestUtils.dumpModel(root, db -> db.includeToken((node, tokenName, value) ->
!tokenName.startsWith("bi")));
assertThat(nodes).flatExtracting(NAME_EXTRACTOR).containsExactlyInAnyOrder(ROOT_NAME, A_NAME, C_NAME);
DumpNode actualC = findByName(nodes, C_NAME);
assertThat(valueTokens(actualC)).containsOnly(
......@@ -258,7 +261,8 @@ public class TestExcluded {
c.setBiA1(a);
}));
List<DumpNode> nodes = TestUtils.dumpModel(root, db -> db.excludeTokens("Bi.*"));
List<DumpNode> nodes = TestUtils.dumpModel(root, db -> db.includeToken((node, tokenName, value) ->
!tokenName.startsWith("Bi")));
assertThat(nodes).flatExtracting(NAME_EXTRACTOR).containsExactlyInAnyOrder(ROOT_NAME, A_NAME, C_NAME);
DumpNode actualC = findByName(nodes, C_NAME);
assertThat(valueTokens(actualC)).containsOnly(
......@@ -312,7 +316,8 @@ public class TestExcluded {
}), null);
root.getA().getB().setOneA(root.getA().getMyC().getA());
List<DumpNode> nodes = TestUtils.dumpModel(root, db -> db.excludeChildren("MyC"));
List<DumpNode> nodes = TestUtils.dumpModel(root, db -> db.includeChild((parentNode, childNode, contextName) ->
!contextName.equals("MyC")));
assertThat(nodes).flatExtracting(NAME_EXTRACTOR).containsExactlyInAnyOrder(
ROOT_NAME, A_NAME, B_NAME, A2_Name, B2_NAME);
DumpNode actualA = findByName(nodes, A_NAME);
......@@ -333,7 +338,8 @@ public class TestExcluded {
public void testRelationsExclude() throws TransformationException {
Root root = setupAllRelations();
List<DumpNode> nodes = TestUtils.dumpModel(root, db -> db.excludeRelations("BiC1"));
List<DumpNode> nodes = TestUtils.dumpModel(root, db -> db.includeRelation((sourceNode, targetNode, roleName) ->
!roleName.equals("BiC1")));
// A
assertThatMapOf(normalRelationChildren(findByName(nodes, A_NAME))).containsExactlyInAnyOrder(
tuple("BiC2", C_NAME), tuple("BiC3", C_NAME));
......@@ -352,7 +358,8 @@ public class TestExcluded {
public void testRelationsExcludeRegex1() throws TransformationException {
Root root = setupAllRelations();
List<DumpNode> nodes = TestUtils.dumpModel(root, db -> db.excludeRelations("Bi.*"));
List<DumpNode> nodes = TestUtils.dumpModel(root, db -> db.includeRelation((sourceNode, targetNode, roleName) ->
!roleName.startsWith("Bi")));
// A
assertThat(normalRelationChildren(findByName(nodes, A_NAME))).isEmpty();
// B
......@@ -369,7 +376,8 @@ public class TestExcluded {
public void testRelationsExcludeRegex2() throws TransformationException {
Root root = setupAllRelations();
List<DumpNode> nodes = TestUtils.dumpModel(root, db -> db.excludeRelations(".*A.*"));
List<DumpNode> nodes = TestUtils.dumpModel(root, db -> db.includeRelation((sourceNode, targetNode, roleName) ->
!roleName.contains("A")));
// A
assertThatMapOf(normalRelationChildren(findByName(nodes, A_NAME))).containsExactlyInAnyOrder(
tuple("BiC1", C_NAME), tuple("BiC2", C_NAME), tuple("BiC3", C_NAME));
......
......@@ -26,7 +26,8 @@ public class TestIncluded {
public void testValueAttributeIncluded() throws TransformationException {
Root root = createRoot(null, null);
List<DumpNode> nodes = TestUtils.dumpModel(root, db -> db.includeAttributes("simpleAttr"));
List<DumpNode> nodes = TestUtils.dumpModel(root, db ->
db.includeAttribute((node, attributeName, isNTA, value) -> !isNTA && attributeName.equals("simpleAttr")));
assertThat(nodes).flatExtracting(NAME_EXTRACTOR).containsExactly(ROOT_NAME);
DumpNode actualRoot = TestUtils.findByName(nodes, ROOT_NAME);
assertThat(valueTokens(actualRoot)).containsOnly(entry("Name", ROOT_NAME), entry("simpleAttr", 42));
......@@ -36,7 +37,8 @@ public class TestIncluded {
public void testReferenceListAttributeIncluded() throws TransformationException {
Root root = createRoot(null, null, createB(B1_NAME), createB(B2_NAME), createB(B3_NAME));
List<DumpNode> nodes = TestUtils.dumpModel(root, db -> db.includeAttributes("setOfBs"));
List<DumpNode> nodes = TestUtils.dumpModel(root, db ->
db.includeAttribute((node, attributeName, isNTA, value) -> !isNTA && attributeName.equals("setOfBs")));
assertThat(nodes).flatExtracting(NAME_EXTRACTOR).containsExactly(ROOT_NAME, B1_NAME, B2_NAME, B3_NAME);
DumpNode actualRoot = TestUtils.findByName(nodes, ROOT_NAME);
......@@ -58,7 +60,8 @@ public class TestIncluded {
public void testReferenceAttributeIncluded() throws TransformationException {
Root root = createRoot(createA(A_NAME), null);
List<DumpNode> nodes = TestUtils.dumpModel(root, db -> db.includeAttributes("referenceAttr"));
List<DumpNode> nodes = TestUtils.dumpModel(root, db ->
db.includeAttribute((node, attributeName, isNTA, value) -> !isNTA && attributeName.equals("referenceAttr")));
assertThat(nodes).flatExtracting(NAME_EXTRACTOR).containsExactly(ROOT_NAME, A_NAME);
DumpNode actualRoot = TestUtils.findByName(nodes, ROOT_NAME);
assertThatMapOf(referenceTokens(actualRoot)).containsOnly(tuple("referenceAttr", A_NAME));
......@@ -78,7 +81,8 @@ public class TestIncluded {
public void testNormalNTAIncluded() throws TransformationException {
Root root = createRoot(null, createC(C_NAME));
List<DumpNode> nodes = TestUtils.dumpModel(root, db -> db.includeNonterminalAttributes("Calculated"));
List<DumpNode> nodes = TestUtils.dumpModel(root, db ->
db.includeAttribute((node, attributeName, isNTA, value) -> isNTA && attributeName.equals("Calculated")));
assertThat(nodes).flatExtracting(NAME_EXTRACTOR).containsExactly(ROOT_NAME, C_NAME, "Calculated-" + C_NAME);
DumpNode actualC = TestUtils.findByName(nodes, C_NAME);
assertThatMapOf(normalChildren(actualC)).containsOnly(tuple("Calculated", "Calculated-" + C_NAME));
......@@ -99,7 +103,8 @@ public class TestIncluded {
public void testListNTAIncluded() throws TransformationException {
Root root = createRoot(null, createC(C_NAME));
List<DumpNode> nodes = TestUtils.dumpModel(root, db -> db.includeNonterminalAttributes("AlsoCalculated"));
List<DumpNode> nodes = TestUtils.dumpModel(root, db ->
db.includeAttribute((node, attributeName, isNTA, value) -> isNTA && attributeName.equals("AlsoCalculated")));
assertThat(nodes).flatExtracting(NAME_EXTRACTOR).containsExactly(ROOT_NAME, C_NAME, "AlsoCalculated-" + C_NAME);
DumpNode actualC = TestUtils.findByName(nodes, C_NAME);
assertThatMapOf(listChildren(actualC), "AlsoCalculated").containsExactly("AlsoCalculated-" + C_NAME);
......
package de.tudresden.inf.st.jastadd.testDumper;
import de.tudresden.inf.st.jastadd.dumpAst.ast.DumpNode;
import de.tudresden.inf.st.jastadd.dumpAst.ast.TransformationException;
import org.jastadd.testDumper.ast.A;
import org.jastadd.testDumper.ast.AbstractT;
import org.jastadd.testDumper.ast.TRoot;
import org.junit.jupiter.api.Assertions;
import org.junit.jupiter.api.DisplayName;
import org.junit.jupiter.api.Test;
import java.util.List;
import java.util.function.Consumer;
import static de.tudresden.inf.st.jastadd.testDumper.TestUtils.*;
import static org.assertj.core.api.Assertions.*;
/**
* Testing type-level exclusions.
* <p>
* Refer to {@link de.tudresden.inf.st.jastadd.dumpAst.ast.DumpBuilder DumpBuilder} for levels of inclusion/exclusion.
*
* @author rschoene - Initial contribution
*/
public class TestTypeLevel3 {
@Test
public void testTokenLevel2Excluded() throws TransformationException {
Consumer<AbstractT> setUnwanted = t -> t.setUnwanted(5);
TRoot root = createTRoot(createA(A_NAME), createT1(setUnwanted), createT2(setUnwanted), createT3(setUnwanted));
Assertions.assertEquals(5, root.getT2().getUnwanted());
List<DumpNode> nodes = TestUtils.dumpModel(root, dp -> dp.excludeTokens("Unwanted"));
assertThat(nodes).flatExtracting(NAME_EXTRACTOR).containsExactlyInAnyOrder(ROOT_NAME, A_NAME, T1_NAME, T2_NAME, T3_NAME);
for (String name : Tx_NAMES) {
DumpNode actualTx = TestUtils.findByName(nodes, name);
assertThat(valueTokens(actualTx)).containsOnly(entry("Name", name));
}
}
@Test
public void testTokenLevel3SomeIncluded() throws TransformationException {
Consumer<AbstractT> setUnwanted = t -> t.setUnwanted(5);
TRoot root = createTRoot(createA(A_NAME), createT1(setUnwanted), createT2(setUnwanted), createT3(setUnwanted));
Assertions.assertEquals(5, root.getT2().getUnwanted());
List<DumpNode> nodesT2 = TestUtils.dumpModel(root,
dp -> dp.excludeTokens("Unwanted")
.includeTokensFor("T2", "Unwanted"));
assertThat(nodesT2).flatExtracting(NAME_EXTRACTOR).containsExactlyInAnyOrder(ROOT_NAME, A_NAME, T1_NAME, T2_NAME, T3_NAME);
assertThat(valueTokens(TestUtils.findByName(nodesT2, T1_NAME))).containsOnly(
entry("Name", T1_NAME));
assertThat(valueTokens(TestUtils.findByName(nodesT2, T2_NAME))).containsOnly(
entry("Name", T2_NAME), entry("Unwanted", 5));
assertThat(valueTokens(TestUtils.findByName(nodesT2, T3_NAME))).containsOnly(
entry("Name", T3_NAME));
List<DumpNode> nodesT2T3 = TestUtils.dumpModel(root,
dp -> dp.excludeTokens("Unwanted")
.includeTokensFor("T2|T3", "Unwanted"));
assertThat(nodesT2T3).flatExtracting(NAME_EXTRACTOR).containsExactlyInAnyOrder(ROOT_NAME, A_NAME, T1_NAME, T2_NAME, T3_NAME);
assertThat(valueTokens(TestUtils.findByName(nodesT2T3, T1_NAME))).containsOnly(
entry("Name", T1_NAME));
assertThat(valueTokens(TestUtils.findByName(nodesT2T3, T2_NAME))).containsOnly(
entry("Name", T2_NAME), entry("Unwanted", 5));
assertThat(valueTokens(TestUtils.findByName(nodesT2T3, T3_NAME))).containsOnly(
entry("Name", T3_NAME), entry("Unwanted", 5));
}
@Test
public void testNormalChildLevel2Excluded() throws TransformationException {
Consumer<AbstractT> setB = t -> t.setB(createB(t.getName() + B_NAME));
TRoot root = createTRoot(createA(A_NAME), createT1(setB), createT2(setB), createT3(setB));
Assertions.assertEquals(T2_NAME + B_NAME, root.getT2().getB().getName());
List<DumpNode> nodes = TestUtils.dumpModel(root, dp -> dp.excludeChildren("B"));
assertThat(nodes).flatExtracting(NAME_EXTRACTOR).containsExactlyInAnyOrder(ROOT_NAME, A_NAME, T1_NAME, T2_NAME, T3_NAME);
for (String name : Tx_NAMES) {
DumpNode actualTx = TestUtils.findByName(nodes, name);
assertThat(normalChildren(actualTx)).isEmpty();
}
}
@Test
public void testNormalChildLevel3SomeIncluded() throws TransformationException {
Consumer<AbstractT> setB = t -> t.setB(createB(t.getName() + B_NAME));
TRoot root = createTRoot(createA(A_NAME), createT1(setB), createT2(setB), createT3(setB));
Assertions.assertEquals(T2_NAME + B_NAME, root.getT2().getB().getName());
List<DumpNode> nodes = TestUtils.dumpModel(root,
dp -> dp.excludeChildren("B")
.includeChildrenFor("T2", "B"));
assertThat(nodes).flatExtracting(NAME_EXTRACTOR).containsExactlyInAnyOrder(ROOT_NAME, A_NAME, T1_NAME, T2_NAME, T3_NAME, T2_NAME + B_NAME);
assertThat(normalChildren(TestUtils.findByName(nodes, T1_NAME))).isEmpty();
assertThatMapOf(normalChildren(TestUtils.findByName(nodes, T2_NAME))).containsOnly(
tuple("B", T2_NAME + B_NAME));
assertThat(normalChildren(TestUtils.findByName(nodes, T3_NAME))).isEmpty();
}
@Test
public void testListChildLevel2Excluded() throws TransformationException {
Consumer<AbstractT> addBee = t -> t.addBee(createB(t.getName() + B_NAME));
TRoot root = createTRoot(createA(A_NAME), createT1(addBee), createT2(addBee), createT3(addBee));
Assertions.assertEquals(T2_NAME + B_NAME, root.getT2().getBee(0).getName());
List<DumpNode> nodes = TestUtils.dumpModel(root,
dp -> dp.excludeChildren("Bee"));
assertThat(nodes).flatExtracting(NAME_EXTRACTOR).containsExactlyInAnyOrder(ROOT_NAME, A_NAME, T1_NAME, T2_NAME, T3_NAME);
for (String name : Tx_NAMES) {
assertEmpty(findByName(nodes, name).getDumpChildNode(0));
}
}
@Test
public void testListChildLevel3SomeIncluded() throws TransformationException {
Consumer<AbstractT> addBee = t -> t.addBee(createB(t.getName() + B_NAME));
TRoot root = createTRoot(createA(A_NAME), createT1(addBee), createT2(addBee), createT3(addBee));
Assertions.assertEquals(T2_NAME + B_NAME, root.getT2().getBee(0).getName());
List<DumpNode> nodes = TestUtils.dumpModel(root,
dp -> dp.excludeChildren("Bee")
.includeChildrenFor("T2", "Bee"));
assertThat(nodes).flatExtracting(NAME_EXTRACTOR).containsExactlyInAnyOrder(ROOT_NAME, A_NAME, T1_NAME, T2_NAME, T3_NAME, T2_NAME + B_NAME);
assertEmpty(findByName(nodes, T1_NAME).getDumpChildNode(0));
assertThatMapOf(listChildren(TestUtils.findByName(nodes, T2_NAME)), "Bee").containsOnly(
T2_NAME + B_NAME);
assertEmpty(TestUtils.findByName(nodes, T3_NAME).getDumpChildNode(0));
}
@Test
public void testRelationLevel2Excluded() throws TransformationException {
final A a = createA(A_NAME);
Consumer<AbstractT> setOneA = t -> t.setOneA(a);
TRoot root = createTRoot(a, createT1(setOneA), createT2(setOneA), createT3(setOneA));
Assertions.assertEquals(a, root.getT2().getOneA());
List<DumpNode> nodes = TestUtils.dumpModel(root, dp -> dp.excludeRelations("OneA"));
assertThat(nodes).flatExtracting(NAME_EXTRACTOR).containsExactlyInAnyOrder(ROOT_NAME, A_NAME, T1_NAME, T2_NAME, T3_NAME);
for (String name : Tx_NAMES) {
DumpNode actualTx = TestUtils.findByName(nodes, name);
assertThat(normalRelationChildren(actualTx)).isEmpty();
}
}
@Test
public void testRelationLevel3SomeIncluded() throws TransformationException {
final A a = createA(A_NAME);
Consumer<AbstractT> setOneA = t -> t.setOneA(a);
TRoot root = createTRoot(a, createT1(setOneA), createT2(setOneA), createT3(setOneA));
Assertions.assertEquals(a, root.getT2().getOneA());
List<DumpNode> nodes = TestUtils.dumpModel(root,
dp -> dp.excludeRelations("OneA")
.includeRelationsFor("T2", "OneA"));
assertThat(nodes).flatExtracting(NAME_EXTRACTOR).containsExactlyInAnyOrder(ROOT_NAME, A_NAME, T1_NAME, T2_NAME, T3_NAME);
assertThat(normalRelationChildren(TestUtils.findByName(nodes, T1_NAME))).isEmpty();
assertThatMapOf(normalRelationChildren(TestUtils.findByName(nodes, T2_NAME))).containsOnly(
tuple("OneA", A_NAME));
assertThat(normalRelationChildren(TestUtils.findByName(nodes, T3_NAME))).isEmpty();
}
@Test
public void testAttributeLevel2Included() throws TransformationException {
TRoot root = createTRoot(createA(A_NAME), createT1(), createT2(), createT3());
List<DumpNode> nodes = dumpModel(root,
dp -> dp.includeAttributes("simpleAttr"));
assertThat(nodes).flatExtracting(NAME_EXTRACTOR).containsExactlyInAnyOrder(ROOT_NAME, A_NAME, T1_NAME, T2_NAME, T3_NAME);
for (String name : Tx_NAMES) {
DumpNode actualTx = findByName(nodes, name);
assertThat(valueTokens(actualTx)).containsOnly(
entry("Name", name),
entry(TOKEN_LABEL_UNWANTED, 0),
entry("simpleAttr", 43));
}
}
@Test
public void testAttributeLevel3SomeExcluded() throws TransformationException {
TRoot root = createTRoot(createA(A_NAME), createT1(), createT2(), createT3());
List<DumpNode> nodes = dumpModel(root,
dp -> dp.includeAttributes("simpleAttr")
.excludeAttributesFor("T2", "simpleAttr"));
assertThat(nodes).flatExtracting(NAME_EXTRACTOR).containsExactlyInAnyOrder(ROOT_NAME, A_NAME, T1_NAME, T2_NAME, T3_NAME);
assertThat(valueTokens(findByName(nodes, T1_NAME))).containsOnly(
entry("Name", T1_NAME), entry(TOKEN_LABEL_UNWANTED, 0), entry("simpleAttr", 43));
assertThat(valueTokens(findByName(nodes, T2_NAME))).containsOnly(
entry("Name", T2_NAME), entry(TOKEN_LABEL_UNWANTED, 0));
assertThat(valueTokens(findByName(nodes, T3_NAME))).containsOnly(
entry("Name", T3_NAME), entry(TOKEN_LABEL_UNWANTED, 0), entry("simpleAttr", 43));
}
@Test
public void testNTALevel2Included() throws TransformationException {
TRoot root = createTRoot(createA(A_NAME), createT1(), createT2(), createT3());
List<DumpNode> nodes = dumpModel(root,
dp -> dp.includeNonterminalAttributes("Calculated"));
assertThat(nodes).flatExtracting(NAME_EXTRACTOR).containsExactlyInAnyOrder(ROOT_NAME, A_NAME, T1_NAME, T2_NAME, T3_NAME, "Calculated-" + T1_NAME, "Calculated-" + T2_NAME, "Calculated-" + T3_NAME);
for (String name : Tx_NAMES) {
assertThatMapOf(normalChildren(findByName(nodes, name))).containsOnly(
tuple("Calculated", "Calculated-" + name));
}
}
@Test
public void testNTALevel3SomeExcluded() throws TransformationException {
TRoot root = createTRoot(createA(A_NAME), createT1(), createT2(), createT3());
List<DumpNode> nodes = dumpModel(root,
dp -> dp.includeNonterminalAttributes("Calculated")
.excludeNonterminalAttributesFor("T2", "Calculated"));
assertThat(nodes).flatExtracting(NAME_EXTRACTOR).containsExactlyInAnyOrder(ROOT_NAME, A_NAME, T1_NAME, T2_NAME, T3_NAME, "Calculated-" + T1_NAME, "Calculated-" + T3_NAME);
assertThatMapOf(normalChildren(findByName(nodes, T1_NAME))).containsOnly(
tuple("Calculated", "Calculated-" + T1_NAME));
assertThat(normalChildren(findByName(nodes, T2_NAME))).isEmpty();
assertThatMapOf(normalChildren(findByName(nodes, T3_NAME))).containsOnly(
tuple("Calculated", "Calculated-" + T3_NAME));
}
}
package de.tudresden.inf.st.jastadd.testDumper;
import de.tudresden.inf.st.jastadd.dumpAst.ast.DumpNode;
import de.tudresden.inf.st.jastadd.dumpAst.ast.TransformationException;
import org.jastadd.testDumper.ast.A;
import org.jastadd.testDumper.ast.AbstractT;
import org.jastadd.testDumper.ast.TRoot;
import org.junit.jupiter.api.Assertions;
import org.junit.jupiter.api.Test;
import java.util.List;
import java.util.function.Consumer;
import static de.tudresden.inf.st.jastadd.testDumper.TestUtils.*;
import static org.assertj.core.api.Assertions.*;
/**
* Testing type-level inclusions.
* <p>
* Refer to {@link de.tudresden.inf.st.jastadd.dumpAst.ast.DumpBuilder DumpBuilder} for levels of inclusion/exclusion.
*
* @author rschoene - Initial contribution
*/
public class TestTypeLevel4 {
@Test
public void testTokenLevel3Included() throws TransformationException {
Consumer<AbstractT> setUnwanted = t -> t.setUnwanted(5);
TRoot root = createTRoot(createA(A_NAME, createC(C_NAME, c -> c.setUnwanted(6))),
createT1(setUnwanted), createT2(setUnwanted), createT3(setUnwanted));
Assertions.assertEquals(5, root.getT2().getUnwanted());
List<DumpNode> nodes = dumpModel(root,
dp -> dp.excludeTokens(TOKEN_LABEL_UNWANTED)
.includeTokensFor("T.", TOKEN_LABEL_UNWANTED));
assertThat(nodes).flatExtracting(NAME_EXTRACTOR).containsExactlyInAnyOrder(
ROOT_NAME, A_NAME, C_NAME, T1_NAME, T2_NAME, T3_NAME);
for (String name : Tx_NAMES) {
DumpNode actualTx = findByName(nodes, name);
assertThat(valueTokens(actualTx)).containsOnly(entry("Name", name), entry(TOKEN_LABEL_UNWANTED, 5));
}
assertThat(valueTokens(findByName(nodes, C_NAME))).containsOnly(
entry("Name", C_NAME));
}
@Test
public void testTokenLevel4SomeExcluded() throws TransformationException {
Consumer<AbstractT> setUnwanted = t -> t.setUnwanted(5);
TRoot root = createTRoot(createA(A_NAME, createC(C_NAME, c -> c.setUnwanted(6))),
createT1(setUnwanted), createT2(setUnwanted), createT3(setUnwanted));
Assertions.assertEquals(5, root.getT2().getUnwanted());
List<DumpNode> nodesT2 = dumpModel(root,
dp -> dp.excludeTokens(TOKEN_LABEL_UNWANTED)
.includeTokensFor("T.", TOKEN_LABEL_UNWANTED)
.excludeTokensFor("T3", TOKEN_LABEL_UNWANTED));
assertThat(nodesT2).flatExtracting(NAME_EXTRACTOR).containsExactlyInAnyOrder(
ROOT_NAME, A_NAME, C_NAME, T1_NAME, T2_NAME, T3_NAME);
assertThat(valueTokens(findByName(nodesT2, T1_NAME))).containsOnly(
entry("Name", T1_NAME), entry(TOKEN_LABEL_UNWANTED, 5));
assertThat(valueTokens(findByName(nodesT2, T2_NAME))).containsOnly(
entry("Name", T2_NAME), entry(TOKEN_LABEL_UNWANTED, 5));
assertThat(valueTokens(findByName(nodesT2, T3_NAME))).containsOnly(
entry("Name", T3_NAME));
assertThat(valueTokens(findByName(nodesT2, C_NAME))).containsOnly(
entry("Name", C_NAME));
List<DumpNode> nodesT2T3 = dumpModel(root,
dp -> dp.excludeTokens(TOKEN_LABEL_UNWANTED)
.includeTokensFor("T.", TOKEN_LABEL_UNWANTED)
.excludeTokensFor("T2|T3", TOKEN_LABEL_UNWANTED));
assertThat(nodesT2T3).flatExtracting(NAME_EXTRACTOR).containsExactlyInAnyOrder(
ROOT_NAME, A_NAME, C_NAME, T1_NAME, T2_NAME, T3_NAME);
assertThat(valueTokens(findByName(nodesT2T3, T1_NAME))).containsOnly(
entry("Name", T1_NAME), entry(TOKEN_LABEL_UNWANTED, 5));
assertThat(valueTokens(findByName(nodesT2T3, T2_NAME))).containsOnly(
entry("Name", T2_NAME));
assertThat(valueTokens(findByName(nodesT2T3, T3_NAME))).containsOnly(
entry("Name", T3_NAME));
assertThat(valueTokens(findByName(nodesT2T3, C_NAME))).containsOnly(
entry("Name", C_NAME));
}
@Test
public void testNormalChildLevel3Included() throws TransformationException {
Consumer<AbstractT> setB = t -> t.setB(createB(t.getName() + B_NAME));
TRoot root = createTRoot(createA(A_NAME), createT1(setB), createT2(setB), createT3(setB));
Assertions.assertEquals(T2_NAME + B_NAME, root.getT2().getB().getName());
List<DumpNode> nodes = dumpModel(root,
dp -> dp.excludeChildren("B")
.includeChildrenFor("T.", "B"));
assertThat(nodes).flatExtracting(NAME_EXTRACTOR).containsExactlyInAnyOrder(ROOT_NAME, A_NAME, T1_NAME, T2_NAME, T3_NAME, T1_NAME + B_NAME, T2_NAME + B_NAME, T3_NAME + B_NAME);
for (String name : Tx_NAMES) {
assertThatMapOf(normalChildren(findByName(nodes, name))).containsOnly(
tuple("B", name + B_NAME));
}
}
@Test
public void testNormalChildLevel4SomeExcluded() throws TransformationException {
Consumer<AbstractT> setB = t -> t.setB(createB(t.getName() + B_NAME));
TRoot root = createTRoot(createA(A_NAME), createT1(setB), createT2(setB), createT3(setB));
Assertions.assertEquals(T2_NAME + B_NAME, root.getT2().getB().getName());
List<DumpNode> nodes = dumpModel(root,
dp -> dp.excludeChildren("B")
.includeChildrenFor("T.", "B")
.excludeChildrenFor("T3", "B"));
assertThat(nodes).flatExtracting(NAME_EXTRACTOR).containsExactlyInAnyOrder(ROOT_NAME, A_NAME, T1_NAME, T2_NAME, T3_NAME, T1_NAME + B_NAME, T2_NAME + B_NAME);
assertThatMapOf(normalChildren(findByName(nodes, T1_NAME))).containsOnly(
tuple("B", T1_NAME + B_NAME));
assertThatMapOf(normalChildren(findByName(nodes, T2_NAME))).containsOnly(
tuple("B", T2_NAME + B_NAME));
assertThat(normalChildren(findByName(nodes, T3_NAME))).isEmpty();
}
@Test
public void testListChildLevel3Included() throws TransformationException {
Consumer<AbstractT> addBee = t -> t.addBee(createB(t.getName() + B_NAME));
TRoot root = createTRoot(createA(A_NAME), createT1(addBee), createT2(addBee), createT3(addBee));
Assertions.assertEquals(T3_NAME + B_NAME, root.getT3().getBee(0).getName());
List<DumpNode> nodes = dumpModel(root,
dp -> dp.excludeChildren("Bee")
.includeChildrenFor("T.", "Bee"));
assertThat(nodes).flatExtracting(NAME_EXTRACTOR).containsExactlyInAnyOrder(ROOT_NAME, A_NAME, T1_NAME, T2_NAME, T3_NAME, T1_NAME + B_NAME, T2_NAME + B_NAME, T3_NAME + B_NAME);
for (String name : Tx_NAMES) {
assertThatMapOf(listChildren(findByName(nodes, name)), "Bee").containsOnly(
name + B_NAME);
}
}
@Test
public void testListChildLevel4SomeExcluded() throws TransformationException {
Consumer<AbstractT> addBee = t -> t.addBee(createB(t.getName() + B_NAME));
TRoot root = createTRoot(createA(A_NAME), createT1(addBee), createT2(addBee), createT3(addBee));
Assertions.assertEquals(T3_NAME + B_NAME, root.getT3().getBee(0).getName());
List<DumpNode> nodes = dumpModel(root,
dp -> dp.excludeChildren("Bee")
.includeChildrenFor("T.", "Bee")
.excludeChildrenFor("T3", "Bee"));
assertThat(nodes).flatExtracting(NAME_EXTRACTOR).containsExactlyInAnyOrder(ROOT_NAME, A_NAME, T1_NAME, T2_NAME, T3_NAME, T1_NAME + B_NAME, T2_NAME + B_NAME);
assertThatMapOf(listChildren(findByName(nodes, T1_NAME)), "Bee").containsOnly(
T1_NAME + B_NAME);
assertThatMapOf(listChildren(findByName(nodes, T2_NAME)), "Bee").containsOnly(
T2_NAME + B_NAME);
assertEmpty(findByName(nodes, T3_NAME).getDumpChildNode(0));
}
@Test
public void testRelationLevel3Included() throws TransformationException {
final A a = createA(A_NAME);
Consumer<AbstractT> setOneA = t -> t.setOneA(a);
TRoot root = createTRoot(a, createT1(setOneA), createT2(setOneA), createT3(setOneA));
Assertions.assertEquals(a, root.getT2().getOneA());
List<DumpNode> nodes = dumpModel(root,
dp -> dp.excludeRelations("OneA")
.includeRelationsFor("T2", "OneA"));
assertThat(nodes).flatExtracting(NAME_EXTRACTOR).containsExactlyInAnyOrder(ROOT_NAME, A_NAME, T1_NAME, T2_NAME, T3_NAME);
assertThat(normalRelationChildren(findByName(nodes, T1_NAME))).isEmpty();
assertThatMapOf(normalRelationChildren(findByName(nodes, T2_NAME))).containsOnly(
tuple("OneA", A_NAME));
assertThat(normalRelationChildren(findByName(nodes, T3_NAME))).isEmpty();
}
@Test
public void testRelationLevel4SomeExcluded() throws TransformationException {
final A a = createA(A_NAME);
Consumer<AbstractT> setOneA = t -> t.setOneA(a);
TRoot root = createTRoot(a, createT1(setOneA), createT2(setOneA), createT3(setOneA));
Assertions.assertEquals(a, root.getT2().getOneA());
List<DumpNode> nodes = dumpModel(root,
dp -> dp.excludeRelations("OneA")
.includeRelationsFor("T.", "OneA")
.excludeRelationsFor("T3", "OneA"));
assertThat(nodes).flatExtracting(NAME_EXTRACTOR).containsExactlyInAnyOrder(ROOT_NAME, A_NAME, T1_NAME, T2_NAME, T3_NAME);
assertThatMapOf(normalRelationChildren(findByName(nodes, T1_NAME))).containsOnly(
tuple("OneA", A_NAME));
assertThatMapOf(normalRelationChildren(findByName(nodes, T2_NAME))).containsOnly(
tuple("OneA", A_NAME));
assertThat(normalRelationChildren(findByName(nodes, T3_NAME))).isEmpty();
}
@Test
public void testAttributeLevel3Excluded() throws TransformationException {
TRoot root = createTRoot(createA(A_NAME), createT1(), createT2(), createT3());
List<DumpNode> nodes = TestUtils.dumpModel(root,
dp -> dp.includeAttributes("simpleAttr")
.excludeAttributesFor("T.", "simpleAttr"));
assertThat(nodes).flatExtracting(NAME_EXTRACTOR).containsExactlyInAnyOrder(ROOT_NAME, A_NAME, T1_NAME, T2_NAME, T3_NAME);
for (String name : Tx_NAMES) {
DumpNode actualTx = TestUtils.findByName(nodes, name);
assertThat(valueTokens(actualTx)).containsOnly(
entry("Name", name), entry(TOKEN_LABEL_UNWANTED, 0));
}
}
@Test
public void testAttributeLevel4SomeIncluded() throws TransformationException {
TRoot root = createTRoot(createA(A_NAME), createT1(), createT2(), createT3());
List<DumpNode> nodes = TestUtils.dumpModel(root,
dp -> dp.includeAttributes("simpleAttr")
.excludeAttributesFor("T.", "simpleAttr")
.includeAttributesFor("T3", "simpleAttr"));
assertThat(nodes).flatExtracting(NAME_EXTRACTOR).containsExactlyInAnyOrder(ROOT_NAME, A_NAME, T1_NAME, T2_NAME, T3_NAME);
assertThat(valueTokens(TestUtils.findByName(nodes, T1_NAME))).containsOnly(
entry("Name", T1_NAME), entry(TOKEN_LABEL_UNWANTED, 0));
assertThat(valueTokens(TestUtils.findByName(nodes, T2_NAME))).containsOnly(
entry("Name", T2_NAME), entry(TOKEN_LABEL_UNWANTED, 0));
assertThat(valueTokens(TestUtils.findByName(nodes, T3_NAME))).containsOnly(
entry("Name", T3_NAME), entry(TOKEN_LABEL_UNWANTED, 0), entry("simpleAttr", 43));
}
@Test
public void testNTALevel3Excluded() throws TransformationException {
TRoot root = createTRoot(createA(A_NAME), createT1(), createT2(), createT3());
List<DumpNode> nodes = TestUtils.dumpModel(root,
dp -> dp.includeNonterminalAttributes("Calculated")
.excludeNonterminalAttributesFor("T.", "Calculated"));
assertThat(nodes).flatExtracting(NAME_EXTRACTOR).containsExactlyInAnyOrder(ROOT_NAME, A_NAME, T1_NAME, T2_NAME, T3_NAME);
DumpNode actualT3 = TestUtils.findByName(nodes, T3_NAME);
assertThat(normalChildren(actualT3)).isEmpty();
}
@Test
public void testNTALevel4SomeIncluded() throws TransformationException {
TRoot root = createTRoot(createA(A_NAME), createT1(), createT2(), createT3());
List<DumpNode> nodes = TestUtils.dumpModel(root,
dp -> dp.includeNonterminalAttributes("Calculated")
.excludeNonterminalAttributesFor("T.", "Calculated")
.includeNonterminalAttributesFor("T3", "Calculated"));
assertThat(nodes).flatExtracting(NAME_EXTRACTOR).containsExactlyInAnyOrder(ROOT_NAME, A_NAME, T1_NAME, T2_NAME, T3_NAME, "Calculated-" + T3_NAME);
DumpNode actualT3 = TestUtils.findByName(nodes, T3_NAME);
assertThatMapOf(normalChildren(actualT3)).containsOnly(tuple("Calculated", "Calculated-" + T3_NAME));
}
}
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment