Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Qute - fix orEmpty resolver #15074

Merged
merged 1 commit into from
Feb 15, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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());
}
}