You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@velocity.apache.org by nb...@apache.org on 2009/03/03 19:41:39 UTC

svn commit: r749686 - in /velocity/engine/trunk/src: java/org/apache/velocity/ java/org/apache/velocity/runtime/ java/org/apache/velocity/runtime/directive/ test/org/apache/velocity/test/

Author: nbubna
Date: Tue Mar  3 18:41:38 2009
New Revision: 749686

URL: http://svn.apache.org/viewvc?rev=749686&view=rev
Log:
VELOCITY-704 : #break -> stop inner scope, #break($<scope>) -> stop specified scope, #stop -> stop topmost scope, #stop($msg) -> stop topmost scope w/message

Added:
    velocity/engine/trunk/src/test/org/apache/velocity/test/BreakDirectiveTestCase.java
      - copied, changed from r740994, velocity/engine/trunk/src/test/org/apache/velocity/test/ForeachBreakTestCase.java
Removed:
    velocity/engine/trunk/src/test/org/apache/velocity/test/ForeachBreakTestCase.java
Modified:
    velocity/engine/trunk/src/java/org/apache/velocity/Template.java
    velocity/engine/trunk/src/java/org/apache/velocity/runtime/RuntimeInstance.java
    velocity/engine/trunk/src/java/org/apache/velocity/runtime/directive/Break.java
    velocity/engine/trunk/src/java/org/apache/velocity/runtime/directive/Directive.java
    velocity/engine/trunk/src/java/org/apache/velocity/runtime/directive/Evaluate.java
    velocity/engine/trunk/src/java/org/apache/velocity/runtime/directive/Stop.java
    velocity/engine/trunk/src/java/org/apache/velocity/runtime/directive/StopCommand.java
    velocity/engine/trunk/src/test/org/apache/velocity/test/ScopeTestCase.java
    velocity/engine/trunk/src/test/org/apache/velocity/test/StopDirectiveTestCase.java

Modified: velocity/engine/trunk/src/java/org/apache/velocity/Template.java
URL: http://svn.apache.org/viewvc/velocity/engine/trunk/src/java/org/apache/velocity/Template.java?rev=749686&r1=749685&r2=749686&view=diff
==============================================================================
--- velocity/engine/trunk/src/java/org/apache/velocity/Template.java (original)
+++ velocity/engine/trunk/src/java/org/apache/velocity/Template.java Tue Mar  3 18:41:38 2009
@@ -361,6 +361,10 @@
                 {
                     throw stop;
                 }
