Skip to content

Commit 507be8f

Browse files
Merge pull request #162 from OP-TED/TEDEFO-5000-with-compute
TEDEFO-5000 Add tests for WITH ... COMPUTE single expression syntax
2 parents d9b4d13 + 2c086f1 commit 507be8f

2 files changed

Lines changed: 80 additions & 0 deletions

File tree

src/test/java/eu/europa/ted/efx/EfxTestsBase.java

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -87,6 +87,16 @@ protected String translateExpressionWithContext(final String context, final Stri
8787
return translateExpression(String.format("{%s} ${%s}", context, expression));
8888
}
8989

90+
protected void testComputeExpressionWithContext(final String expectedTranslation,
91+
final String context, final String expression) {
92+
assertEquals(expectedTranslation, translateComputeExpressionWithContext(context, expression));
93+
}
94+
95+
protected String translateComputeExpressionWithContext(final String context,
96+
final String expression) {
97+
return translateExpression(String.format("WITH %s COMPUTE %s", context, expression));
98+
}
99+
90100
protected String translateExpression(final String expression, final String... params) {
91101
try {
92102
String result = EfxTranslator.translateExpression(DependencyFactoryMock.INSTANCE,

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

Lines changed: 70 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4604,4 +4604,74 @@ void testComputedProperty_privacyCode_Multilingual() {
46044604
// #endregion: Privacy property cardinality
46054605

46064606
// #endregion: Cardinality x Consumer Gaps
4607+
4608+
// #region: EFX-2 COMPUTE syntax ---------------------------------------------
4609+
4610+
@Test
4611+
void testCompute_BooleanExpression() {
4612+
testComputeExpressionWithContext("(true() or true()) and false()", "BT-00-Text",
4613+
"(ALWAYS or TRUE) and NEVER");
4614+
}
4615+
4616+
@Test
4617+
void testCompute_PresenceCondition() {
4618+
testComputeExpressionWithContext("PathNode/TextField", "ND-Root", "BT-00-Text is present");
4619+
}
4620+
4621+
@Test
4622+
void testCompute_NumericExpression() {
4623+
testComputeExpressionWithContext("1 + 2", "BT-00-Text", "1 + 2");
4624+
}
4625+
4626+
@Test
4627+
void testCompute_StringComparison() {
4628+
testComputeExpressionWithContext("'abc' = 'def'", "BT-00-Text", "'abc' == 'def'");
4629+
}
4630+
4631+
@Test
4632+
void testCompute_FieldReference() {
4633+
testComputeExpressionWithContext("PathNode/TextField/normalize-space(text())", "ND-Root",
4634+
"BT-00-Text");
4635+
}
4636+
4637+
@Test
4638+
void testCompute_WithNodeContext() {
4639+
testComputeExpressionWithContext("PathNode/TextField", "ND-Root", "BT-00-Text is present");
4640+
}
4641+
4642+
@Test
4643+
void testCompute_WithParameters() {
4644+
testExpressionTranslation("'hello' = 'world'",
4645+
"WITH ND-Root, text:$p1, text:$p2 COMPUTE $p1 == $p2", "'hello'", "'world'");
4646+
}
4647+
4648+
@Test
4649+
void testCompute_WithNumericParameters() {
4650+
testExpressionTranslation("1 = 2",
4651+
"WITH ND-Root, number:$p1, number:$p2 COMPUTE $p1 == $p2", "1", "2");
4652+
}
4653+
4654+
@Test
4655+
void testCompute_WithDateParameters() {
4656+
testExpressionTranslation("xs:date('2018-01-01Z') = xs:date('2020-01-01Z')",
4657+
"WITH ND-Root, date:$p1, date:$p2 COMPUTE $p1 == $p2", "2018-01-01Z", "2020-01-01Z");
4658+
}
4659+
4660+
@Test
4661+
void testCompute_WithSequenceParameter() {
4662+
testExpressionTranslation("count(('a','b','c'))",
4663+
"WITH ND-Root, text*:$items COMPUTE count($items)", "['a', 'b', 'c']");
4664+
}
4665+
4666+
@Test
4667+
void testCompute_CaseInsensitive() {
4668+
testComputeExpressionWithContext("(true() or true()) and false()", "BT-00-Text",
4669+
"(ALWAYS or TRUE) and NEVER");
4670+
// Also test lowercase
4671+
assertEquals(
4672+
translateComputeExpressionWithContext("BT-00-Text", "(ALWAYS or TRUE) and NEVER"),
4673+
translateExpression("with BT-00-Text compute (ALWAYS or TRUE) and NEVER"));
4674+
}
4675+
4676+
// #endregion: EFX-2 COMPUTE syntax
46074677
}

0 commit comments

Comments
 (0)