From e584d61865e57a6aa16377810b08bcc766e69261 Mon Sep 17 00:00:00 2001 From: Luigi Dell'Aquila Date: Mon, 21 Oct 2024 09:30:56 +0200 Subject: [PATCH] Fix tests --- .../predicate/regex/StringPatternTests.java | 14 ++++++------- .../rules/logical/ReplaceRegexMatchTests.java | 20 ++++++++++--------- 2 files changed, 18 insertions(+), 16 deletions(-) diff --git a/x-pack/plugin/esql-core/src/test/java/org/elasticsearch/xpack/esql/core/expression/predicate/regex/StringPatternTests.java b/x-pack/plugin/esql-core/src/test/java/org/elasticsearch/xpack/esql/core/expression/predicate/regex/StringPatternTests.java index 44fec5ac18b81..c361b7e3726ed 100644 --- a/x-pack/plugin/esql-core/src/test/java/org/elasticsearch/xpack/esql/core/expression/predicate/regex/StringPatternTests.java +++ b/x-pack/plugin/esql-core/src/test/java/org/elasticsearch/xpack/esql/core/expression/predicate/regex/StringPatternTests.java @@ -39,13 +39,13 @@ private boolean rlikeExactMatch(String pattern) { public void testWildcardMatchAll() { assertTrue(likeMatchesAll("*")); - assertTrue(likeMatchesAll("*")); + assertTrue(likeMatchesAll("**")); assertFalse(likeMatchesAll("a*")); - assertFalse(likeMatchesAll("*_")); - assertFalse(likeMatchesAll("*_*_*")); - assertFalse(likeMatchesAll("_*")); - assertFalse(likeMatchesAll("0%")); + assertFalse(likeMatchesAll("*?")); + assertFalse(likeMatchesAll("*?*?*")); + assertFalse(likeMatchesAll("?*")); + assertFalse(likeMatchesAll("\\*")); } public void testRegexMatchAll() { @@ -64,8 +64,8 @@ public void testWildcardExactMatch() { assertTrue(likeExactMatch("\\*")); assertTrue(likeExactMatch("\\?")); assertTrue(likeExactMatch("123")); - assertTrue(likeExactMatch("1230_")); - assertTrue(likeExactMatch("1230_321")); + assertTrue(likeExactMatch("123\\?")); + assertTrue(likeExactMatch("123\\?321")); assertFalse(likeExactMatch("*")); assertFalse(likeExactMatch("**")); diff --git a/x-pack/plugin/esql/src/test/java/org/elasticsearch/xpack/esql/optimizer/rules/logical/ReplaceRegexMatchTests.java b/x-pack/plugin/esql/src/test/java/org/elasticsearch/xpack/esql/optimizer/rules/logical/ReplaceRegexMatchTests.java index b71877c6a4617..20d638a113bf2 100644 --- a/x-pack/plugin/esql/src/test/java/org/elasticsearch/xpack/esql/optimizer/rules/logical/ReplaceRegexMatchTests.java +++ b/x-pack/plugin/esql/src/test/java/org/elasticsearch/xpack/esql/optimizer/rules/logical/ReplaceRegexMatchTests.java @@ -15,6 +15,7 @@ import org.elasticsearch.xpack.esql.core.expression.predicate.regex.RLikePattern; import org.elasticsearch.xpack.esql.core.expression.predicate.regex.WildcardLike; import org.elasticsearch.xpack.esql.core.expression.predicate.regex.WildcardPattern; +import org.elasticsearch.xpack.esql.core.util.StringUtils; import org.elasticsearch.xpack.esql.expression.predicate.operator.comparison.Equals; import static java.util.Arrays.asList; @@ -46,15 +47,16 @@ public void testMatchAllRLikeToExist() { } public void testExactMatchWildcardLike() { - String s = "ab"; - WildcardPattern pattern = new WildcardPattern(s); - FieldAttribute fa = getFieldAttribute(); - WildcardLike l = new WildcardLike(EMPTY, fa, pattern); - Expression e = new ReplaceRegexMatch().rule(l); - assertEquals(Equals.class, e.getClass()); - Equals eq = (Equals) e; - assertEquals(fa, eq.left()); - assertEquals(s, eq.right().fold()); + for (String s : asList("ab", "ab\\*", "ab\\?c")) { + WildcardPattern pattern = new WildcardPattern(s); + FieldAttribute fa = getFieldAttribute(); + WildcardLike l = new WildcardLike(EMPTY, fa, pattern); + Expression e = new ReplaceRegexMatch().rule(l); + assertEquals(Equals.class, e.getClass()); + Equals eq = (Equals) e; + assertEquals(fa, eq.left()); + assertEquals(s.replace("\\", StringUtils.EMPTY), eq.right().fold()); + } } public void testExactMatchRLike() {