1 package org.apache.velocity.test; 2 17 18 import junit.framework.Test; 19 import junit.framework.TestCase; 20 import junit.framework.TestSuite; 21 import org.apache.velocity.app.VelocityEngine; 22 import org.apache.velocity.VelocityContext; 23 import org.apache.velocity.exception.ParseErrorException; 24 25 import java.io.StringWriter ; 26 27 34 public class ParserTestCase extends TestCase 35 { 36 public ParserTestCase(String testName) 37 { 38 super(testName); 39 } 40 41 public static Test suite() 42 { 43 return new TestSuite(ParserTestCase.class); 44 } 45 46 49 public void testEquals() 50 throws Exception 51 { 52 VelocityEngine ve = new VelocityEngine(); 53 54 ve.init(); 55 56 59 60 String template = "#if($a == $b) foo #end"; 61 62 ve.evaluate(new VelocityContext(), new StringWriter (), "foo", template); 63 64 67 68 template = "#if($a = $b) foo #end"; 69 70 try 71 { 72 ve.evaluate(new VelocityContext(), new StringWriter (), "foo", template); 73 assertTrue(false); 74 } 75 catch(ParseErrorException pe) 76 { 77 } 78 } 79 80 83 public void testMacro() 84 throws Exception 85 { 86 VelocityEngine ve = new VelocityEngine(); 87 88 ve.init(); 89 90 93 94 String template = "#macro(foo) foo #end"; 95 96 ve.evaluate(new VelocityContext(), new StringWriter (), "foo", template); 97 98 101 102 template = "#macro($x) foo #end"; 103 104 try 105 { 106 ve.evaluate(new VelocityContext(), new StringWriter (), "foo", template); 107 assertTrue(false); 108 } 109 catch(ParseErrorException pe) 110 { 111 } 112 } 113 114 118 public void testArgs() 119 throws Exception 120 { 121 VelocityEngine ve = new VelocityEngine(); 122 123 ve.init(); 124 125 128 129 String template = "#macro(foo) foo #end"; 130 131 ve.evaluate(new VelocityContext(), new StringWriter (), "foo", template); 132 133 136 137 template = "#foreach( $i in $woogie ) end #end"; 138 139 ve.evaluate(new VelocityContext(), new StringWriter (), "foo", template); 140 141 144 145 template = "#macro( foo $a) $a #end #foo(woogie)"; 146 147 try 148 { 149 ve.evaluate(new VelocityContext(), new StringWriter (), "foo", template); 150 assertTrue(false); 151 } 152 catch(ParseErrorException pe) 153 { 154 System.out.println("Caught pee!"); 155 } 156 } 157 158 } 159 | Popular Tags |