package org.apache.velocity.test;

/*
 * Licensed to the Apache Software Foundation (ASF) under one
 * or more contributor license agreements.  See the NOTICE file
 * distributed with this work for additional information
 * regarding copyright ownership.  The ASF licenses this file
 * to you under the Apache License, Version 2.0 (the
 * "License"); you may not use this file except in compliance
 * with the License.  You may obtain a copy of the License at
 *
 *   http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing,
 * software distributed under the License is distributed on an
 * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
 * KIND, either express or implied.  See the License for the
 * specific language governing permissions and limitations
 * under the License.    
 */

import junit.framework.TestCase;
import org.apache.velocity.VelocityContext;
import org.apache.velocity.context.InternalContextAdapterImpl;
import org.apache.velocity.context.ProxyVMContext;
import org.apache.velocity.runtime.RuntimeConstants;
import org.apache.velocity.runtime.RuntimeInstance;

/**
 * Tests scope of velocimacros with localscope setting. 
 * 
 * @author <a href="mailto:stephenh@chase3000.com">Stephen Habermann</a>
 * @version $Id$
 */
public class VMContextLocalscopeTestCase extends TestCase {

    private RuntimeInstance instance;

    public void setUp() throws Exception 
    {
        this.instance = new RuntimeInstance();
        this.instance.setProperty(RuntimeConstants.VM_CONTEXT_LOCALSCOPE, Boolean.TRUE);
        this.instance.init();
    }

    public void testLocalscopePutDoesntLeakButGetDoes() 
    {
        VelocityContext base = new VelocityContext();
        base.put("outsideVar", "value1");

        ProxyVMContext vm = new ProxyVMContext(new InternalContextAdapterImpl(base), this.instance, true);
        vm.put("newLocalVar", "value2");

        // New variable put doesn't leak
        assertNull(base.get("newLocalVar"));
        assertEquals("value2", vm.get("newLocalVar"));

        // But we can still get to "outsideVar"
        assertEquals("value1", vm.get("outsideVar"));

        // If we decide to try and set outsideVar it won't leak
        vm.put("outsideVar", "value3");
        assertEquals("value3", vm.get("outsideVar"));
        assertEquals("value1", base.get("outsideVar"));
    }

}

@@ -848,42 +848,8 @@
 /%0A%0D%0A
-import junit.framework.TestCase;%0D%0A
 impo
@@ -1328,16 +1328,20 @@
 extends 
+Base
 TestCase
@@ -1355,335 +1355,665 @@
    p
-rivate RuntimeInstance instance;%0D%0A%0D%0A    public void setUp() throws Exception %0D%0A    %7B%0D%0A        this.instance = new RuntimeInstance();%0D%0A        this.instance.setProperty(RuntimeConstants.VM_CONTEXT_LOCALSCOPE, Boolean.TRUE);%0D%0A        this.instance.init();%0D%0A    %7D%0D%0A%0D%0A    public void testLocalscopePutDoesntLeakButGetDoes() %0D%0A    %7B
+ublic VMContextLocalscopeTestCase(String name)%0D%0A    %7B%0D%0A        super(name);%0D%0A    %7D%0D%0A%0D%0A    public void testViaEval()%0D%0A    %7B%0D%0A        engine.setProperty(RuntimeConstants.VM_CONTEXT_LOCALSCOPE, Boolean.TRUE);%0D%0A        assertEvalEquals(%22$a%22, %22#macro(a)#set($a = 'b')#end#a$a%22);%0D%0A        context.put(%22b%22, %22b%22);%0D%0A        assertEvalEquals(%22b%22, %22#macro(b)$b#set($b = 'c')#end#b%22);%0D%0A        assertContextValue(%22b%22, %22b%22);%0D%0A    %7D%0D%0A%0D%0A    public void testLocalscopePutDoesntLeakButGetDoes() %0D%0A    %7B%0D%0A        RuntimeInstance instance = new RuntimeInstance();%0D%0A        instance.setProperty(RuntimeConstants.VM_CONTEXT_LOCALSCOPE, Boolean.TRUE);%0D%0A        instance.init();%0D%0A
 %0D%0A  
@@ -2137,16 +2137,29 @@
 ext vm =
+%0D%0A           
  new Pro
@@ -2212,13 +2212,8 @@
 e), 
-this.
 inst

update vm localscope test a bit