diff --git a/src/main/java/walkingkooka/tree/expression/BasicExpressionEvaluationContext.java b/src/main/java/walkingkooka/tree/expression/BasicExpressionEvaluationContext.java index 8fce2461..ac9fb1d7 100644 --- a/src/main/java/walkingkooka/tree/expression/BasicExpressionEvaluationContext.java +++ b/src/main/java/walkingkooka/tree/expression/BasicExpressionEvaluationContext.java @@ -172,7 +172,10 @@ public Object evaluate(final Expression expression) { @Override public ExpressionEvaluationContext context(final Function>> resolver) { - throw new UnsupportedOperationException("https://github.com/mP1/walkingkooka-tree/issues/599"); + return ExpressionEvaluationContexts.scoped( + resolver, + this + ); } @Override diff --git a/src/test/java/walkingkooka/tree/expression/BasicExpressionEvaluationContextTest.java b/src/test/java/walkingkooka/tree/expression/BasicExpressionEvaluationContextTest.java index 9aee512f..75efb79f 100644 --- a/src/test/java/walkingkooka/tree/expression/BasicExpressionEvaluationContextTest.java +++ b/src/test/java/walkingkooka/tree/expression/BasicExpressionEvaluationContextTest.java @@ -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);