commons-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From hen...@apache.org
Subject svn commit: r809316 - in /commons/proper/jexl/branches/2.0/src/test/java/org/apache/commons/jexl: ArithmeticTest.java BitwiseOperatorTest.java BlockTest.java CacheTest.java IfTest.java IssuesTest.java MethodTest.java UnifiedJEXLTest.java
Date Sun, 30 Aug 2009 11:33:20 GMT
Author: henrib
Date: Sun Aug 30 11:33:19 2009
New Revision: 809316

URL: http://svn.apache.org/viewvc?rev=809316&view=rev
Log:
Refactored BitwiseOperator to use asserter.
Removed main methods from tests (use JexlTestCase instead).
Added parenthesized expression tests & further Debugger checking.

Modified:
    commons/proper/jexl/branches/2.0/src/test/java/org/apache/commons/jexl/ArithmeticTest.java
    commons/proper/jexl/branches/2.0/src/test/java/org/apache/commons/jexl/BitwiseOperatorTest.java
    commons/proper/jexl/branches/2.0/src/test/java/org/apache/commons/jexl/BlockTest.java
    commons/proper/jexl/branches/2.0/src/test/java/org/apache/commons/jexl/CacheTest.java
    commons/proper/jexl/branches/2.0/src/test/java/org/apache/commons/jexl/IfTest.java
    commons/proper/jexl/branches/2.0/src/test/java/org/apache/commons/jexl/IssuesTest.java
    commons/proper/jexl/branches/2.0/src/test/java/org/apache/commons/jexl/MethodTest.java
    commons/proper/jexl/branches/2.0/src/test/java/org/apache/commons/jexl/UnifiedJEXLTest.java

Modified: commons/proper/jexl/branches/2.0/src/test/java/org/apache/commons/jexl/ArithmeticTest.java
URL: http://svn.apache.org/viewvc/commons/proper/jexl/branches/2.0/src/test/java/org/apache/commons/jexl/ArithmeticTest.java?rev=809316&r1=809315&r2=809316&view=diff
==============================================================================
--- commons/proper/jexl/branches/2.0/src/test/java/org/apache/commons/jexl/ArithmeticTest.java
(original)
+++ commons/proper/jexl/branches/2.0/src/test/java/org/apache/commons/jexl/ArithmeticTest.java
Sun Aug 30 11:33:19 2009
@@ -91,6 +91,12 @@
         asserter.assertExpression("3 * 3 - foo", new Long(7));
 
         /*
+         * test parenthesized exprs
+         */
+        asserter.assertExpression("(4 + 3) * 6", new Long(42));
+        asserter.assertExpression("(8 - 2) * 7", new Long(42));
+
+        /*
          * test some floaty stuff
          */
         asserter.assertExpression("3 * \"3.0\"", new Double(9));
@@ -151,6 +157,7 @@
         final int PERMS = tnames.length * tnames.length;
 
         JexlEngine jexl = new JexlEngine();
+        jexl.setCache(128);
         jexl.setSilent(false);
         // for non-silent, silent...
         for (int s = 0; s < 2; ++s) {
@@ -186,5 +193,6 @@
                 assertTrue("All expressions should have zeroed " + zeval + "/" + PERMS,
                         zeval == PERMS);
         }
+        debuggerCheck(jexl);
     }
 }
\ No newline at end of file

Modified: commons/proper/jexl/branches/2.0/src/test/java/org/apache/commons/jexl/BitwiseOperatorTest.java
URL: http://svn.apache.org/viewvc/commons/proper/jexl/branches/2.0/src/test/java/org/apache/commons/jexl/BitwiseOperatorTest.java?rev=809316&r1=809315&r2=809316&view=diff
==============================================================================
--- commons/proper/jexl/branches/2.0/src/test/java/org/apache/commons/jexl/BitwiseOperatorTest.java
(original)
+++ commons/proper/jexl/branches/2.0/src/test/java/org/apache/commons/jexl/BitwiseOperatorTest.java
Sun Aug 30 11:33:19 2009
@@ -16,7 +16,7 @@
  */
 
 package org.apache.commons.jexl;
