velocity-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From nbu...@apache.org
Subject svn commit: r712887 - in /velocity/engine/trunk/src: java/org/apache/velocity/runtime/parser/node/ASTAddNode.java test/org/apache/velocity/test/StringConcatenationTestCase.java
Date Tue, 11 Nov 2008 00:27:51 GMT
Author: nbubna
Date: Mon Nov 10 16:27:50 2008
New Revision: 712887

URL: http://svn.apache.org/viewvc?rev=712887&view=rev
Log:
add string concatenation tests and fix NPE when concatenating string with null reference

Added:
    velocity/engine/trunk/src/test/org/apache/velocity/test/StringConcatenationTestCase.java
  (with props)
Modified:
    velocity/engine/trunk/src/java/org/apache/velocity/runtime/parser/node/ASTAddNode.java

Modified: velocity/engine/trunk/src/java/org/apache/velocity/runtime/parser/node/ASTAddNode.java
URL: http://svn.apache.org/viewvc/velocity/engine/trunk/src/java/org/apache/velocity/runtime/parser/node/ASTAddNode.java?rev=712887&r1=712886&r2=712887&view=diff
==============================================================================
--- velocity/engine/trunk/src/java/org/apache/velocity/runtime/parser/node/ASTAddNode.java
(original)
+++ velocity/engine/trunk/src/java/org/apache/velocity/runtime/parser/node/ASTAddNode.java
Mon Nov 10 16:27:50 2008
@@ -61,6 +61,14 @@
          */
         if (left instanceof String || right instanceof String)
         {
+            if (left == null)
+            {
+                left = jjtGetChild(0).literal();
+            }
+            else if (right == null)
+            {
+                right = jjtGetChild(1).literal();
+            }
             return left.toString().concat(right.toString());
         }
         return null;

Added: velocity/engine/trunk/src/test/org/apache/velocity/test/StringConcatenationTestCase.java
URL: http://svn.apache.org/viewvc/velocity/engine/trunk/src/test/org/apache/velocity/test/StringConcatenationTestCase.java?rev=712887&view=auto
==============================================================================
--- velocity/engine/trunk/src/test/org/apache/velocity/test/StringConcatenationTestCase.java
(added)
+++ velocity/engine/trunk/src/test/org/apache/velocity/test/StringConcatenationTestCase.java
Mon Nov 10 16:27:50 2008
@@ -0,0 +1,69 @@
+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 org.apache.velocity.VelocityContext;
+import org.apache.velocity.exception.MathException;
+import org.apache.velocity.runtime.RuntimeConstants;
+
+/**
+ * This class tests support for string concatenation.
+ */
+public class StringConcatenationTestCase extends BaseEvalTestCase
+{
+    public StringConcatenationTestCase(String name)
+    {
+       super(name);
+    }
+
+    public void setUp() throws Exception
+    {
+        super.setUp();
+        DEBUG = true;
+        context.put("foo", "foo");
+        context.put("baz", "baz");
+    }
+
+    public void testStringRefLeft()
+    {
+        assertEvalEquals("foobar", "#set( $o = $foo + 'bar' )$o");
+        assertEvalEquals("foo$bar", "#set( $o = $foo + $bar )$o");
+        assertEvalEquals("foo1", "#set( $o = $foo + 1 )$o");
+        assertEvalEquals("foobaz", "#set( $o = $foo + $baz )$o");
+    }
+
+    public void testStringRefRight()
+    {
+        assertEvalEquals("barfoo", "#set( $o = 'bar' + $foo )$o");
+        assertEvalEquals("$barfoo", "#set( $o = $bar + $foo )$o");
+        assertEvalEquals("1foo", "#set( $o = 1 + $foo )$o");
+    }
+
+    public void testNoRef()
+    {
+        assertEvalEquals("bar1", "#set( $o = 'bar' + 1 )$o");
+    }
+
+    public void testAll()
+    {
+        assertEvalEquals("foobar$bar1baz", "#set( $o = $foo + 'bar' + $bar + 1 + $baz )$o");
+    }
+
+}

Propchange: velocity/engine/trunk/src/test/org/apache/velocity/test/StringConcatenationTestCase.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: velocity/engine/trunk/src/test/org/apache/velocity/test/StringConcatenationTestCase.java
------------------------------------------------------------------------------
    svn:executable = *

Propchange: velocity/engine/trunk/src/test/org/apache/velocity/test/StringConcatenationTestCase.java
------------------------------------------------------------------------------
    svn:keywords = Revision

Propchange: velocity/engine/trunk/src/test/org/apache/velocity/test/StringConcatenationTestCase.java
------------------------------------------------------------------------------
    svn:mime-type = text/plain



Mime
View raw message