From 3aec5b0dbe4519c58d60ba048a2a9584b0dc404d Mon Sep 17 00:00:00 2001 From: Martin Kouba Date: Mon, 15 Feb 2021 09:45:16 +0100 Subject: [PATCH] Qute - fix orEmpty resolver --- .../src/main/java/io/quarkus/qute/ValueResolvers.java | 8 +++++--- .../core/src/test/java/io/quarkus/qute/SimpleTest.java | 8 ++++---- 2 files changed, 9 insertions(+), 7 deletions(-) diff --git a/independent-projects/qute/core/src/main/java/io/quarkus/qute/ValueResolvers.java b/independent-projects/qute/core/src/main/java/io/quarkus/qute/ValueResolvers.java index f75046c764690..789ed41a0cc62 100644 --- a/independent-projects/qute/core/src/main/java/io/quarkus/qute/ValueResolvers.java +++ b/independent-projects/qute/core/src/main/java/io/quarkus/qute/ValueResolvers.java @@ -119,13 +119,15 @@ public static ValueResolver orEmpty() { return new ValueResolver() { public boolean appliesTo(EvalContext context) { - return (context.getBase() == null || Results.Result.NOT_FOUND.equals(context.getBase())) - && context.getName().equals("orEmpty"); + return context.getParams().isEmpty() && context.getName().equals("orEmpty"); } @Override public CompletionStage resolve(EvalContext context) { - return empty; + if (context.getBase() == null || Results.Result.NOT_FOUND.equals(context.getBase())) { + return empty; + } + return CompletableFuture.completedFuture(context.getBase()); } }; } diff --git a/independent-projects/qute/core/src/test/java/io/quarkus/qute/SimpleTest.java b/independent-projects/qute/core/src/test/java/io/quarkus/qute/SimpleTest.java index a5fe04945375a..f1c8b3154e68b 100644 --- a/independent-projects/qute/core/src/test/java/io/quarkus/qute/SimpleTest.java +++ b/independent-projects/qute/core/src/test/java/io/quarkus/qute/SimpleTest.java @@ -221,9 +221,9 @@ public void testConvenientDataMethods() { @Test public void testOrEmpty() { - Engine engine = Engine.builder().addDefaultSectionHelpers() - .addValueResolvers(ValueResolvers.mapResolver(), ValueResolvers.orEmpty()) - .build(); - assertEquals("STARTEND", engine.parse("START{#for pet in pets.orEmpty}...{/for}END").data("pets", null).render()); + Engine engine = Engine.builder().addDefaults().build(); + assertEquals("STARTEND::STARTJackEND", + engine.parse("START{#for pet in pets.orEmpty}...{/for}END::START{#for dog in dogs.orEmpty}{dog}{/for}END") + .data("pets", null, "dogs", Collections.singleton("Jack")).render()); } }