-
+import org.apache.commons.jexl.junit.Asserter;
 
 /**
  * Tests for the bitwise operators.
@@ -24,6 +24,12 @@
  * @since 1.1
  */
 public class BitwiseOperatorTest extends JexlTestCase {
+    private Asserter asserter;
+
+    @Override
+    public void setUp() {
+        asserter = new Asserter(JEXL);
+    }
 
     /**
      * Create the named test.
@@ -34,170 +40,114 @@
     }
     
     public void testAndWithTwoNulls() throws Exception {
-        Expression e = JEXL.createExpression("null & null");
-        JexlContext jc = JexlHelper.createContext();
-        Object o = e.evaluate(jc);
-        assertEquals("Result is wrong", new Long(0), o);
+        asserter.assertExpression("null & null", new Long(0));
     }
 
     public void testAndWithLeftNull() throws Exception {
-        Expression e = JEXL.createExpression("null & 1");
-        JexlContext jc = JexlHelper.createContext();
-        Object o = e.evaluate(jc);
-        assertEquals("Result is wrong", new Long(0), o);
+        asserter.assertExpression("null & 1", new Long(0));
     }
 
     public void testAndWithRightNull() throws Exception {
-        Expression e = JEXL.createExpression("1 & null");
-        JexlContext jc = JexlHelper.createContext();
-        Object o = e.evaluate(jc);
-        assertEquals("Result is wrong", new Long(0), o);
+        asserter.assertExpression("1 & null", new Long(0));
     }
 
     public void testAndSimple() throws Exception {
-        Expression e = JEXL.createExpression("15 & 3");
-        JexlContext jc = JexlHelper.createContext();
-        Object o = e.evaluate(jc);
-        assertEquals("Result is wrong", new Long(3), o);
+        asserter.assertExpression("15 & 3", new Long(15 & 3));
     }
 
     public void testAndVariableNumberCoercion() throws Exception {
-        Expression e = JEXL.createExpression("x & y");
-        JexlContext jc = JexlHelper.createContext();
-        jc.getVars().put("x", new Integer(15));
-        jc.getVars().put("y", new Short((short)7));
-        Object o = e.evaluate(jc);
-        assertEquals("Result is wrong", new Long(7), o);
+        asserter.setVariable("x", new Integer(15));
+        asserter.setVariable("y", new Short((short)7));
+        asserter.assertExpression("x & y", new Long(15 & 7));
     }
 
     public void testAndVariableStringCoercion() throws Exception {
-        Expression e = JEXL.createExpression("x & y");
-        JexlContext jc = JexlHelper.createContext();
-        jc.getVars().put("x", new Integer(15));
-        jc.getVars().put("y", "7");
-        Object o = e.evaluate(jc);
-        assertEquals("Result is wrong", new Long(7), o);
+        asserter.setVariable("x", new Integer(15));
+        asserter.setVariable("y", "7");
+        asserter.assertExpression("x & y", new Long(15 & 7));
     }
 
     public void testComplementWithNull() throws Exception {
-        Expression e = JEXL.createExpression("~null");
-        JexlContext jc = JexlHelper.createContext();
-        Object o = e.evaluate(jc);
-        assertEquals("Result is wrong", new Long(-1), o);
+        asserter.assertExpression("~null", new Long(-1));
     }
     
     public void testComplementSimple() throws Exception {
-        Expression e = JEXL.createExpression("~128");
-        JexlContext jc = JexlHelper.createContext();
-        Object o = e.evaluate(jc);
-        assertEquals("Result is wrong", new Long(-129), o);
+        asserter.assertExpression("~128", new Long(-129));
     }
 
     public void testComplementVariableNumberCoercion() throws Exception {
-        Expression e = JEXL.createExpression("~x");
-        JexlContext jc = JexlHelper.createContext();
-        jc.getVars().put("x", new Integer(15));
-        Object o = e.evaluate(jc);
-        assertEquals("Result is wrong", new Long(-16), o);
+        asserter.setVariable("x", new Integer(15));
+        asserter.assertExpression("~x", new Long(~15));
     }
 
     public void testComplementVariableStringCoercion() throws Exception {
-        Expression e = JEXL.createExpression("~x");
-        JexlContext jc = JexlHelper.createContext();
-        jc.getVars().put("x", "15");
-        Object o = e.evaluate(jc);
-        assertEquals("Result is wrong", new Long(-16), o);
+        asserter.setVariable("x", "15");
+        asserter.assertExpression("~x", new Long(~15));
     }
 
     public void testOrWithTwoNulls() throws Exception {
-        Expression e = JEXL.createExpression("null | null");
-        JexlContext jc = JexlHelper.createContext();
-        Object o = e.evaluate(jc);
-        assertEquals("Result is wrong", new Long(0), o);
+        asserter.assertExpression("null | null", new Long(0));
     }
 
     public void testOrWithLeftNull() throws Exception {
-        Expression e = JEXL.createExpression("null | 1");
-        JexlContext jc = JexlHelper.createContext();
-        Object o = e.evaluate(jc);
-        assertEquals("Result is wrong", new Long(1), o);
+        asserter.assertExpression("null | 1", new Long(1));
     }
 
     public void testOrWithRightNull() throws Exception {
-        Expression e = JEXL.createExpression("1 | null");
-        JexlContext jc = JexlHelper.createContext();
-        Object o = e.evaluate(jc);
-        assertEquals("Result is wrong", new Long(1), o);
+        asserter.assertExpression("1 | null", new Long(1));
     }
 
     public void testOrSimple() throws Exception {
-        Expression e = JEXL.createExpression("12 | 3");
-        JexlContext jc = JexlHelper.createContext();
-        Object o = e.evaluate(jc);
-        assertEquals("Result is wrong", new Long(15), o);
+        asserter.assertExpression("12 | 3", new Long(15));
     }
 
     public void testOrVariableNumberCoercion() throws Exception {
-        Expression e = JEXL.createExpression("x | y");
-        JexlContext jc = JexlHelper.createContext();
-        jc.getVars().put("x", new Integer(12));
-        jc.getVars().put("y", new Short((short) 3));
-        Object o = e.evaluate(jc);
-        assertEquals("Result is wrong", new Long(15), o);
+        asserter.setVariable("x", new Integer(12));
+        asserter.setVariable("y", new Short((short) 3));
+        asserter.assertExpression("x | y", new Long(15));
     }
 
     public void testOrVariableStringCoercion() throws Exception {
-        Expression e = JEXL.createExpression("x | y");
-        JexlContext jc = JexlHelper.createContext();
-        jc.getVars().put("x", new Integer(12));
-        jc.getVars().put("y", "3");
-        Object o = e.evaluate(jc);
-        assertEquals("Result is wrong", new Long(15), o);
+        asserter.setVariable("x", new Integer(12));
+        asserter.setVariable("y", "3");
+        asserter.assertExpression("x | y", new Long(15));
     }
 
     public void testXorWithTwoNulls() throws Exception {
-        Expression e = JEXL.createExpression("null ^ null");
-        JexlContext jc = JexlHelper.createContext();
-        Object o = e.evaluate(jc);
-        assertEquals("Result is wrong", new Long(0), o);
+        asserter.assertExpression("null ^ null", new Long(0));
     }
 
     public void testXorWithLeftNull() throws Exception {
-        Expression e = JEXL.createExpression("null ^ 1");
-        JexlContext jc = JexlHelper.createContext();
-        Object o = e.evaluate(jc);
-        assertEquals("Result is wrong", new Long(1), o);
+        asserter.assertExpression("null ^ 1", new Long(1));
     }
 
     public void testXorWithRightNull() throws Exception {
-        Expression e = JEXL.createExpression("1 ^ null");
-        JexlContext jc = JexlHelper.createContext();
-        Object o = e.evaluate(jc);
-        assertEquals("Result is wrong", new Long(1), o);
+        asserter.assertExpression("1 ^ null", new Long(1));
     }
 
     public void testXorSimple() throws Exception {
-        Expression e = JEXL.createExpression("1 ^ 3");
-        JexlContext jc = JexlHelper.createContext();
-        Object o = e.evaluate(jc);
-        assertEquals("Result is wrong", new Long(2), o);
+        asserter.assertExpression("1 ^ 3", new Long(1 ^ 3));
     }
 
     public void testXorVariableNumberCoercion() throws Exception {
-        Expression e = JEXL.createExpression("x ^ y");
-        JexlContext jc = JexlHelper.createContext();
-        jc.getVars().put("x", new Integer(1));
-        jc.getVars().put("y", new Short((short) 3));
-        Object o = e.evaluate(jc);
-        assertEquals("Result is wrong", new Long(2), o);
+        asserter.setVariable("x", new Integer(1));
+        asserter.setVariable("y", new Short((short) 3));
+        asserter.assertExpression("x ^ y", new Long(1 ^ 3));
     }
 
     public void testXorVariableStringCoercion() throws Exception {
-        Expression e = JEXL.createExpression("x ^ y");
-        JexlContext jc = JexlHelper.createContext();
-        jc.getVars().put("x", new Integer(1));
-        jc.getVars().put("y", "3");
-        Object o = e.evaluate(jc);
-        assertEquals("Result is wrong", new Long(2), o);
+        asserter.setVariable("x", new Integer(1));
+        asserter.setVariable("y", "3");
+        asserter.assertExpression("x ^ y", new Long(1 ^ 3));
+    }
+
+    public void testParenthesized() throws Exception {
+        asserter.assertExpression("(2 | 1) & 3", 3L);
+        asserter.assertExpression("(2 & 1) | 3", 3L);
+        asserter.assertExpression("~(120 | 42)", new Long( ~(120 | 42) ));
+    }
+
+    public static void main(String[] args) throws Exception {
+        new BitwiseOperatorTest("debug").runTest("testAndVariableNumberCoercion");
     }
 }

Modified: commons/proper/jexl/branches/2.0/src/test/java/org/apache/commons/jexl/BlockTest.java
URL: http://svn.apache.org/viewvc/commons/proper/jexl/branches/2.0/src/test/java/org/apache/commons/jexl/BlockTest.java?rev=809316&r1=809315&r2=809316&view=diff
==============================================================================
--- commons/proper/jexl/branches/2.0/src/test/java/org/apache/commons/jexl/BlockTest.java
(original)
+++ commons/proper/jexl/branches/2.0/src/test/java/org/apache/commons/jexl/BlockTest.java
Sun Aug 30 11:33:19 2009
@@ -74,9 +74,4 @@
         Object o = e.evaluate(jc);
         assertEquals("Block result is wrong", "world", o);
     }
-
-    public static void main(String[] args) throws Exception {
-        new BlockTest("debug").testBlockExecutesAll();
-        //new AssignTest("debug").testArray();
-    }
 }

Modified: commons/proper/jexl/branches/2.0/src/test/java/org/apache/commons/jexl/CacheTest.java
URL: http://svn.apache.org/viewvc/commons/proper/jexl/branches/2.0/src/test/java/org/apache/commons/jexl/CacheTest.java?rev=809316&r1=809315&r2=809316&view=diff
==============================================================================
--- commons/proper/jexl/branches/2.0/src/test/java/org/apache/commons/jexl/CacheTest.java
(original)
+++ commons/proper/jexl/branches/2.0/src/test/java/org/apache/commons/jexl/CacheTest.java
Sun Aug 30 11:33:19 2009
@@ -575,7 +575,4 @@
         doCOMPUTE(args, LOOPS, true);
     }
 
-    public static void main(String[] args) throws Exception {
-        new CacheTest("debug").runTest("testNew");
-    }
 }

Modified: commons/proper/jexl/branches/2.0/src/test/java/org/apache/commons/jexl/IfTest.java
URL: http://svn.apache.org/viewvc/commons/proper/jexl/branches/2.0/src/test/java/org/apache/commons/jexl/IfTest.java?rev=809316&r1=809315&r2=809316&view=diff
==============================================================================
--- commons/proper/jexl/branches/2.0/src/test/java/org/apache/commons/jexl/IfTest.java (original)
+++ commons/proper/jexl/branches/2.0/src/test/java/org/apache/commons/jexl/IfTest.java Sun
Aug 30 11:33:19 2009
@@ -63,7 +63,7 @@
      */
     public void testSimpleElse() throws Exception {
         Expression e = JEXL
-                .createExpression("if (false) 1; else 2;");
+                .createExpression("if (false) 1 else 2;");
         JexlContext jc = JexlHelper.createContext();
 
         Object o = e.evaluate(jc);
@@ -91,11 +91,11 @@
      */
     public void testBlockElse() throws Exception {
         Expression e = JEXL
-                .createExpression("if (false) {1;} else {2;}");
+                .createExpression("if (false) {1} else {2 ; 3}");
         JexlContext jc = JexlHelper.createContext();
 
         Object o = e.evaluate(jc);
-        assertEquals("Result is wrong", new Integer(2), o);
+        assertEquals("Result is wrong", new Integer(3), o);
     }
 
     /**

Modified: commons/proper/jexl/branches/2.0/src/test/java/org/apache/commons/jexl/IssuesTest.java
URL: http://svn.apache.org/viewvc/commons/proper/jexl/branches/2.0/src/test/java/org/apache/commons/jexl/IssuesTest.java?rev=809316&r1=809315&r2=809316&view=diff
==============================================================================
--- commons/proper/jexl/branches/2.0/src/test/java/org/apache/commons/jexl/IssuesTest.java
(original)
+++ commons/proper/jexl/branches/2.0/src/test/java/org/apache/commons/jexl/IssuesTest.java
Sun Aug 30 11:33:19 2009
@@ -174,7 +174,7 @@
             try {
                 Expression expr = jexl.createExpression( exprs[e]);
                 /* Object value = */ expr.evaluate(ctxt);
-                fail("Should have failed due to null argument");
+                fail(exprs[e] + " : should have failed due to null argument");
             }
             catch(JexlException xjexl) {
                 // expected

Modified: commons/proper/jexl/branches/2.0/src/test/java/org/apache/commons/jexl/MethodTest.java
URL: http://svn.apache.org/viewvc/commons/proper/jexl/branches/2.0/src/test/java/org/apache/commons/jexl/MethodTest.java?rev=809316&r1=809315&r2=809316&view=diff
==============================================================================
--- commons/proper/jexl/branches/2.0/src/test/java/org/apache/commons/jexl/MethodTest.java
(original)
+++ commons/proper/jexl/branches/2.0/src/test/java/org/apache/commons/jexl/MethodTest.java
Sun Aug 30 11:33:19 2009
@@ -124,7 +124,6 @@
         java.util.Map<String, Object> funcs = new java.util.HashMap<String, Object>();
         funcs.put("func", new Functor());
         funcs.put("FUNC", Functor.class);
-        JexlEngine JEXL = new JexlEngine();
         JEXL.setFunctions(funcs);
 
         Expression e = JEXL.createExpression("func:ten()");
@@ -153,8 +152,4 @@
         assertEquals("Result is not 40", new Integer(40), o);
     }
 
-    public static void main(String[] args) throws Exception {
-        new MethodTest().runTest("testNamespaceCall");
-    }
-
 }
\ No newline at end of file

Modified: commons/proper/jexl/branches/2.0/src/test/java/org/apache/commons/jexl/UnifiedJEXLTest.java
URL: http://svn.apache.org/viewvc/commons/proper/jexl/branches/2.0/src/test/java/org/apache/commons/jexl/UnifiedJEXLTest.java?rev=809316&r1=809315&r2=809316&view=diff
==============================================================================
--- commons/proper/jexl/branches/2.0/src/test/java/org/apache/commons/jexl/UnifiedJEXLTest.java
(original)
+++ commons/proper/jexl/branches/2.0/src/test/java/org/apache/commons/jexl/UnifiedJEXLTest.java
Sun Aug 30 11:33:19 2009
@@ -251,9 +251,4 @@
 
     }
 
-    public static void main(String[] args) throws Exception {
-        UnifiedJEXLTest test = new UnifiedJEXLTest("debug");
-        test.setUp();
-        test.testBadContextNested();
-    }
 }



Mime
View raw message