@Test public void testPopulatedNestedScopes() { ExpressionState state = getState(); assertNull(state.lookupLocalVariable("foo")); state.enterScope("foo",34); assertEquals(34, state.lookupLocalVariable("foo")); state.enterScope(null); state.setLocalVariable("foo", 12); assertEquals(12, state.lookupLocalVariable("foo")); state.exitScope(); assertEquals(34, state.lookupLocalVariable("foo")); state.exitScope(); assertNull(state.lookupLocalVariable("goo")); }
@Test public void testPopulatedNestedScopesMap() { ExpressionState state = getState(); assertNull(state.lookupLocalVariable("foo")); assertNull(state.lookupLocalVariable("goo")); Map<String,Object> m = new HashMap<>(); m.put("foo", 34); m.put("goo", "abc"); state.enterScope(m); assertEquals(34, state.lookupLocalVariable("foo")); assertEquals("abc", state.lookupLocalVariable("goo")); state.enterScope(null); state.setLocalVariable("foo",12); assertEquals(12, state.lookupLocalVariable("foo")); assertEquals("abc", state.lookupLocalVariable("goo")); state.exitScope(); state.exitScope(); assertNull(state.lookupLocalVariable("foo")); assertNull(state.lookupLocalVariable("goo")); }
@Test public void testLocalVariableNestedScopes() { ExpressionState state = getState(); assertEquals(null, state.lookupLocalVariable("foo")); state.setLocalVariable("foo",12); assertEquals(12, state.lookupLocalVariable("foo")); state.enterScope(null); assertEquals(12, state.lookupLocalVariable("foo")); // found in upper scope state.setLocalVariable("foo","abc"); assertEquals("abc", state.lookupLocalVariable("foo")); // found in nested scope state.exitScope(); assertEquals(12, state.lookupLocalVariable("foo")); // found in nested scope }