Skip to content

Commit 6fa60dc

Browse files
committed
TEDEFO-5002 Exclude @post rules, add global/stage variable dependency test
1 parent 9133127 commit 6fa60dc

5 files changed

Lines changed: 72 additions & 4 deletions

File tree

src/main/java/eu/europa/ted/efx/sdk2/EfxValidationDependencyExtractor.java

Lines changed: 15 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -128,7 +128,7 @@ public void enterSimpleRule(final SimpleRuleContext ctx) {
128128

129129
@Override
130130
public void exitSimpleRule(final SimpleRuleContext ctx) {
131-
this.commitRule(ctx.asClause(), ctx.forClause());
131+
this.commitRule(ctx.asClause(), ctx.forClause(), ctx.scopeClause());
132132
}
133133

134134
@Override
@@ -138,7 +138,7 @@ public void enterConditionalRule(final ConditionalRuleContext ctx) {
138138

139139
@Override
140140
public void exitConditionalRule(final ConditionalRuleContext ctx) {
141-
this.commitRule(ctx.asClause(), ctx.forClause());
141+
this.commitRule(ctx.asClause(), ctx.forClause(), ctx.scopeClause());
142142
}
143143

144144
@Override
@@ -148,7 +148,7 @@ public void enterFallbackRule(final FallbackRuleContext ctx) {
148148

149149
@Override
150150
public void exitFallbackRule(final FallbackRuleContext ctx) {
151-
this.commitRule(ctx.asClause(), ctx.forClause());
151+
this.commitRule(ctx.asClause(), ctx.forClause(), ctx.scopeClause());
152152
}
153153

154154
private void pushRuleFrame() {
@@ -157,8 +157,19 @@ private void pushRuleFrame() {
157157
this.stack.push(ruleFrame);
158158
}
159159

160-
private void commitRule(final AsClauseContext asClause, final ForClauseContext forClause) {
160+
private boolean isPostOnly(final ScopeClauseContext scopeClause) {
161+
return scopeClause != null
162+
&& scopeClause.scopeAnnotation() != null
163+
&& scopeClause.scopeAnnotation().Post() != null;
164+
}
165+
166+
private void commitRule(final AsClauseContext asClause, final ForClauseContext forClause,
167+
final ScopeClauseContext scopeClause) {
161168
final DependencySet ruleDeps = this.stack.pop();
169+
170+
if (this.isPostOnly(scopeClause)) {
171+
return;
172+
}
162173
final String ruleId = asClause.ruleId().getText().replaceAll("^\"|\"$", "");
163174

164175
final String targetId;

src/test/java/eu/europa/ted/efx/sdk2/EfxValidationDependencyExtractorTest.java

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -120,6 +120,11 @@ void testMultipleStages() throws IOException {
120120
assertDependencyGraph("testMultipleStages");
121121
}
122122

123+
@Test
124+
void testGlobalAndStageVariables() throws IOException {
125+
assertDependencyGraph("testGlobalAndStageVariables");
126+
}
127+
123128
// #endregion: Structure
124129

125130
// #region: Comprehensive ----------------------------------------------------

src/test/resources/eu/europa/ted/efx/sdk2/EfxValidationDependencyExtractorTest/testComprehensive/input.efx

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -56,3 +56,9 @@ WITH ND-Root
5656
ASSERT BT-00-Code in [...accessibility]
5757
AS ERROR R-C02-003
5858
FOR BT-00-Code IN *
59+
60+
// Rule 9: @POST rule — should be excluded from the dependency graph
61+
WITH ND-Root
62+
ASSERT BT-00-Number > 0 and BT-00-Text is present
63+
AS ERROR R-C02-004
64+
FOR BT-00-Indicator IN * SCOPE @POST
Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
{
2+
"fields" : [ {
3+
"id" : "BT-00-Code",
4+
"dependsOn" : {
5+
"assert" : [ {
6+
"ruleId" : "R-GS0-001",
7+
"fields" : [ "BT-00-Text", "BT-00-Number" ],
8+
"nodes" : [ "ND-Root" ]
9+
} ]
10+
}
11+
}, {
12+
"id" : "BT-00-Text",
13+
"requiredBy" : {
14+
"assert" : {
15+
"fields" : [ "BT-00-Code" ]
16+
}
17+
}
18+
}, {
19+
"id" : "BT-00-Number",
20+
"requiredBy" : {
21+
"assert" : {
22+
"fields" : [ "BT-00-Code" ]
23+
}
24+
}
25+
} ],
26+
"nodes" : [ {
27+
"id" : "ND-Root",
28+
"requiredBy" : {
29+
"assert" : {
30+
"fields" : [ "BT-00-Code" ]
31+
}
32+
}
33+
} ]
34+
}
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
// Test: Dependencies inherited through global and stage variables
2+
3+
LET text:$globalLabel = BT-00-Text;
4+
5+
---- STAGE test ----
6+
7+
LET number:$stageThreshold = BT-00-Number;
8+
9+
WITH ND-Root
10+
ASSERT $globalLabel == 'expected' and $stageThreshold > 0
11+
AS ERROR R-GS0-001
12+
FOR BT-00-Code IN *

0 commit comments

Comments
 (0)