commons-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From hen...@apache.org
Subject svn commit: r1687737 - in /commons/proper/jexl/trunk/src: main/java/org/apache/commons/jexl3/internal/ test/java/org/apache/commons/jexl3/ test/java/org/apache/commons/jexl3/internal/
Date Fri, 26 Jun 2015 10:23:52 GMT
Author: henrib
Date: Fri Jun 26 10:23:51 2015
New Revision: 1687737

URL: http://svn.apache.org/r1687737
Log:
JEXL:
Added test on ranges;
Issues updated

Added:
    commons/proper/jexl/trunk/src/test/java/org/apache/commons/jexl3/internal/RangeTest.java
  (with props)
Modified:
    commons/proper/jexl/trunk/src/main/java/org/apache/commons/jexl3/internal/IntegerRange.java
    commons/proper/jexl/trunk/src/main/java/org/apache/commons/jexl3/internal/LongRange.java
    commons/proper/jexl/trunk/src/main/java/org/apache/commons/jexl3/internal/TemplateEngine.java
    commons/proper/jexl/trunk/src/test/java/org/apache/commons/jexl3/ArithmeticOperatorTest.java
    commons/proper/jexl/trunk/src/test/java/org/apache/commons/jexl3/IssuesTest.java
    commons/proper/jexl/trunk/src/test/java/org/apache/commons/jexl3/JXLTTest.java

Modified: commons/proper/jexl/trunk/src/main/java/org/apache/commons/jexl3/internal/IntegerRange.java
URL: http://svn.apache.org/viewvc/commons/proper/jexl/trunk/src/main/java/org/apache/commons/jexl3/internal/IntegerRange.java?rev=1687737&r1=1687736&r2=1687737&view=diff
==============================================================================
--- commons/proper/jexl/trunk/src/main/java/org/apache/commons/jexl3/internal/IntegerRange.java
(original)
+++ commons/proper/jexl/trunk/src/main/java/org/apache/commons/jexl3/internal/IntegerRange.java
Fri Jun 26 10:23:51 2015
@@ -19,6 +19,7 @@ package org.apache.commons.jexl3.interna
 import java.lang.reflect.Array;
 import java.util.Collection;
 import java.util.Iterator;
+import java.util.NoSuchElementException;
 
 /**
  * A range of integers.
@@ -45,6 +46,32 @@ public class IntegerRange implements Col
     }
 
     @Override
+    public int hashCode() {
+        int hash = 7;
+        hash = 13 * hash + this.low;
+        hash = 13 * hash + this.high;
+        return hash;
+    }
+
+    @Override
+    public boolean equals(Object obj) {
+        if (obj == null) {
+            return false;
+        }
+        if (getClass() != obj.getClass()) {
+            return false;
+        }
+        final IntegerRange other = (IntegerRange) obj;
+        if (this.low != other.low) {
+            return false;
+        }
+        if (this.high != other.high) {
+            return false;
+        }
+        return true;
+    }
+
+    @Override
     public Iterator<Integer> iterator() {
         return new IntegerIterator(low, high);
     }
@@ -176,7 +203,7 @@ class IntegerIterator implements Iterato
             cursor += 1;
             return Integer.valueOf(next);
         } else {
-            return null;
+            throw new NoSuchElementException();
         }
     }
 

Modified: commons/proper/jexl/trunk/src/main/java/org/apache/commons/jexl3/internal/LongRange.java
URL: http://svn.apache.org/viewvc/commons/proper/jexl/trunk/src/main/java/org/apache/commons/jexl3/internal/LongRange.java?rev=1687737&r1=1687736&r2=1687737&view=diff
==============================================================================
--- commons/proper/jexl/trunk/src/main/java/org/apache/commons/jexl3/internal/LongRange.java
(original)
+++ commons/proper/jexl/trunk/src/main/java/org/apache/commons/jexl3/internal/LongRange.java
Fri Jun 26 10:23:51 2015
@@ -47,6 +47,32 @@ public class LongRange implements Collec
     }
 
     @Override
+    public int hashCode() {
+        int hash = 3;
+        hash = 41 * hash + (int) (this.low ^ (this.low >>> 32));
+        hash = 41 * hash + (int) (this.high ^ (this.high >>> 32));
+        return hash;
+    }
+
+    @Override
+    public boolean equals(Object obj) {
+        if (obj == null) {
+            return false;
+        }
+        if (getClass() != obj.getClass()) {
+            return false;
+        }
+        final LongRange other = (LongRange) obj;
+        if (this.low != other.low) {
+            return false;
+        }
+        if (this.high != other.high) {
+            return false;
+        }
+        return true;
+    }
+
+    @Override
     public Iterator<Long> iterator() {
         return new LongIterator(low, high);
     }

Modified: commons/proper/jexl/trunk/src/main/java/org/apache/commons/jexl3/internal/TemplateEngine.java
URL: http://svn.apache.org/viewvc/commons/proper/jexl/trunk/src/main/java/org/apache/commons/jexl3/internal/TemplateEngine.java?rev=1687737&r1=1687736&r2=1687737&view=diff
==============================================================================
--- commons/proper/jexl/trunk/src/main/java/org/apache/commons/jexl3/internal/TemplateEngine.java
(original)
+++ commons/proper/jexl/trunk/src/main/java/org/apache/commons/jexl3/internal/TemplateEngine.java
Fri Jun 26 10:23:51 2015
@@ -105,7 +105,7 @@ public final class TemplateEngine extend
      * A helper class to build expressions.
      * Keeps count of sub-expressions by type.
      */
