From b4c768b1010e1ae491913dbfaaef189de5fe134f Mon Sep 17 00:00:00 2001 From: Johannes Schindelin Date: Thu, 14 Nov 2013 14:46:28 -0600 Subject: [PATCH] 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 --- test/Regex.java | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/test/Regex.java b/test/Regex.java index 6a5e0909ad..16b50745fa 100644 --- a/test/Regex.java +++ b/test/Regex.java @@ -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"); } }