commons-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From d...@apache.org
Subject cvs commit: jakarta-commons/jexl/src/test/org/apache/commons/jexl JexlTest.java
Date Tue, 24 Aug 2004 02:22:12 GMT
dion        2004/08/23 19:22:12

  Modified:    jexl/src/java/org/apache/commons/jexl/parser ASTAddNode.java
               jexl/src/test/org/apache/commons/jexl JexlTest.java
  Log:
  Fix string concatenation with variables dying. Thanks to Geoff Waggott
  
  Revision  Changes    Path
  1.7       +15 -5     jakarta-commons/jexl/src/java/org/apache/commons/jexl/parser/ASTAddNode.java
  
  Index: ASTAddNode.java
  ===================================================================
  RCS file: /home/cvs/jakarta-commons/jexl/src/java/org/apache/commons/jexl/parser/ASTAddNode.java,v
  retrieving revision 1.6
  retrieving revision 1.7
  diff -u -r1.6 -r1.7
  --- ASTAddNode.java	28 Feb 2004 13:45:20 -0000	1.6
  +++ ASTAddNode.java	24 Aug 2004 02:22:12 -0000	1.7
  @@ -80,10 +80,20 @@
                * null a 0
                */
   
  -            Double l = left == null ? new Double(0) : Coercion.coerceDouble(left);
  -            Double r = right == null? new Double(0) : Coercion.coerceDouble(right);
  +            try
  +            {
  +                Double l = left == null ? new Double(0) : Coercion.coerceDouble(left);
  +                Double r = right == null? new Double(0) : Coercion.coerceDouble(right);
   
  -            return new Double(l.doubleValue() + r.doubleValue());
  +                return new Double(l.doubleValue() + r.doubleValue());
  +            }
  +            catch( java.lang.NumberFormatException nfe )
  +            {
  +                /*
  +                 * Well, use strings!
  +                 */
  +                return left.toString().concat(right.toString());
  +            }
           }
   
           /*
  
  
  
  1.58      +13 -1     jakarta-commons/jexl/src/test/org/apache/commons/jexl/JexlTest.java
  
  Index: JexlTest.java
  ===================================================================
  RCS file: /home/cvs/jakarta-commons/jexl/src/test/org/apache/commons/jexl/JexlTest.java,v
  retrieving revision 1.57
  retrieving revision 1.58
  diff -u -r1.57 -r1.58
  --- JexlTest.java	22 Aug 2004 14:52:15 -0000	1.57
  +++ JexlTest.java	24 Aug 2004 02:22:12 -0000	1.58
  @@ -838,6 +838,18 @@
       }
   
       /**
  +     * Simple test of '+' as a string concatenation operator
  +     * @throws Exception
  +     */
  +    public void testStringConcatenation() throws Exception
  +    {
  +        JexlContext jc = JexlHelper.createContext();
  +        jc.getVars().put("first", "Hello");
  +        jc.getVars().put("second", "World");
  +        assertExpression(jc, "first + ' ' + second", "Hello World");
  +    }
  +
  +    /**
        * Ensures static methods on objects can be called.
        */
       public void testStaticMethodInvocation() throws Exception
  
  
  

---------------------------------------------------------------------
To unsubscribe, e-mail: commons-dev-unsubscribe@jakarta.apache.org
For additional commands, e-mail: commons-dev-help@jakarta.apache.org


Mime
View raw message