Skip to content

Commit

Permalink
Question mark in filter expressions should match exactly one character (
Browse files Browse the repository at this point in the history
  • Loading branch information
marchof authored and Godin committed Apr 15, 2018
1 parent dc2d8e1 commit 1a56c96
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 13 deletions.
Expand Up @@ -19,51 +19,56 @@
public class WildcardMatcherTest {

@Test
public void testEmpty() {
public void empty_expression_should_match_any_string() {
assertTrue(new WildcardMatcher("").matches(""));
assertFalse(new WildcardMatcher("").matches("abc"));
}

@Test
public void testExact() {
public void expressions_without_wildcards_should_match_exactly() {
assertTrue(new WildcardMatcher("abc/def.txt").matches("abc/def.txt"));
assertFalse(new WildcardMatcher("abc/def.txt").matches("/abc/def.txt"));
}

@Test
public void testCaseSensitive() {
public void should_match_case_sensitive() {
assertFalse(new WildcardMatcher("abcdef").matches("abcDef"));
assertFalse(new WildcardMatcher("ABCDEF").matches("AbCDEF"));
}

@Test
public void testQuote() {
public void should_not_use_regex_characters() {
assertFalse(new WildcardMatcher("rst.xyz").matches("rstAxyz"));
assertTrue(new WildcardMatcher("(x)+").matches("(x)+"));
}

@Test
public void testWildcards() {
public void asterix_should_match_any_number_of_any_character() {
assertTrue(new WildcardMatcher("*").matches(""));
assertTrue(new WildcardMatcher("*").matches("java/lang/Object"));
assertTrue(new WildcardMatcher("*Test").matches("jacoco/MatcherTest"));
assertTrue(new WildcardMatcher("Matcher*").matches("Matcher"));
assertTrue(new WildcardMatcher("Matcher*").matches("MatcherTest"));
assertTrue(new WildcardMatcher("a*b*a").matches("a-b-b-a"));
assertFalse(new WildcardMatcher("a*b*a").matches("alaska"));
}

@Test
public void questionmark_should_match_any_single_character() {
assertTrue(new WildcardMatcher("Hello?orld").matches("HelloWorld"));
assertFalse(new WildcardMatcher("Hello?orld").matches("Helloorld"));
assertFalse(new WildcardMatcher("Hello?orld").matches("HelloWWWorld"));
assertTrue(new WildcardMatcher("?aco*").matches("jacoco"));
}

@Test
public void testMultiExpression() {
assertTrue(new WildcardMatcher("Hello:World").matches("World"));
public void should_match_any_expression_when_multiple_expressions_are_given() {
assertTrue(new WildcardMatcher("Hello:World").matches("World"));
assertTrue(new WildcardMatcher("*Test:*Foo").matches("UnitTest"));
assertFalse(new WildcardMatcher("foo:bar").matches("foo:bar"));
}

@Test
public void testDollar() {
public void should_match_dollar_sign() {
assertTrue(new WildcardMatcher("*$*").matches("java/util/Map$Entry"));
assertTrue(new WildcardMatcher("*$$$*")
.matches("org/example/Enity$$$generated123"));
Expand Down
Expand Up @@ -14,9 +14,10 @@
import java.util.regex.Pattern;

/**
* Matches strings against <code>?</code>/<code>*</code> wildcard expressions.
* Multiple expressions can be separated with a colon (:). In this case the
* expression matches if at least one part matches.
* Matches strings against glob like wildcard expressions where <code>?</code>
* matches any single character and <code>*</code> matches any number of any
* character. Multiple expressions can be separated with a colon (:). In this
* case the expression matches if at least one part matches.
*/
public class WildcardMatcher {

Expand Down Expand Up @@ -47,7 +48,7 @@ private static CharSequence toRegex(final String expression) {
for (final char c : expression.toCharArray()) {
switch (c) {
case '?':
regex.append(".?");
regex.append(".");
break;
case '*':
regex.append(".*");
Expand Down
2 changes: 2 additions & 0 deletions org.jacoco.doc/docroot/doc/changes.html
Expand Up @@ -31,6 +31,8 @@ <h3>Fixed Bugs</h3>
<li>Don't insert stackmap frames into class files with version &lt; 1.6,
this fixes regression which was introduced in version 0.6.5
(GitHub <a href="https://github.com/jacoco/jacoco/issues/667">#667</a>).</li>
<li>Question mark in filter expressions now correctly matches exactly one character
(GitHub <a href="https://github.com/jacoco/jacoco/issues/672">#672</a>).</li>
</ul>

<h2>Release 0.8.1 (2018/03/21)</h2>
Expand Down

0 comments on commit 1a56c96

Please sign in to comment.