-    private static class ExpressionBuilder {
+    private static final class ExpressionBuilder {
         /** Per TemplateExpression type counters. */
         private final int[] counts;
         /** The list of expressions. */
@@ -115,7 +115,7 @@ public final class TemplateEngine extend
          * Creates a builder.
          * @param size the initial TemplateExpression array size
          */
-        ExpressionBuilder(int size) {
+        private ExpressionBuilder(int size) {
             counts = new int[]{0, 0, 0};
             expressions = new ArrayList<TemplateExpression>(size <= 0 ? 3 : size);
         }
@@ -124,32 +124,48 @@ public final class TemplateEngine extend
          * Adds an TemplateExpression to the list of expressions, maintain per-type counts.
          * @param expr the TemplateExpression to add
          */
-        void add(TemplateExpression expr) {
+        private void add(TemplateExpression expr) {
             counts[expr.getType().index] += 1;
             expressions.add(expr);
         }
 
+        @Override
+        public String toString() {
+            return toString(new StringBuilder()).toString();
+        }
+
+        /**
+         * Base for to-string.
+         * @param error the builder to fill
+         * @return the builder
+         */
+        private StringBuilder toString(StringBuilder error) {
+            error.append("exprs{");
+            error.append(expressions.size());
+            error.append(", constant:");
+            error.append(counts[ExpressionType.CONSTANT.index]);
+            error.append(", immediate:");
+            error.append(counts[ExpressionType.IMMEDIATE.index]);
+            error.append(", deferred:");
+            error.append(counts[ExpressionType.DEFERRED.index]);
+            error.append("}");
+            return error;
+        }
+
         /**
          * Builds an TemplateExpression from a source, performs checks.
          * @param el     the unified el instance
          * @param source the source TemplateExpression
          * @return an TemplateExpression
          */
-        TemplateExpression build(TemplateEngine el, TemplateExpression source) {
+        private TemplateExpression build(TemplateEngine el, TemplateExpression source) {
             int sum = 0;
             for (int count : counts) {
                 sum += count;
             }
             if (expressions.size() != sum) {
-                StringBuilder error = new StringBuilder("parsing algorithm error, exprs:
");
-                error.append(expressions.size());
-                error.append(", constant:");
-                error.append(counts[ExpressionType.CONSTANT.index]);
-                error.append(", immediate:");
-                error.append(counts[ExpressionType.IMMEDIATE.index]);
-                error.append(", deferred:");
-                error.append(counts[ExpressionType.DEFERRED.index]);
-                throw new IllegalStateException(error.toString());
+                StringBuilder error = new StringBuilder("parsing algorithm error: ");
+                throw new IllegalStateException(toString(error).toString());
             }
             // if only one sub-expr, no need to create a composite
             if (expressions.size() == 1) {
@@ -239,6 +255,11 @@ public final class TemplateEngine extend
             return Collections.emptySet();
         }
 
+        @Override
+        public final TemplateExpression getSource() {
+            return source;
+        }
+
         /**
          * Fills up the list of variables accessed by this unified expression.
          * @param collector the variable collector
@@ -249,14 +270,25 @@ public final class TemplateEngine extend
 
         @Override
         public final TemplateExpression prepare(JexlContext context) {
-            try {
                 Scope.Frame frame = context instanceof TemplateContext
                                     ? ((TemplateContext) context).getFrame()
                                     : null;
+                return prepare(frame, context);
+        }
+
+        /**
+         * Prepares this expression.
+         * @param frame the frame storing parameters and local variables
+         * @param context the context storing global variables
+         * @return the expression value
+         * @throws JexlException
+         */
+        protected final TemplateExpression prepare(Scope.Frame frame, JexlContext context)
{
+            try {
                 Interpreter interpreter = jexl.createInterpreter(context, frame);
                 return prepare(interpreter);
             } catch (JexlException xjexl) {
-                Exception xuel = createException(xjexl.getInfo(), "prepare", this, xjexl);
+                JexlException xuel = createException(xjexl.getInfo(), "prepare", this, xjexl);
                 if (jexl.isSilent()) {
                     jexl.logger.warn(xuel.getMessage(), xuel.getCause());
                     return null;
@@ -265,16 +297,37 @@ public final class TemplateEngine extend
             }
         }
 
+        /**
+         * Prepares a sub-expression for interpretation.
+         * @param interpreter a JEXL interpreter
+         * @return a prepared unified expression
+         * @throws JexlException (only for nested and composite)
+         */
+        protected TemplateExpression prepare(Interpreter interpreter) {
+            return this;
+        }
+
         @Override
         public final Object evaluate(JexlContext context) {
-            try {
                 Scope.Frame frame = context instanceof TemplateContext
                                     ? ((TemplateContext) context).getFrame()
                                     : null;
+                return evaluate(frame, context);
+        }
+
+        /**
+         * Evaluates this expression.
+         * @param frame the frame storing parameters and local variables
+         * @param context the context storing global variables
+         * @return the expression value
+         * @throws JexlException
+         */
+        protected final Object evaluate(Scope.Frame frame, JexlContext context) {
+            try {
                 Interpreter interpreter = jexl.createInterpreter(context, frame);
                 return evaluate(interpreter);
             } catch (JexlException xjexl) {
-                Exception xuel = createException(xjexl.getInfo(), "prepare", this, xjexl);
+                JexlException xuel = createException(xjexl.getInfo(), "prepare", this, xjexl);
                 if (jexl.isSilent()) {
                     jexl.logger.warn(xuel.getMessage(), xuel.getCause());
                     return null;
@@ -283,21 +336,6 @@ public final class TemplateEngine extend
             }
         }
 
-        @Override
-        public final TemplateExpression getSource() {
-            return source;
-        }
-
-        /**
-         * Prepares a sub-expression for interpretation.
-         * @param interpreter a JEXL interpreter
-         * @return a prepared unified expression
-         * @throws JexlException (only for nested and composite)
-         */
-        protected TemplateExpression prepare(Interpreter interpreter) {
-            return this;
-        }
-
         /**
          * Interprets a sub-expression.
          * @param interpreter a JEXL interpreter
@@ -305,6 +343,7 @@ public final class TemplateEngine extend
          * @throws JexlException (only for nested and composite)
          */
         protected abstract Object evaluate(Interpreter interpreter);
+
     }
 
     /** A constant unified expression. */
@@ -588,8 +627,7 @@ public final class TemplateEngine extend
                 // keep track of TemplateExpression equivalence
                 eq &= expr == prepared;
             }
-            TemplateExpression ready = eq ? this : builder.build(TemplateEngine.this, this);
-            return ready;
+            return eq ? this : builder.build(TemplateEngine.this, this);
         }
 
         @Override
@@ -696,8 +734,8 @@ public final class TemplateEngine extend
      */
     private TemplateExpression parseExpression(JexlInfo info, String expr, Scope scope) {
         final int size = expr.length();
-        ExpressionBuilder builder = new ExpressionBuilder(0);
-        StringBuilder strb = new StringBuilder(size);
+        final ExpressionBuilder builder = new ExpressionBuilder(0);
+        final StringBuilder strb = new StringBuilder(size);
         ParseState state = ParseState.CONST;
         int immediate1 = 0;
         int deferred1 = 0;
@@ -1040,7 +1078,7 @@ public final class TemplateEngine extend
             TemplateContext tcontext = new TemplateContext(context, frame, exprs, null);
             TemplateExpression[] immediates = new TemplateExpression[exprs.length];
             for (int e = 0; e < exprs.length; ++e) {
-                immediates[e] = exprs[e].prepare(tcontext);
+                immediates[e] = exprs[e].prepare(frame, tcontext);
             }
             return new TemplateScript(prefix, source, script, immediates);
         }
@@ -1161,12 +1199,12 @@ public final class TemplateEngine extend
             }
             TemplateExpression expr = exprs[e];
             if (expr.isDeferred()) {
-                expr = expr.prepare(wrap);
+                expr = expr.prepare(frame, wrap);
             }
             if (expr instanceof CompositeExpression) {
                 printComposite((CompositeExpression) expr);
             } else {
-                doPrint(expr.getInfo(), expr.evaluate(this));
+                doPrint(expr.getInfo(), expr.evaluate(frame, this));
             }
         }
 
@@ -1179,7 +1217,7 @@ public final class TemplateEngine extend
             final int size = cexprs.length;
             Object value;
             for (int e = 0; e < size; ++e) {
-                value = cexprs[e].evaluate(this);
+                value = cexprs[e].evaluate(frame, this);
                 doPrint(cexprs[e].getInfo(), value);
             }
         }

Modified: commons/proper/jexl/trunk/src/test/java/org/apache/commons/jexl3/ArithmeticOperatorTest.java
URL: http://svn.apache.org/viewvc/commons/proper/jexl/trunk/src/test/java/org/apache/commons/jexl3/ArithmeticOperatorTest.java?rev=1687737&r1=1687736&r2=1687737&view=diff
==============================================================================
--- commons/proper/jexl/trunk/src/test/java/org/apache/commons/jexl3/ArithmeticOperatorTest.java
(original)
+++ commons/proper/jexl/trunk/src/test/java/org/apache/commons/jexl3/ArithmeticOperatorTest.java
Fri Jun 26 10:23:51 2015
@@ -34,6 +34,7 @@ import org.junit.Test;
  * Tests for the startsWith, endsWith, match and range operators.
  * @since 3.0
  */
+@SuppressWarnings({"UnnecessaryBoxing", "AssertEqualsBetweenInconvertibleTypes"})
 public class ArithmeticOperatorTest extends JexlTestCase {
     private Asserter asserter;
 
@@ -252,7 +253,6 @@ public class ArithmeticOperatorTest exte
         Assert.assertEquals(Integer.valueOf(1), ii.next());
         Assert.assertEquals(Integer.valueOf(2), ii.next());
         Assert.assertEquals(Integer.valueOf(3), ii.next());
-        Assert.assertNull(ii.next());
 
         script = jexl.createScript("(4 - 3) .. (9 / 3)");
         result = script.execute(null);
@@ -261,7 +261,6 @@ public class ArithmeticOperatorTest exte
         Assert.assertEquals(Integer.valueOf(1), ii.next());
         Assert.assertEquals(Integer.valueOf(2), ii.next());
         Assert.assertEquals(Integer.valueOf(3), ii.next());
-        Assert.assertNull(ii.next());
 
         // sum of 1, 2, 3
         script = jexl.createScript("var x = 0; for(var y : ((5 - 4) .. (12 / 4))) { x = x
+ y }; x");

Modified: commons/proper/jexl/trunk/src/test/java/org/apache/commons/jexl3/IssuesTest.java
URL: http://svn.apache.org/viewvc/commons/proper/jexl/trunk/src/test/java/org/apache/commons/jexl3/IssuesTest.java?rev=1687737&r1=1687736&r2=1687737&view=diff
==============================================================================
--- commons/proper/jexl/trunk/src/test/java/org/apache/commons/jexl3/IssuesTest.java (original)
+++ commons/proper/jexl/trunk/src/test/java/org/apache/commons/jexl3/IssuesTest.java Fri Jun
26 10:23:51 2015
@@ -1037,4 +1037,76 @@ public class IssuesTest extends JexlTest
         Assert.assertTrue(o instanceof List);
         Assert.assertEquals(Arrays.asList(1, 2), o);
     }
+
+    @Test
+    public void test155() throws Exception {
+        JexlEngine jexlEngine = new Engine();
+        JexlExpression jexlExpresssion = jexlEngine.createExpression("first.second.name");
+        JexlContext jc = new MapContext();
+        jc.set("first.second.name", "RIGHT");
+        jc.set("name", "WRONG");
+        Object value = jexlExpresssion.evaluate(jc);
+        Assert.assertEquals("RIGHT", value.toString());
+    }
+
+    public static class Question42 extends MapContext {
+        public String functionA(String arg) {
+            return "a".equals(arg)? "A" : "";
+        }
+        public String functionB(String arg) {
+            return "b".equals(arg)? "B" : "";
+        }
+        public String functionC(String arg) {
+            return "c".equals(arg)? "C" : "";
+        }
+        public String functionD(String arg) {
+            return "d".equals(arg)? "D" : "";
+        }
+    }
+
+    public static class Arithmetic42 extends JexlArithmetic {
+        public Arithmetic42() {
+            super(false);
+        }
+
+        public Object bitwiseAnd(String lhs, String rhs) {
+            if (rhs.isEmpty()) { return "";  }
+            if (lhs.isEmpty()) { return ""; }
+            return lhs + rhs;
+        }
+
+        public Object bitwiseOr(String lhs, String rhs) {
+            if (rhs.isEmpty()) { return lhs; }
+            if (lhs.isEmpty()) { return rhs; }
+            return lhs + rhs;
+        }
+    }
+
+    @Test
+    public void testQuestion42() throws Exception {
+        JexlEngine jexl = new JexlBuilder().arithmetic(new Arithmetic42()).create();
+        JexlContext jc = new Question42();
+
+        String str0 = "(functionA('z') | functionB('b')) &  (functionC('c') |  functionD('d')
) ";
+        JexlExpression expr0 = jexl.createExpression(str0);
+        Object value0 = expr0.evaluate(jc);
+        Assert.assertEquals("BCD", value0);
+
+        String str1 = "(functionA('z') & functionB('b')) |  (functionC('c') &  functionD('d')
) ";
+        JexlExpression expr1 = jexl.createExpression(str1);
+        Object value1 = expr1.evaluate(jc);
+        Assert.assertEquals("CD", value1);
+    }
+
+    @Test
+    public void test156() throws Exception {
+        JexlEngine jexl = new Engine();
+        JexlContext jc = new MapContext();
+        Object ra = jexl.createExpression("463.0d * 0.1").evaluate(jc);
+        Assert.assertEquals(Double.class, ra.getClass());
+        Object r0 = jexl.createExpression("463.0B * 0.1").evaluate(jc);
+        Assert.assertEquals(java.math.BigDecimal.class, r0.getClass());
+        Object r1 = jexl.createExpression("463.0B * 0.1B").evaluate(jc);
+        Assert.assertEquals(java.math.BigDecimal.class, r1.getClass());
+    }
 }

Modified: commons/proper/jexl/trunk/src/test/java/org/apache/commons/jexl3/JXLTTest.java
URL: http://svn.apache.org/viewvc/commons/proper/jexl/trunk/src/test/java/org/apache/commons/jexl3/JXLTTest.java?rev=1687737&r1=1687736&r2=1687737&view=diff
==============================================================================
--- commons/proper/jexl/trunk/src/test/java/org/apache/commons/jexl3/JXLTTest.java (original)
+++ commons/proper/jexl/trunk/src/test/java/org/apache/commons/jexl3/JXLTTest.java Fri Jun
26 10:23:51 2015
@@ -193,6 +193,20 @@ public class JXLTTest extends JexlTestCa
     }
 
     @Test
