Skip to content

Commit

Permalink
Qute - fix orEmpty resolver
Browse files Browse the repository at this point in the history
  • Loading branch information
mkouba committed Feb 15, 2021
1 parent 9170b6f commit 3aec5b0
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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<Object> resolve(EvalContext context) {
return empty;
if (context.getBase() == null || Results.Result.NOT_FOUND.equals(context.getBase())) {
return empty;
}
return CompletableFuture.completedFuture(context.getBase());
}
};
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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());
}
}

0 comments on commit 3aec5b0

Please sign in to comment.