-
Notifications
You must be signed in to change notification settings - Fork 130
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
5 changed files
with
61 additions
and
5 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
54 changes: 54 additions & 0 deletions
54
product/runtime/src/test/java/com/chaquo/java/MatchesPattern.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,54 @@ | ||
package com.chaquo.java; | ||
|
||
import org.hamcrest.Description; | ||
import org.hamcrest.Matcher; | ||
import org.hamcrest.TypeSafeMatcher; | ||
|
||
import java.util.regex.Pattern; | ||
|
||
|
||
/** Copied from Hamcrest 2, which doesn't interact well with JUnit 4 and ProGuard | ||
* ("Missing class org.hamcrest.Factory"). */ | ||
public class MatchesPattern extends TypeSafeMatcher<String> { | ||
|
||
private final Pattern pattern; | ||
|
||
public MatchesPattern(Pattern pattern) { | ||
this.pattern = pattern; | ||
} | ||
|
||
@Override | ||
protected boolean matchesSafely(String item) { | ||
return pattern.matcher(item).matches(); | ||
} | ||
|
||
@Override | ||
public void describeTo(Description description) { | ||
description.appendText("a string matching the pattern '" + pattern + "'"); | ||
} | ||
|
||
/** | ||
* Creates a matcher of {@link java.lang.String} that matches when the examined string | ||
* exactly matches the given {@link java.util.regex.Pattern}. | ||
* | ||
* @param pattern | ||
* the text pattern to match. | ||
* @return The matcher. | ||
*/ | ||
public static Matcher<String> matchesPattern(Pattern pattern) { | ||
return new MatchesPattern(pattern); | ||
} | ||
|
||
/** | ||
* Creates a matcher of {@link java.lang.String} that matches when the examined string | ||
* exactly matches the given regular expression, treated as a {@link java.util.regex.Pattern}. | ||
* | ||
* @param regex | ||
* the regex to match. | ||
* @return The matcher. | ||
*/ | ||
public static Matcher<String> matchesPattern(String regex) { | ||
return new MatchesPattern(Pattern.compile(regex)); | ||
} | ||
|
||
} |
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
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