+    public void testNestedTemplate() throws Exception {
+        final String source = "#{${hi}+'.world'}";
+        JxltEngine.Template expr = JXLT.createTemplate(source, "hi");
+
+        context.set("greeting.world", "Hello World!");
+        StringWriter strw = new StringWriter();
+        expr.evaluate(context, strw, "greeting");
+        String o = strw.toString();
+        Assert.assertEquals("Hello World!", o);
+
+        Assert.assertEquals(source, getSource(expr.toString()));
+    }
+
+    @Test
     public void testImmediate() throws Exception {
         JexlContext none = null;
         final String source = "${'Hello ' + 'World!'}";
@@ -586,9 +600,39 @@ public class JXLTTest extends JexlTestCa
             }
         }
         Assert.assertEquals(6, count);
+        Assert.assertTrue(output.indexOf("42") > 0);
+        Assert.assertTrue(output.indexOf("43") > 0);
+        Assert.assertTrue(output.indexOf("44") > 0);
+        Assert.assertTrue(output.indexOf("45") > 0);
     }
 
     @Test
+    public void testReport2() throws Exception {
+        String rpt
+                = "<report>\n"
+                + "this is ${x}\n"
+                + "${x + 1}\n"
+                + "${x + 2}\n"
+                + "${x + 3}\n"
+                + "</report>\n";
+        JxltEngine.Template t = JXLT.createTemplate("$$", new StringReader(rpt), "x");
+        StringWriter strw = new StringWriter();
+        t.evaluate(context, strw, 42);
+        String output = strw.toString();
+        int count = 0;
+        for (int i = 0; i < output.length(); ++i) {
+            char c = output.charAt(i);
+            if ('\n' == c) {
+                count += 1;
+            }
+        }
+        Assert.assertEquals(6, count);
+        Assert.assertTrue(output.indexOf("42") > 0);
+        Assert.assertTrue(output.indexOf("43") > 0);
+        Assert.assertTrue(output.indexOf("44") > 0);
+        Assert.assertTrue(output.indexOf("45") > 0);
+    }
+    @Test
     public void testOneLiner() throws Exception {
         JxltEngine.Template t = JXLT.createTemplate("$$", new StringReader("fourty-two"));
         StringWriter strw = new StringWriter();

Added: commons/proper/jexl/trunk/src/test/java/org/apache/commons/jexl3/internal/RangeTest.java
URL: http://svn.apache.org/viewvc/commons/proper/jexl/trunk/src/test/java/org/apache/commons/jexl3/internal/RangeTest.java?rev=1687737&view=auto
==============================================================================
--- commons/proper/jexl/trunk/src/test/java/org/apache/commons/jexl3/internal/RangeTest.java
(added)
+++ commons/proper/jexl/trunk/src/test/java/org/apache/commons/jexl3/internal/RangeTest.java
Fri Jun 26 10:23:51 2015
@@ -0,0 +1,138 @@
+/*
+ * 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.
+ */
+package org.apache.commons.jexl3.internal;
+
+import org.apache.commons.jexl3.JexlTestCase;
+import java.util.Arrays;
+import java.util.Iterator;
+import java.util.NoSuchElementException;
+import org.junit.After;
+import org.junit.Assert;
+import org.junit.Before;
+import org.junit.Test;
+
+/**
+ * Basic checks on ranges.
+ */
+@SuppressWarnings({"UnnecessaryBoxing", "AssertEqualsBetweenInconvertibleTypes"})
+public class RangeTest extends JexlTestCase {
+
+    public RangeTest() {
+        super("InternalTest");
+    }
+
+    @Before
+    @Override
+    public void setUp() throws Exception {
+        // ensure jul logging is only error
+        java.util.logging.Logger.getLogger(org.apache.commons.jexl3.JexlEngine.class.getName()).setLevel(java.util.logging.Level.SEVERE);
+    }
+
+    @After
+    @Override
+    public void tearDown() throws Exception {
+        super.tearDown();
+    }
+
+    @Test
+    public void testRanges() {
+        LongRange lr0 = new LongRange(20,10);
+        Assert.assertFalse(lr0.isEmpty());
+        Assert.assertTrue(lr0.contains(10L));
+        Assert.assertTrue(lr0.contains(20L));
+        Assert.assertFalse(lr0.contains(30L));
+        Assert.assertFalse(lr0.contains(5L));
+        LongRange lr1 = new LongRange(10,20);
+        Assert.assertEquals(lr0, lr1);
+        Assert.assertTrue(lr0.containsAll(lr1));
+        LongRange lr2 = new LongRange(10,15);
+        Assert.assertNotEquals(lr0, lr2);
+        Assert.assertTrue(lr0.containsAll(lr2));
+        Assert.assertFalse(lr2.containsAll(lr1));
+        IntegerRange ir0 = new IntegerRange(20,10);
+        Assert.assertFalse(ir0.isEmpty());
+        Assert.assertTrue(ir0.contains(10));
+        Assert.assertTrue(ir0.contains(20));
+        Assert.assertFalse(ir0.contains(30));
+        Assert.assertFalse(ir0.contains(5));
+        IntegerRange ir1 = new IntegerRange(10,20);
+        Assert.assertEquals(ir0, ir1);
+        Assert.assertTrue(ir0.containsAll(ir1));
+        Assert.assertNotEquals(ir0, lr0);
+        Assert.assertNotEquals(ir1, lr1);
+        IntegerRange ir2 = new IntegerRange(10,15);
+        Assert.assertNotEquals(ir0, ir2);
+        Assert.assertTrue(ir0.containsAll(ir2));
+        Assert.assertFalse(ir2.containsAll(ir1));
+
+        long lc0 = 10;
+        Iterator<Long> il0 = lr0.iterator();
+        while(il0.hasNext()) {
+            long v0 = il0.next();
+            Assert.assertEquals(lc0, v0);
+            try {
+                switch((int)v0) {
+                    case 10:  il0.remove(); Assert.fail(); break;
+                    case 11: lr1.add(v0); Assert.fail(); break;
+                    case 12: lr1.remove(v0); Assert.fail(); break;
+                    case 13: lr1.addAll(Arrays.asList(v0)); Assert.fail(); break;
+                    case 14: lr1.removeAll(Arrays.asList(v0)); Assert.fail(); break;
+                    case 15: lr1.retainAll(Arrays.asList(v0)); Assert.fail(); break;
+                }
+            } catch(UnsupportedOperationException xuo) {
+                // ok
+            }
+            lc0 += 1;
+        }
+        Assert.assertEquals(21L, lc0);
+        try {
+            il0.next();
+            Assert.fail();
+        } catch(NoSuchElementException xns) {
+            // ok
+        }
+
+        int ic0 = 10;
+        Iterator<Integer> ii0 = ir0.iterator();
+        while(ii0.hasNext()) {
+            int v0 = ii0.next();
+            Assert.assertEquals(ic0, v0);
+            try {
+                switch(v0) {
+                    case 10: ii0.remove(); Assert.fail(); break;
+                    case 11: ir1.add(v0); Assert.fail(); break;
+                    case 12: ir1.remove(v0); Assert.fail(); break;
+                    case 13: ir1.addAll(Arrays.asList(v0)); Assert.fail(); break;
+                    case 14: ir1.removeAll(Arrays.asList(v0)); Assert.fail(); break;
+                    case 15: ir1.retainAll(Arrays.asList(v0)); Assert.fail(); break;
+                }
+            } catch(UnsupportedOperationException xuo) {
+                // ok
+            }
+            ic0 += 1;
+        }
+        Assert.assertEquals(21, ic0);
+        try {
+            ii0.next();
+            Assert.fail();
+        } catch(NoSuchElementException xns) {
+            // ok
+        }
+
+    }
+}
+

Propchange: commons/proper/jexl/trunk/src/test/java/org/apache/commons/jexl3/internal/RangeTest.java
------------------------------------------------------------------------------
    svn:eol-style = native



Mime
View raw message