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 8a52b3b6 JEXL: add test on using regexp array (SO question)
8a52b3b6 is described below

commit 8a52b3b620e790e0abff19e90551677c10f3b1f6
Author: Henrib <hbies...@gmail.com>
AuthorDate: Wed Sep 4 08:37:30 2024 +0200

    JEXL: add test on using regexp array (SO question)
---
 .../org/apache/commons/jexl3/Issues400Test.java    | 26 ++++++++++++++++++++++
 1 file changed, 26 insertions(+)

diff --git a/src/test/java/org/apache/commons/jexl3/Issues400Test.java 
b/src/test/java/org/apache/commons/jexl3/Issues400Test.java
index 1c3e2670..f8c3afc0 100644
--- a/src/test/java/org/apache/commons/jexl3/Issues400Test.java
+++ b/src/test/java/org/apache/commons/jexl3/Issues400Test.java
@@ -28,6 +28,7 @@ import static org.junit.jupiter.api.Assertions.assertTrue;
 
 import java.lang.reflect.Method;
 import java.math.BigDecimal;
+import java.math.MathContext;
 import java.util.Arrays;
 import java.util.Collections;
 import java.util.Comparator;
@@ -37,6 +38,7 @@ import java.util.List;
 import java.util.Map;
 import java.util.Objects;
 import java.util.concurrent.atomic.AtomicLong;
+import java.util.regex.Pattern;
 
 import org.apache.commons.jexl3.introspection.JexlPermissions;
 import org.junit.jupiter.api.Test;
@@ -483,4 +485,28 @@ public class Issues400Test {
         assertEquals(9, m[1].get("type"));
     }
 
+
+    public static class MatchingArithmetic extends JexlArithmetic {
+        public MatchingArithmetic(boolean astrict) {
+            super(astrict);
+        }
+
+        public boolean contains(Pattern[] container, String str) {
+            for(Pattern pattern : container) {
+                if (pattern.matcher(str).matches()) {
+                    return true;
+                }
+            }
+            return false;
+        }
+    }
+
+    @Test
+    void testPatterns() {
+        final JexlEngine jexl = new JexlBuilder().arithmetic(new 
MatchingArithmetic(true)).create();
+        JexlScript script = jexl.createScript("str =~ [~/abc.*/, ~/def.*/]", 
"str");
+        assertTrue((boolean) script.execute(null, "abcdef"));
+        assertTrue((boolean) script.execute(null, "defghi"));
+        assertFalse((boolean) script.execute(null, "ghijkl"));
+    }
 }

Reply via email to