Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
ISPN-6588 Query DSL 'like' queries should only accept % and _ as the …
…wildcards
- Loading branch information
1 parent
0eeea50
commit 7cc0f88
Showing
5 changed files
with
159 additions
and
9 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
75 changes: 75 additions & 0 deletions
75
...ter/src/test/java/org/infinispan/objectfilter/impl/predicateindex/RegexConditionTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,75 @@ | ||
package org.infinispan.objectfilter.impl.predicateindex; | ||
|
||
import org.junit.Test; | ||
|
||
import static org.junit.Assert.assertFalse; | ||
import static org.junit.Assert.assertTrue; | ||
|
||
/** | ||
* @author anistor@redhat.com | ||
* @since 9.0 | ||
*/ | ||
public class RegexConditionTest { | ||
|
||
@Test | ||
public void testSingleWildcard() throws Exception { | ||
RegexCondition regexCondition = new RegexCondition("a_b"); | ||
assertTrue(regexCondition.match("aXb")); | ||
assertTrue(regexCondition.match("a_b")); | ||
assertTrue(regexCondition.match("a%b")); | ||
|
||
assertFalse(regexCondition.match("ab")); | ||
assertFalse(regexCondition.match("aXXb")); | ||
} | ||
|
||
@Test | ||
public void testMultipleWildcard() throws Exception { | ||
RegexCondition regexCondition = new RegexCondition("a%b"); | ||
assertTrue(regexCondition.match("ab")); | ||
assertTrue(regexCondition.match("aXb")); | ||
assertTrue(regexCondition.match("aXYb")); | ||
assertTrue(regexCondition.match("a_b")); | ||
assertTrue(regexCondition.match("a%b")); | ||
|
||
assertFalse(regexCondition.match("a")); | ||
assertFalse(regexCondition.match("aX")); | ||
assertFalse(regexCondition.match("a%")); | ||
} | ||
|
||
@Test | ||
public void testPlusEscaping() throws Exception { | ||
RegexCondition regexCondition = new RegexCondition("a%aZ+"); | ||
assertTrue(regexCondition.match("aaaZ+")); | ||
|
||
assertFalse(regexCondition.match("aaa")); | ||
assertFalse(regexCondition.match("aaaZ")); | ||
assertFalse(regexCondition.match("aaaZZ")); | ||
assertFalse(regexCondition.match("aaaZZZ")); | ||
} | ||
|
||
@Test | ||
public void testAsteriskEscaping() throws Exception { | ||
RegexCondition regexCondition = new RegexCondition("a%aZ*"); | ||
assertTrue(regexCondition.match("aaaZ*")); | ||
|
||
assertFalse(regexCondition.match("aaa")); | ||
assertFalse(regexCondition.match("aaaZ")); | ||
assertFalse(regexCondition.match("aaaZZ")); | ||
assertFalse(regexCondition.match("aaaZZZ")); | ||
} | ||
|
||
@Test | ||
public void testGeneralMetacharEscaping() { | ||
assertTrue(new RegexCondition("a%(b").match("aaa(b")); | ||
assertTrue(new RegexCondition("a%)b").match("aaa)b")); | ||
assertTrue(new RegexCondition("a%[b").match("aaa[b")); | ||
assertTrue(new RegexCondition("a%]b").match("aaa]b")); | ||
assertTrue(new RegexCondition("a%{b").match("aaa{b")); | ||
assertTrue(new RegexCondition("a%}b").match("aaa}b")); | ||
assertTrue(new RegexCondition("a%$b").match("aaa$b")); | ||
assertTrue(new RegexCondition("a%^b").match("aaa^b")); | ||
assertTrue(new RegexCondition("a%.b").match("aaa.b")); | ||
assertTrue(new RegexCondition("a%|b").match("aaa|b")); | ||
assertTrue(new RegexCondition("a%\\b").match("aaa\\b")); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters