Regex: Test Pattern#split(String)

The particular pattern we use to test it is used in ImgLib2, based on
this answer on stackoverflow:

	http://stackoverflow.com/a/279337

Signed-off-by: Johannes Schindelin <johannes.schindelin@gmx.de>
This commit is contained in:
Johannes Schindelin 2013-11-14 14:46:28 -06:00
parent 8ab10a6953
commit b4c768b101

View File

@ -44,6 +44,16 @@ public class Regex {
expect(!matcher.find());
}
private static void expectSplit(String regex, String string,
String... list)
{
String[] array = Pattern.compile(regex).split(string);
expect(array.length == list.length);
for (int i = 0; i < list.length; ++ i) {
expect(list[i].equals(array[i]));
}
}
public static void main(String[] args) {
expectMatch("a(bb)?a", "abba");
expectNoMatch("a(bb)?a", "abbba");
@ -69,5 +79,7 @@ public class Regex {
expectMatch("\\x4A", "J");
expectMatch("\\x61", "a");
expectMatch("\\078", "\0078");
expectSplit("(?<=\\w)(?=\\W)|(?<=\\W)(?=\\w)", "a + b * x",
"a", " + ", "b", " * ", "x");
}
}