julianhyde commented on code in PR #3712:
URL: https://github.com/apache/calcite/pull/3712#discussion_r1511789203


##########
testkit/src/main/java/org/apache/calcite/test/SqlOperatorTest.java:
##########
@@ -4928,6 +4928,37 @@ private static void checkIf(SqlOperatorFixture f) {
     f.checkNull("regexp_contains(cast(null as varchar), cast(null as 
varchar))");
   }
 
+  @Test void testRegexpFunc() {
+    final SqlOperatorFixture f = fixture().setFor(SqlLibraryOperators.REGEXP);
+    checkRegexpFunc(f, FunctionAlias.of(SqlLibraryOperators.REGEXP));
+    checkRegexpFunc(f, FunctionAlias.of(SqlLibraryOperators.REGEXP_LIKE));
+  }
+
+  void checkRegexpFunc(SqlOperatorFixture f0, FunctionAlias functionAlias) {
+    final SqlFunction function = functionAlias.function;
+    final String fn = function.getName();
+    final Consumer<SqlOperatorFixture> consumer = f -> {
+      f.checkBoolean(fn + "('abc def ghi', 'abc')", true);
+      f.checkBoolean(fn + "('abc def ghi', '[a-z]+')", true);
+      f.checkBoolean(fn + "('f...@bar.com', 
'@[a-zA-Z0-9-]+\\.[a-zA-Z0-9-.]+')", true);
+      f.checkBoolean(fn + "('foo@.com', '@[a-zA-Z0-9-]+\\.[a-zA-Z0-9-.]+')", 
false);
+      f.checkBoolean(fn + "('5556664422', '^\\d{10}$')", false);
+      f.checkBoolean(fn + "('11555666442233', '^\\d{10}$')", false);
+      f.checkBoolean(fn + "('55566644221133', '\\d{10}')", false);
+      f.checkBoolean(fn + "('55as56664as422', '\\d{10}')", false);
+      f.checkBoolean(fn + "('55as56664as422', '')", true);
+
+      f.checkQuery("select " + fn + "('abc def ghi', 'abc')");
+      f.checkQuery("select " + fn + "('f...@bar.com', 
'@[a-zA-Z0-9-]+\\\\.[a-zA-Z0-9-.]+')");
+      f.checkQuery("select " + fn + "('55as56664as422', '\\d{10}')");
+
+      f.checkNull(fn + "('abc def ghi', cast(null as varchar))");
+      f.checkNull(fn + "(cast(null as varchar), 'abc')");
+      f.checkNull(fn + "(cast(null as varchar), cast(null as varchar))");
+    };
+    f0.forEachLibrary(list(functionAlias.libraries), consumer);

Review Comment:
   if RLIKE, REGEXP_LIKE and REGEXP are identical, you should devise a way to 
test all three with a single test



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: commits-unsubscr...@calcite.apache.org

For queries about this service, please contact Infrastructure at:
us...@infra.apache.org

Reply via email to