Skip to content

Commit

Permalink
Merge pull request #844 from mP1/feature/BasicExpressionEvaluationCon…
Browse files Browse the repository at this point in the history
…text-context-ExpressionEvaluationContexts-scoped

BasicExpressionEvaluationContext.context ExpressionEvaluationContexts…
  • Loading branch information
mP1 authored Jan 11, 2025
2 parents 6641040 + cbab58b commit dcf313d
Show file tree
Hide file tree
Showing 2 changed files with 39 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -172,7 +172,10 @@ public Object evaluate(final Expression expression) {

@Override
public ExpressionEvaluationContext context(final Function<ExpressionReference, Optional<Optional<Object>>> resolver) {
throw new UnsupportedOperationException("https://github.com/mP1/walkingkooka-tree/issues/599");
return ExpressionEvaluationContexts.scoped(
resolver,
this
);
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -503,6 +503,41 @@ public void testReferenceNotFound() {
);
}

// context..........................................................................................................

@Test
public void testContextWithGlobalReference() {
this.referenceAndCheck(
this.createContext()
.context(
r -> Optional.empty() // no locals
),
REFERENCE,
REFERENCE_VALUE
);
}

@Test
public void testContextWithLocalReference() {
final ExpressionReference reference = new FakeExpressionReference();
final String value = "*reference value*";

this.referenceAndCheck(
this.createContext()
.context(
r -> r.equals(reference) ?
Optional.of(
Optional.of(value)
) :
Optional.empty()
),
reference,
value
);
}

// convert..........................................................................................................

@Test
public void testConvert() {
this.convertAndCheck(123.0, Long.class, 123L);
Expand Down

0 comments on commit dcf313d

Please sign in to comment.