diff --git a/src/test/java/eu/europa/ted/efx/EfxTestsBase.java b/src/test/java/eu/europa/ted/efx/EfxTestsBase.java index d9dcebd..b477e9c 100644 --- a/src/test/java/eu/europa/ted/efx/EfxTestsBase.java +++ b/src/test/java/eu/europa/ted/efx/EfxTestsBase.java @@ -87,6 +87,16 @@ protected String translateExpressionWithContext(final String context, final Stri return translateExpression(String.format("{%s} ${%s}", context, expression)); } + protected void testComputeExpressionWithContext(final String expectedTranslation, + final String context, final String expression) { + assertEquals(expectedTranslation, translateComputeExpressionWithContext(context, expression)); + } + + protected String translateComputeExpressionWithContext(final String context, + final String expression) { + return translateExpression(String.format("WITH %s COMPUTE %s", context, expression)); + } + protected String translateExpression(final String expression, final String... params) { try { String result = EfxTranslator.translateExpression(DependencyFactoryMock.INSTANCE, diff --git a/src/test/java/eu/europa/ted/efx/sdk2/EfxExpressionTranslatorV2Test.java b/src/test/java/eu/europa/ted/efx/sdk2/EfxExpressionTranslatorV2Test.java index ea4b5b0..ddb7633 100644 --- a/src/test/java/eu/europa/ted/efx/sdk2/EfxExpressionTranslatorV2Test.java +++ b/src/test/java/eu/europa/ted/efx/sdk2/EfxExpressionTranslatorV2Test.java @@ -4581,4 +4581,74 @@ void testComputedProperty_privacyCode_Multilingual() { // #endregion: Privacy property cardinality // #endregion: Cardinality x Consumer Gaps + + // #region: EFX-2 COMPUTE syntax --------------------------------------------- + + @Test + void testCompute_BooleanExpression() { + testComputeExpressionWithContext("(true() or true()) and false()", "BT-00-Text", + "(ALWAYS or TRUE) and NEVER"); + } + + @Test + void testCompute_PresenceCondition() { + testComputeExpressionWithContext("PathNode/TextField", "ND-Root", "BT-00-Text is present"); + } + + @Test + void testCompute_NumericExpression() { + testComputeExpressionWithContext("1 + 2", "BT-00-Text", "1 + 2"); + } + + @Test + void testCompute_StringComparison() { + testComputeExpressionWithContext("'abc' = 'def'", "BT-00-Text", "'abc' == 'def'"); + } + + @Test + void testCompute_FieldReference() { + testComputeExpressionWithContext("PathNode/TextField/normalize-space(text())", "ND-Root", + "BT-00-Text"); + } + + @Test + void testCompute_WithNodeContext() { + testComputeExpressionWithContext("PathNode/TextField", "ND-Root", "BT-00-Text is present"); + } + + @Test + void testCompute_WithParameters() { + testExpressionTranslation("'hello' = 'world'", + "WITH ND-Root, text:$p1, text:$p2 COMPUTE $p1 == $p2", "'hello'", "'world'"); + } + + @Test + void testCompute_WithNumericParameters() { + testExpressionTranslation("1 = 2", + "WITH ND-Root, number:$p1, number:$p2 COMPUTE $p1 == $p2", "1", "2"); + } + + @Test + void testCompute_WithDateParameters() { + testExpressionTranslation("xs:date('2018-01-01Z') = xs:date('2020-01-01Z')", + "WITH ND-Root, date:$p1, date:$p2 COMPUTE $p1 == $p2", "2018-01-01Z", "2020-01-01Z"); + } + + @Test + void testCompute_WithSequenceParameter() { + testExpressionTranslation("count(('a','b','c'))", + "WITH ND-Root, text*:$items COMPUTE count($items)", "['a', 'b', 'c']"); + } + + @Test + void testCompute_CaseInsensitive() { + testComputeExpressionWithContext("(true() or true()) and false()", "BT-00-Text", + "(ALWAYS or TRUE) and NEVER"); + // Also test lowercase + assertEquals( + translateComputeExpressionWithContext("BT-00-Text", "(ALWAYS or TRUE) and NEVER"), + translateExpression("with BT-00-Text compute (ALWAYS or TRUE) and NEVER")); + } + + // #endregion: EFX-2 COMPUTE syntax }