+                else if (rsvc.getLog().isDebugEnabled())
+                {
+                    rsvc.getLog().debug(stop.getMessage());
+                }
             }
             catch (IOException e)
             {

Modified: velocity/engine/trunk/src/java/org/apache/velocity/runtime/RuntimeInstance.java
URL: http://svn.apache.org/viewvc/velocity/engine/trunk/src/java/org/apache/velocity/runtime/RuntimeInstance.java?rev=749686&r1=749685&r2=749686&view=diff
==============================================================================
--- velocity/engine/trunk/src/java/org/apache/velocity/runtime/RuntimeInstance.java (original)
+++ velocity/engine/trunk/src/java/org/apache/velocity/runtime/RuntimeInstance.java Tue Mar  3 18:41:38 2009
@@ -1370,6 +1370,10 @@
                 {
                     throw stop;
                 }
+                else if (getLog().isDebugEnabled())
+                {
+                    getLog().debug(stop.getMessage());
+                }
             }
             catch (IOException e)
             {

Modified: velocity/engine/trunk/src/java/org/apache/velocity/runtime/directive/Break.java
URL: http://svn.apache.org/viewvc/velocity/engine/trunk/src/java/org/apache/velocity/runtime/directive/Break.java?rev=749686&r1=749685&r2=749686&view=diff
==============================================================================
--- velocity/engine/trunk/src/java/org/apache/velocity/runtime/directive/Break.java (original)
+++ velocity/engine/trunk/src/java/org/apache/velocity/runtime/directive/Break.java Tue Mar  3 18:41:38 2009
@@ -19,31 +19,23 @@
  * under the License.    
  */
 
-import java.io.IOException;
 import java.io.Writer;
 import org.apache.velocity.context.InternalContextAdapter;
-import org.apache.velocity.exception.MethodInvocationException;
-import org.apache.velocity.exception.ParseErrorException;
-import org.apache.velocity.exception.ResourceNotFoundException;
-import org.apache.velocity.exception.TemplateInitException;
 import org.apache.velocity.exception.VelocityException;
 import org.apache.velocity.runtime.RuntimeServices;
 import org.apache.velocity.runtime.log.Log;
-import org.apache.velocity.runtime.parser.node.ASTDirective;
 import org.apache.velocity.runtime.parser.node.Node;
 
 /**
- * Break directive used for interrupting foreach loops.
+ * Break directive used for interrupting scopes.
  *
  * @author <a href="mailto:wyla@removethis.sci.fi">Jarkko Viinamaki</a>
- * @deprecated use {@link Stop} with {@link ForeachScope} (e.g. #stop($foreach) )
+ * @author Nathan Bubna
  * @version $Id$
  */
 public class Break extends Directive
 {
-    private static final BreakCommand BREAK = new BreakCommand();
-
-    private boolean warned = false;
+    private boolean scoped = false;
 
     /**
      * Return name of this directive.
@@ -81,75 +73,52 @@
      * @throws TemplateInitException
      */
     public void init(RuntimeServices rs, InternalContextAdapter context, Node node)
-        throws TemplateInitException
     {
         super.init(rs, context, node);
 
-        // Make sure the #break directive is within a foreach block.
-        Node check = node;
-        while (!(check instanceof ASTDirective) ||
-               !((ASTDirective)check).getDirectiveName().equals("foreach"))
-        {
-            check = check.jjtGetParent();
-            if (check == null)
-            {
-                // We are not in a macro definition, so throw an exception.
-                throw new VelocityException("#break must be within a #foreach block at " 
-                    + Log.formatFileString(this));
-            }
+        int kids = node.jjtGetNumChildren();
+        if (kids > 1)
+        {  
+            throw new VelocityException("The #stop directive only accepts a single scope object at "
+                 + Log.formatFileString(this));
         }
-
-        // give deprecation warning once per instance, not on every merge
-        if (!warned)
+        else
         {
-            warned = true;
-            if (rs.getLog().isWarnEnabled())
-            {
-                rs.getLog().warn("#break has been deprecated and will be removed in Velocity 2.0; please use #stop($foreach) instead.");
-            }
+            this.scoped = (kids == 1);
         }
     }
 
     /**
      * Break directive does not actually do any rendering. 
      * 
-     * This directive throws a BreakCommand which
-     * signals foreach directive to break out of the loop. Note that this
-     * directive does not verify that it is being called inside a foreach
-     * loop.
+     * This directive throws a StopCommand which signals either
+     * the nearest Scope or the specified scope to stop rendering
+     * its content.
      * 
      * @param context
      * @param writer
      * @param node
-     * @return true if the directive rendered successfully.
-     * @throws IOException
-     * @throws MethodInvocationException
-     * @throws ResourceNotFoundException
-     * @throws ParseErrorException
+     * @return never, always throws a StopCommand
      */
-    public boolean render(InternalContextAdapter context,
-                           Writer writer, Node node)
-        throws IOException,  MethodInvocationException, ResourceNotFoundException,
-        	ParseErrorException
+    public boolean render(InternalContextAdapter context, Writer writer, Node node)
     {
-        throw BREAK;
-    }
-    
-    /**
-     * Specialized StopCommand that stops the nearest #foreach loop.
-     */
-    public static class BreakCommand extends StopCommand 
-    {
-        public BreakCommand()
+        if (!scoped)
         {
-            // If a break is thrown during a macro or parse call, then this exception
-            // will eventually be seen, so provide the user with some info.
-            super("closest #foreach loop");
+            throw new StopCommand();
         }
 
-        public boolean isFor(Object that)
+        Object argument = node.jjtGetChild(0).value(context);
+        if (argument instanceof Scope)
+        {
+            ((Scope)argument).stop();
+        }
+        else
         {
-            return (that instanceof Foreach);
+            throw new VelocityException(node.jjtGetChild(0).literal()+
+                " is not a valid " + Scope.class.getName() + " instance at "
+                + Log.formatFileString(this));
         }
+        return false;
     }
+
 }

Modified: velocity/engine/trunk/src/java/org/apache/velocity/runtime/directive/Directive.java
URL: http://svn.apache.org/viewvc/velocity/engine/trunk/src/java/org/apache/velocity/runtime/directive/Directive.java?rev=749686&r1=749685&r2=749686&view=diff
==============================================================================
--- velocity/engine/trunk/src/java/org/apache/velocity/runtime/directive/Directive.java (original)
+++ velocity/engine/trunk/src/java/org/apache/velocity/runtime/directive/Directive.java Tue Mar  3 18:41:38 2009
@@ -215,5 +215,5 @@
             }
         }
     }
