Skip to content

Commit

Permalink
Simplified test-multilingual rendering
Browse files Browse the repository at this point in the history
  • Loading branch information
rousso committed Jun 17, 2023
1 parent a60b795 commit 1e0b873
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -83,10 +83,7 @@ public <T extends Expression> T composeFieldValueReference(PathExpression fieldR
if ((MultilingualStringExpression.class.isAssignableFrom(type)
|| MultilingualStringListExpression.class.isAssignableFrom(type))
&& !XPathContextualizer.hasPredicate(fieldReference, "@languageID")) {
PathExpression languageSpecific = XPathContextualizer.addPredicate(fieldReference, "@languageID=$__LANG__");
String script = "(for $__LANG__ in $PREFERRED_LANGUAGES return " + languageSpecific.script
+ "/normalize-space(text()), " + fieldReference.script + "/normalize-space(text()))[1]";
return Expression.instantiate(script, type);
return Expression.instantiate("efx:preferred-language-text(" + fieldReference.script + ")", type);
}
if (StringExpression.class.isAssignableFrom(type) || StringListExpression.class.isAssignableFrom(type)) {
return Expression.instantiate(fieldReference.script + "/normalize-space(text())", type);
Expand Down
16 changes: 14 additions & 2 deletions src/test/java/eu/europa/ted/efx/EfxExpressionTranslatorTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -97,8 +97,8 @@ void testLikePatternCondition_WithNot() {
@Test
void testFieldValueComparison_UsingTextFields() {
assertEquals(
"(for $__LANG__ in $PREFERRED_LANGUAGES return PathNode/TextMultilingualField[@languageID=$__LANG__]/normalize-space(text()), PathNode/TextMultilingualField/normalize-space(text()))[1]",
test("ND-Root", "BT-00-Text-Multilingual"));
"PathNode/TextField/normalize-space(text()) = efx:preferred-language-text(PathNode/TextMultilingualField)",
test("ND-Root", "BT-00-Text == BT-00-Text-Multilingual"));
}

@Test
Expand Down Expand Up @@ -1076,6 +1076,18 @@ void testFieldReference_WithAxis() {
test("ND-Root", "ND-Root::preceding::BT-00-Integer"));
}

@Test
void testMultilingualTextFieldReference() {
assertEquals("efx:preferred-language-text(PathNode/TextMultilingualField)",
test("ND-Root", "BT-00-Text-Multilingual"));
}

@Test
void testMultilingualTextFieldReference_WithLanguagePredicate() {
assertEquals("PathNode/TextMultilingualField[./@languageID = 'eng']/normalize-space(text())",
test("ND-Root", "BT-00-Text-Multilingual[BT-00-Text-Multilingual/@languageID == 'eng']"));
}

/*** Boolean functions ***/

@Test
Expand Down

0 comments on commit 1e0b873

Please sign in to comment.