This is an automated email from the ASF dual-hosted git repository.

henrib pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/commons-jexl.git


The following commit(s) were added to refs/heads/master by this push:
     new 06122d3  JEXL-266: augmented example/prototype with 2 forEach operator 
'overloads'
06122d3 is described below

commit 06122d3775edf14bdb0c87bf642976a9e8a01b9d
Author: henrib <hen...@apache.org>
AuthorDate: Thu Aug 16 15:00:29 2018 +0200

    JEXL-266: augmented example/prototype with 2 forEach operator 'overloads'
---
 .../org/apache/commons/jexl3/Issues200Test.java    | 23 ++++++++++++++++++++--
 1 file changed, 21 insertions(+), 2 deletions(-)

diff --git a/src/test/java/org/apache/commons/jexl3/Issues200Test.java 
b/src/test/java/org/apache/commons/jexl3/Issues200Test.java
index 9b09dd4..625962d 100644
--- a/src/test/java/org/apache/commons/jexl3/Issues200Test.java
+++ b/src/test/java/org/apache/commons/jexl3/Issues200Test.java
@@ -588,6 +588,10 @@ public class Issues200Test extends JexlTestCase {
             queue.addFirst(it266);
             return it266;
         }
+                
+        public Iterator<?> forEach(Map<?,?> collection) {
+            return forEach(collection.values());
+        }
         
         public void remove() {
             Deque<Iterator266> queue = TLS_FOREACH.get();
@@ -603,14 +607,29 @@ public class Issues200Test extends JexlTestCase {
     
     @Test
     public void test266() throws Exception {
+        Object result;
+        JexlScript script;
         JexlEngine jexl = new JexlBuilder().arithmetic(new 
Arithmetic266(true)).create();
         JexlContext ctxt = new MapContext();
+        
         List<Integer> li = new ArrayList<Integer>(Arrays.asList(1, 2, 3, 4, 5 
,6));
         ctxt.set("list", li);
-        Object result;
-        JexlScript script;
         script = jexl.createScript("for (var item : list) { if (item <= 3) 
remove(); } return size(list)");
         result = script.execute(ctxt);
         Assert.assertEquals(3, result);
+        Assert.assertEquals(3, li.size());
+        
+        Map<String, Integer> msi = new HashMap<String, Integer>();
+        msi.put("a", 1);
+        msi.put("b", 2);
+        msi.put("c", 3);
+        msi.put("d", 4);
+        msi.put("e", 5);
+        msi.put("f", 6);
+        ctxt.set("map", msi);
+        script = jexl.createScript("for (var item : map) { if (item <= 2) 
remove(); } return size(map)");
+        result = script.execute(ctxt);
+        Assert.assertEquals(4, result);
+        Assert.assertEquals(4, msi.size());
     }
 }

Reply via email to