-                
+
 }

Modified: velocity/engine/trunk/src/java/org/apache/velocity/runtime/directive/Evaluate.java
URL: http://svn.apache.org/viewvc/velocity/engine/trunk/src/java/org/apache/velocity/runtime/directive/Evaluate.java?rev=749686&r1=749685&r2=749686&view=diff
==============================================================================
--- velocity/engine/trunk/src/java/org/apache/velocity/runtime/directive/Evaluate.java (original)
+++ velocity/engine/trunk/src/java/org/apache/velocity/runtime/directive/Evaluate.java Tue Mar  3 18:41:38 2009
@@ -210,6 +210,10 @@
                     {
                         throw stop;
                     }
+                    else if (rsvc.getLog().isDebugEnabled())
+                    {
+                        rsvc.getLog().debug(stop.getMessage());
+                    }
                 }
                 catch (ParseErrorException pex)
                 {

Modified: velocity/engine/trunk/src/java/org/apache/velocity/runtime/directive/Stop.java
URL: http://svn.apache.org/viewvc/velocity/engine/trunk/src/java/org/apache/velocity/runtime/directive/Stop.java?rev=749686&r1=749685&r2=749686&view=diff
==============================================================================
--- velocity/engine/trunk/src/java/org/apache/velocity/runtime/directive/Stop.java (original)
+++ velocity/engine/trunk/src/java/org/apache/velocity/runtime/directive/Stop.java Tue Mar  3 18:41:38 2009
@@ -20,7 +20,6 @@
  */
 
 import java.io.Writer;
-import org.apache.velocity.Template;
 import org.apache.velocity.context.InternalContextAdapter;
 import org.apache.velocity.exception.VelocityException;
 import org.apache.velocity.runtime.RuntimeInstance;
@@ -30,18 +29,15 @@
 
 /**
  * This class implements the #stop directive which allows
- * a user to stop rendering the current execution context. The #stop directive
- * with no arguments will immediately stop rendering the current Template merge
- * or evaluate(...) call.
- * If the stop directive is called with a Scope argument, e.g.; #stop($foreach),
- * then rendering will end within that particular directive, but resume at 
- * the parent level.
+ * a user to stop the merging and rendering process. The #stop directive
+ * will accept a single message argument with info about the reason for
+ * stopping.
  */
 public class Stop extends Directive
 {  
-    private static final StopCommand STOP_ALL = new StopAllCommand();
+    private static final StopCommand STOP_ALL = new StopCommand("StopCommand to exit merging");
 
-    private boolean scopedStop = false;
+    private boolean hasMessage = false;
 
     /**
      * Return name of this directive.
@@ -77,54 +73,27 @@
         int kids = node.jjtGetNumChildren();
         if (kids > 1)
         {  
-            throw new VelocityException("The #stop directive only accepts a single scope object at "
+            throw new VelocityException("The #stop directive only accepts a single message parameter at "
                  + Log.formatFileString(this));
         }
         else
         {
-            this.scopedStop = (kids == 1);
+            hasMessage = (kids == 1);
         }
     }
 
     public boolean render(InternalContextAdapter context, Writer writer, Node node)
     {
-        if (!scopedStop)
+        if (!hasMessage)
         {
-            // Only the top level calls that render an AST node tree catch and keep
-            // this, thereby terminating at Template.merge or RuntimeInstance.evaluate.
             throw STOP_ALL;
         }
 
         Object argument = node.jjtGetChild(0).value(context);
-        if (argument instanceof Scope)
-        {
-            ((Scope)argument).stop();
-        }
-        else
-        {
-            throw new VelocityException(node.jjtGetChild(0).literal()+" is not a valid Scope instance at "
-                + Log.formatFileString(this));
-        }
-        return false;
-    }
-
-    /**
-     * Specialized StopCommand that stops all merge or evaluate activity.
-     */
-    public static class StopAllCommand extends StopCommand
-    {
-        public StopAllCommand()
-        {
-            super("Template.merge or RuntimeInstance.evaluate");
-        }
 
-        public boolean isFor(Object that)
-        {
-            // only stop for the top :)
-            return (that instanceof Template ||
-                    that instanceof RuntimeInstance ||
-                    that instanceof Evaluate);
-        }
+        // stop all and use specified message
+        throw new StopCommand(String.valueOf(argument));
     }
+
 }
 

Modified: velocity/engine/trunk/src/java/org/apache/velocity/runtime/directive/StopCommand.java
URL: http://svn.apache.org/viewvc/velocity/engine/trunk/src/java/org/apache/velocity/runtime/directive/StopCommand.java?rev=749686&r1=749685&r2=749686&view=diff
==============================================================================
--- velocity/engine/trunk/src/java/org/apache/velocity/runtime/directive/StopCommand.java (original)
+++ velocity/engine/trunk/src/java/org/apache/velocity/runtime/directive/StopCommand.java Tue Mar  3 18:41:38 2009
@@ -19,6 +19,10 @@
  * under the License.    
  */
 
+import org.apache.velocity.Template;
+import org.apache.velocity.runtime.RuntimeInstance;
+import org.apache.velocity.runtime.directive.Evaluate;
+
 /**
  * Stop command for directive Control objects.  In an ideal JDK,
  * this would be able to extend a RuntimeThrowable class, but we
@@ -33,6 +37,17 @@
 public class StopCommand extends Error
 {
     private Object stopMe;
+    private boolean nearest = false;
+
+    public StopCommand()
+    {
+        this.nearest = true;
+    }
+
+    public StopCommand(String message)
+    {
+        super(message);
+    }
 
     public StopCommand(Object stopMe)
     {
@@ -41,12 +56,34 @@
 
     public String getMessage()
     {
-        // only create a useful message if requested (which is unlikely)
-        return "StopCommand for "+stopMe;
+        if (stopMe != null)
+        {
+            // only create a useful message if requested (which is unlikely)
+            return "StopCommand: "+stopMe;
+        }
+        else
+        {
+            return "StopCommand: "+super.getMessage();
+        }
     }
 
     public boolean isFor(Object that)
     {
-        return (that == stopMe);
+        if (nearest) // if we're stopping at the first chance
+        {
+            // save that for message
+            stopMe = that;
+            return true;
+        }
+        else if (stopMe != null) // if we have a specified stopping point
+        {
+            return (that == stopMe);
+        }
+        else // only stop for the top :)
+        {
+            return (that instanceof Template ||
+                    that instanceof RuntimeInstance ||
+                    that instanceof Evaluate);
+        }
     }
 }

Copied: velocity/engine/trunk/src/test/org/apache/velocity/test/BreakDirectiveTestCase.java (from r740994, velocity/engine/trunk/src/test/org/apache/velocity/test/ForeachBreakTestCase.java)
URL: http://svn.apache.org/viewvc/velocity/engine/trunk/src/test/org/apache/velocity/test/BreakDirectiveTestCase.java?p2=velocity/engine/trunk/src/test/org/apache/velocity/test/BreakDirectiveTestCase.java&p1=velocity/engine/trunk/src/test/org/apache/velocity/test/ForeachBreakTestCase.java&r1=740994&r2=749686&rev=749686&view=diff
==============================================================================
--- velocity/engine/trunk/src/test/org/apache/velocity/test/ForeachBreakTestCase.java (original)
+++ velocity/engine/trunk/src/test/org/apache/velocity/test/BreakDirectiveTestCase.java Tue Mar  3 18:41:38 2009
@@ -20,35 +20,86 @@
  */
 
 /**
- * This class tests the break directive within Foreach loop.
+ * This class tests the break directive.
  */
-public class ForeachBreakTestCase extends BaseTestCase
+public class BreakDirectiveTestCase extends BaseTestCase
 {
-    public ForeachBreakTestCase(String name)
+    public BreakDirectiveTestCase(String name)
     {
         super(name);
     }
-    
-    /**
-     * Tests break directive with a couple of iterations.
-     */
-    public void testConditionalBreakDirective()
+
+    public void testBadArgs()
+    {
+        context.put("foo","foo");
+        assertEvalException("#break($null)");
+        assertEvalException("#break($foo)");
+        assertEvalException("#break(true)");
+        assertEvalException("#break(1.2)");
+        assertEvalException("#break([0..1])");
+        assertEvalException("#break( $too $many )");
+    }
+
+    public void testStopForeach()
     {
+        String template = "#foreach($i in [1..5])$i#if($i>2)#break($foreach)#end#end test";
+        assertEvalEquals("123 test", template);
+
+        // only inner should be stopped, not outer
+        String t2 = "#foreach($j in [1..2])"+template+"#end";
+        assertEvalEquals("123 test123 test", t2);
+
+        // stop outer using #break($foreach.parent)
+        String t3 = "#foreach($i in [1..2])#foreach($j in [2..3])$i$j#if($i+$j==5)#break($foreach.parent)#end#end test#end";
+        assertEvalEquals("1213 test2223", t3);
+
+        // without specifying scope...
         assertEvalEquals("1, 2, 3, 4, 5",
                          "#foreach($i in [1..10])$i#if($i > 4)#break#end, #end");
+        assertEvalEquals("1", "#foreach($i in [1..5])$i#break #end");
+        assertEvalEquals("~~~, ~~, ~, ",
+            "#foreach($i in [1..3])#foreach($j in [2..4])#if($i*$j >= 8)#break#end~#end, #end");
     }
 
-    /**
-     * Tests break directive with immediate break.
-     */
-    public void testUnconditionalBreakDirective()
+    public void testStopTemplate()
     {
-        assertEvalEquals("1", "#foreach($i in [1..5])$i#break #end");
+        addTemplate("a", "a#break($template)b");
+        assertTmplEquals("a", "a");
+        assertEvalEquals("ac", "#parse('a')c");
+
+        addTemplate("b", "b#{break}a");
+        assertTmplEquals("b", "b");
     }
 
-    public void testNestedForeach()
+    public void testStopEvaluate()
     {
-        assertEvalEquals("~~~, ~~, ~, ",
-            "#foreach($i in [1..3])#foreach($j in [2..4])#if($i*$j >= 8)#break#end~#end, #end");
+        assertEvalEquals("a", "a#break($evaluate)b");
+        assertEvalEquals("a", "#evaluate('a#break($evaluate)b')");
+        assertEvalEquals("a", "a#evaluate('#break($evaluate.topmost)')b");
+        assertEvalEquals("a", "a#{break}b");
+    }
+
+    public void testStopDefineBlock()
+    {
+        assertEvalEquals("a", "#define($a)a#break($define)b#end$a");
+        assertEvalEquals("aa", "#define($a)a#break($define.parent)b#end#define($b)a${a}b#end$b");
+        assertEvalEquals("a", "#define($a)a#{break}b#end$a");
+    }
+
+    public void testStopMacro()
+    {
+        assertEvalEquals("a ", "#macro(a)a #break($macro) b#end#a");
+        assertEvalEquals("b c ", "#macro(c)c #break($macro.parent) d#end"+
+                               "#macro(b)b #c c#end"+
+                               "#b");
+        assertEvalEquals("d", "#macro(d)d#{break}e#end#d");
+    }
+
+    public void testStopMacroBodyBlock()
+    {
+        assertEvalEquals(" a ", "#macro(a) $bodyContent #end"+
+                                "#@a()a#break($a)b#end");
+        assertEvalEquals(" b ", "#macro(b) $bodyContent #end"+
+                                "#@b()b#{break}c#end");
     }
 }

Modified: velocity/engine/trunk/src/test/org/apache/velocity/test/ScopeTestCase.java
URL: http://svn.apache.org/viewvc/velocity/engine/trunk/src/test/org/apache/velocity/test/ScopeTestCase.java?rev=749686&r1=749685&r2=749686&view=diff
==============================================================================
--- velocity/engine/trunk/src/test/org/apache/velocity/test/ScopeTestCase.java (original)
+++ velocity/engine/trunk/src/test/org/apache/velocity/test/ScopeTestCase.java Tue Mar  3 18:41:38 2009
@@ -36,7 +36,7 @@
 
     public void testRootTemplateMergeScope()
     {
-        addTemplate("foo", "foo#stop($template)bar");
+        addTemplate("foo", "foo#break($template)bar");
         assertTmplEquals("foo", "foo");
         assertNull(context.get("template"));
     }
@@ -47,7 +47,7 @@
                             "$!parse.parent.depth"+
                             "#set( $template.foo = 'bar' )"+
                             "$template.foo"+
-                            "#stop($template)"+
+                            "#break($template)"+
                             "woogie");
         assertEvalEquals("1bar", "#parse( 'test' )");
         assertNull(context.get("template"));
