mirror of
https://github.com/corda/corda.git
synced 2025-01-19 11:16:54 +00:00
Add a unit test for the regular expression engine
We still do not parse the regular expression patterns, but we can at least test that the hardcoded 'a(bb)+a' works as expected. This class will be extended as we support more and more features. Signed-off-by: Johannes Schindelin <johannes.schindelin@gmx.de>
This commit is contained in:
parent
2073d4bffb
commit
b03283033e
26
test/Regex.java
Normal file
26
test/Regex.java
Normal file
@ -0,0 +1,26 @@
|
||||
import regex.Matcher;
|
||||
import regex.Pattern;
|
||||
|
||||
public class Regex {
|
||||
private static void expect(boolean v) {
|
||||
if (! v) throw new RuntimeException();
|
||||
}
|
||||
|
||||
private static Matcher getMatcher(String regex, String string) {
|
||||
return Pattern.compile(regex).matcher(string);
|
||||
}
|
||||
|
||||
private static void expectMatch(String regex, String string) {
|
||||
expect(getMatcher(regex, string).matches());
|
||||
}
|
||||
|
||||
private static void expectNoMatch(String regex, String string) {
|
||||
expect(!getMatcher(regex, string).matches());
|
||||
}
|
||||
|
||||
public static void main(String[] args) {
|
||||
expectMatch("a(bb)?a", "abba");
|
||||
expectNoMatch("a(bb)?a", "abbba");
|
||||
expectNoMatch("a(bb)?a", "abbaa");
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue
Block a user