You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@tinkerpop.apache.org by kr...@apache.org on 2022/01/07 21:53:13 UTC

[tinkerpop] 01/08: Regex tests

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

krlawrence pushed a commit to branch TINKERPOP-2652
in repository https://gitbox.apache.org/repos/asf/tinkerpop.git

commit efb57e46fd2676d8779fac1393f98b5b01df0063
Author: Kelvin Lawrence <gf...@yahoo.com>
AuthorDate: Thu Nov 18 16:20:48 2021 -0600

    Regex tests
---
 .../apache/tinkerpop/gremlin/process/traversal/Text.java   |  4 ++--
 .../language/grammar/TraversalPredicateVisitorTest.java    |  3 +++
 .../apache/tinkerpop/gremlin/process/traversal/PTest.java  | 14 ++++++++++++++
 .../src/main/python/gremlin_python/process/traversal.py    |  8 ++++++++
 4 files changed, 27 insertions(+), 2 deletions(-)

diff --git a/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/process/traversal/Text.java b/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/process/traversal/Text.java
index 5d443ff..91fcd7d 100644
--- a/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/process/traversal/Text.java
+++ b/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/process/traversal/Text.java
@@ -39,7 +39,7 @@ public enum Text implements BiPredicate<String, String> {
     regex {
         @Override
         public boolean test(final String value, final String regex) {
-            Pattern pattern = Pattern.compile(regex, Pattern.CASE_INSENSITIVE);
+            Pattern pattern = Pattern.compile(regex);
             Matcher matcher = pattern.matcher(value);
             return matcher.find();   
         }
@@ -60,7 +60,7 @@ public enum Text implements BiPredicate<String, String> {
     notRegex {
         @Override
         public boolean test(final String value, final String regex) {
-	    Pattern pattern = Pattern.compile(regex, Pattern.CASE_INSENSITIVE);
+	    Pattern pattern = Pattern.compile(regex);
 	    Matcher matcher = pattern.matcher(value);
 	    return !matcher.find();   
         }
diff --git a/gremlin-core/src/test/java/org/apache/tinkerpop/gremlin/language/grammar/TraversalPredicateVisitorTest.java b/gremlin-core/src/test/java/org/apache/tinkerpop/gremlin/language/grammar/TraversalPredicateVisitorTest.java
index 7254388..4bb7f30 100644
--- a/gremlin-core/src/test/java/org/apache/tinkerpop/gremlin/language/grammar/TraversalPredicateVisitorTest.java
+++ b/gremlin-core/src/test/java/org/apache/tinkerpop/gremlin/language/grammar/TraversalPredicateVisitorTest.java
@@ -90,6 +90,9 @@ public class TraversalPredicateVisitorTest {
                 {"TextP.endingWith('hakuna')", TextP.endingWith("hakuna")},
                 {"TextP.notEndingWith('hakuna')", TextP.notEndingWith("hakuna")},
                 {"TextP.notStartingWith('hakuna')", TextP.notStartingWith("hakuna")},
+                {"TextP.regex('^h')", TextP.regex("^h")},
+                {"TextP.notRegex('^h')", TextP.notRegex("^h")},
+                {"TextP.regex('^h').negate()", TextP.regex("^h").negate()},
         });
     }
 
diff --git a/gremlin-core/src/test/java/org/apache/tinkerpop/gremlin/process/traversal/PTest.java b/gremlin-core/src/test/java/org/apache/tinkerpop/gremlin/process/traversal/PTest.java
index e58e8be..d29e666 100644
--- a/gremlin-core/src/test/java/org/apache/tinkerpop/gremlin/process/traversal/PTest.java
+++ b/gremlin-core/src/test/java/org/apache/tinkerpop/gremlin/process/traversal/PTest.java
@@ -158,6 +158,20 @@ public class PTest {
                     {TextP.containing("o").and(P.gte("j")).and(TextP.endingWith("ko")), "josh", false},
                     {TextP.containing("o").and(P.gte("j").and(TextP.endingWith("ko"))), "marko", true},
                     {TextP.containing("o").and(P.gte("j").and(TextP.endingWith("ko"))), "josh", false},
+                    {TextP.regex("^D"), "Dallas Fort Worth", true},
+                    {TextP.regex("^d"), "Dallas Fort Worth", false},
+                    {TextP.regex("^Da"), "Dallas Forth Worth", true},
+                    {TextP.regex("^da"), "Dallas Forth Worth", false},
+                    {TextP.regex("^x"), "Dallas Fort Worth", false},
+                    {TextP.regex("Dal[l|x]as"), "Dallas Fort Worth", true},
+                    {TextP.regex("Dal[f|x]as"), "Dallas Fort Worth", false},
+                    {TextP.regex("[a-zA-Z]+ Fort"), "Dallas Fort Worth", true},
+                    {TextP.regex("[1-9]{3}"), "123-ABC-456", true},
+                    {TextP.regex("[1-9]{3}-[A-Z]{3}-[1-9]{3}"), "123-ABC-456", true},
+                    {TextP.regex("[1-9]{3}-[a-z]{3}-[1-9]{3}"), "123-ABC-456", false},
+                    {TextP.regex("(?i)[1-9]{3}-[a-z]{3}-[1-9]{3}"), "123-ABC-456", true},
+                    {TextP.regex("(?i)abc"), "123-ABC-456", true},
+                    {TextP.regex("(?i)[a-b]{3}-[1-9]{3}-[a-z]{3}"), "123-ABC-456", false},
             }));
         }
 
diff --git a/gremlin-python/src/main/python/gremlin_python/process/traversal.py b/gremlin-python/src/main/python/gremlin_python/process/traversal.py
index f7bd31d..f8bb83c 100644
--- a/gremlin-python/src/main/python/gremlin_python/process/traversal.py
+++ b/gremlin-python/src/main/python/gremlin_python/process/traversal.py
@@ -384,6 +384,14 @@ class TextP(P):
     def startingWith(*args):
         return TextP("startingWith", *args)
 
+    @staticmethod
+    def regex(*args):
+        return TextP("regex", *args)
+
+    @staticmethod
+    def notRegex(*args):
+        return TextP("notRegex", *args)
+
     def __eq__(self, other):
         return isinstance(other, self.__class__) and self.operator == other.operator and self.value == other.value and self.other == other.other