@@ -61,7 +61,7 @@
         addTemplate("inner", "Inner depth: $template.depth"+
                              "#set( $template.foo = '?' )"+
                              "$!grab.put('inner',$template)"+
-                             "#stop($template)$template.foo");
+                             "#break($template)$template.foo");
         addTemplate("outer", "#set( $template.foo = '!' )"+
                              "Outer depth: $template.depth "+
                              "#parse('inner')"+
@@ -84,7 +84,7 @@
     public void testForeachScope()
     {
         String template = "#foreach( $i in [0..2] )"+
-                          "#if( $i > 1 )#stop($foreach)#end"+
+                          "#if( $i > 1 )#break($foreach)#end"+
                           "$foreach.index:$foreach.count:$foreach.hasNext,"+
                           "#end";
         assertEvalEquals("0:1:true,1:2:true,", template);
@@ -95,7 +95,7 @@
     {
         String template = "#foreach( $i in [1..5] )"+
                             "#foreach( $j in [1..2] )"+
-                              "#if ( $i > $foreach.count + $foreach.index + $foreach.depth )#stop($foreach.topmost)#end"+
+                              "#if ( $i > $foreach.count + $foreach.index + $foreach.depth )#break($foreach.topmost)#end"+
                             "#end"+
                             "$i"+
                           "#end";
@@ -106,7 +106,7 @@
     public void testMacroScope()
     {
         String template = "#macro( foo $i )"+
-                          "#if($i > 2 )#stop($macro)#end"+
+                          "#if($i > 2 )#break($macro)#end"+
                           "$i#end"+
                           "#foo( 0 )#foo( 1 )#foo( 2 )";
         assertEvalEquals("012", template);
@@ -116,7 +116,7 @@
     public void testRecursiveMacroScope()
     {
         String template = "#macro( foo )$macro.depth"+
-                          "#if($macro.depth > 2 )#stop($macro.topmost)#end"+
+                          "#if($macro.depth > 2 )#break($macro.topmost)#end"+
                           "#foo()#end#foo()";
         assertEvalEquals("123", template);
         assertNull(context.get("macro"));
@@ -162,7 +162,7 @@
     public void testNestedDefineScope()
     {
         String template = "#define($a)$b c#end"+
-                          "#define($b)$define.depth#stop($define.topmost)#end"+
+                          "#define($b)$define.depth#break($define.topmost)#end"+
                           "$a";
         assertEvalEquals("2", template);
         assertNull(context.get("define"));
@@ -172,7 +172,7 @@
     {
         engine.setProperty(RuntimeConstants.DEFINE_DIRECTIVE_MAXDEPTH, "10");
         String template = "#define($a)$define.depth"+
-                          "#if($define.depth == 5)#stop($define)#end,$a#end$a";
+                          "#if($define.depth == 5)#break($define)#end,$a#end$a";
         assertEvalEquals("1,2,3,4,5", template);
         assertNull(context.get("define"));
     }
@@ -180,7 +180,7 @@
     public void testRootEvaluateScope()
     {
         assertEvalEquals("1", "$evaluate.depth");
-        assertEvalEquals("foo", "foo#stop($evaluate)bar");
+        assertEvalEquals("foo", "foo#break($evaluate)bar");
         assertNull(context.get("evaluate"));
     }
 

Modified: velocity/engine/trunk/src/test/org/apache/velocity/test/StopDirectiveTestCase.java
URL: http://svn.apache.org/viewvc/velocity/engine/trunk/src/test/org/apache/velocity/test/StopDirectiveTestCase.java?rev=749686&r1=749685&r2=749686&view=diff
==============================================================================
--- velocity/engine/trunk/src/test/org/apache/velocity/test/StopDirectiveTestCase.java (original)
+++ velocity/engine/trunk/src/test/org/apache/velocity/test/StopDirectiveTestCase.java Tue Mar  3 18:41:38 2009
@@ -20,6 +20,7 @@
  */
 
 import org.apache.velocity.test.BaseTestCase;
+import org.apache.velocity.test.misc.TestLogChute;
 import org.apache.velocity.runtime.RuntimeConstants;
 
 /**
@@ -51,17 +52,6 @@
       assertTmplEquals("text1blaa1", "stop3.vm");
     }
 
-    public void testBadStopArgs()
-    {
-        context.put("foo","foo");
-        assertEvalException("#stop($null)");
-        assertEvalException("#stop($foo)");
-        assertEvalException("#stop(true)");
-        assertEvalException("#stop(1.2)");
-        assertEvalException("#stop([0..1])");
-        assertEvalException("#stop( $too $many )");
-    }
-
     public void testNestedStopAll()
     {
         addTemplate("ns", ",template"+
@@ -78,51 +68,16 @@
         assertEvalEquals(expected, "#evaluate('evaluate#parse(\"ns\")evaluate')");
     }
 
-    public void testStopForeach()
-    {
-        String template = "#foreach($i in [1..5])$i#if($i>2)#stop($foreach)#end#end test";
-        assertEvalEquals("123 test", template);
-
-        // only inner should be stopped, not outer
-        String t2 = "#foreach($j in [1..2])"+template+"#end";
-        assertEvalEquals("123 test123 test", t2);
-
-        // stop outer using #stop($foreach.parent)
-        String t3 = "#foreach($i in [1..2])#foreach($j in [2..3])$i$j#if($i+$j==5)#stop($foreach.parent)#end#end test#end";
-        assertEvalEquals("1213 test2223", t3);
-    }
-
-    public void testStopTemplate()
-    {
-        addTemplate("a", "a#stop($template)b");
-        assertTmplEquals("a", "a");
-        assertEvalEquals("ac", "#parse('a')c");
-    }
-
-    public void testStopEvaluate()
+    public void testStopMessage()
     {
-        assertEvalEquals("a", "a#stop($evaluate)b");
-        assertEvalEquals("a", "#evaluate('a#stop($evaluate)b')");
-        assertEvalEquals("a", "a#evaluate('#stop($evaluate.topmost)')b");
-    }
+        log.setEnabledLevel(TestLogChute.DEBUG_ID);
+        log.off();
+        context.put("log", log);
 
-    public void testStopDefineBlock()
-    {
-        assertEvalEquals("a", "#define($a)a#stop($define)b#end$a");
-        assertEvalEquals("aa", "#define($a)a#stop($define.parent)b#end#define($b)a${a}b#end$b");
-    }
+        assertEvalEquals("a", "a$!log.startCapture()#stop('woogie!')b");
 
-    public void testStopMacro()
-    {
-        assertEvalEquals("a ", "#macro(a)a #stop($macro) b#end#a");
-        assertEvalEquals("b c ", "#macro(c)c #stop($macro.parent) d#end"+
-                               "#macro(b)b #c c#end"+
-                               "#b");
+        info("Log: "+log.getLog());
+        assertTrue(log.getLog().contains("StopCommand: woogie!"));
     }
 
-    public void testStopMacroBodyBlock()
-    {
-        assertEvalEquals(" a ", "#macro(a) $bodyContent #end"+
-                                "#@a()a#stop($a)b#end");
-    }
 }
\ No newline at end of file