• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 package org.apache.velocity.test.issues;
2 
3 /*
4  * Licensed to the Apache Software Foundation (ASF) under one
5  * or more contributor license agreements.  See the NOTICE file
6  * distributed with this work for additional information
7  * regarding copyright ownership.  The ASF licenses this file
8  * to you under the Apache License, Version 2.0 (the
9  * "License"); you may not use this file except in compliance
10  * with the License.  You may obtain a copy of the License at
11  *
12  *   http://www.apache.org/licenses/LICENSE-2.0
13  *
14  * Unless required by applicable law or agreed to in writing,
15  * software distributed under the License is distributed on an
16  * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
17  * KIND, either express or implied.  See the License for the
18  * specific language governing permissions and limitations
19  * under the License.
20  */
21 
22 import org.apache.velocity.runtime.RuntimeConstants;
23 import org.apache.velocity.test.BaseTestCase;
24 
25 /**
26  * This class tests VELOCITY-682.
27  */
28 public class Velocity682TestCase extends BaseTestCase
29 {
Velocity682TestCase(String name)30     public Velocity682TestCase(String name)
31     {
32         super(name);
33         //DEBUG = true;
34     }
35 
test682()36     public void test682()
37     {
38         engine.setProperty(RuntimeConstants.VM_PERM_INLINE_LOCAL, Boolean.TRUE);
39         assertEvalEquals("foo1foo2", "#macro(eval $e)#evaluate($e)#end#eval('foo1')#eval('foo2')");
40     }
41 
test682b()42     public void test682b()
43     {
44         String template = "#macro( eval $e )#evaluate($e)#end" +
45                           "#eval('foo')" +
46                           "#eval('bar')";
47         String expected = "foo"+
48                           "bar";
49         assertEvalEquals(expected, template);
50     }
51 
test682c()52     public void test682c()
53     {
54         //NOTE: #eval call is apparently swallowing preceding newlines. :(
55         //      appears to be a parser issue unrelated to VELOCITY-682
56         String template = "#macro( eval $e )#evaluate($e)#end" +
57                           "\n#eval('foo')" +
58                           "\n\n#eval('bar')";
59         String expected = "foo"+
60                           "\nbar";
61         assertEvalEquals(expected, template);
62     }
63 }
64