Skip to content

Commit

Permalink
Fix tests
Browse files Browse the repository at this point in the history
  • Loading branch information
luigidellaquila committed Oct 21, 2024
1 parent e8deff4 commit e584d61
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 16 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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() {
Expand All @@ -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("**"));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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() {
Expand Down

0 comments on commit e584d61

Please sign in to comment.