From 3db013fc7ec8b242f1a7456910484063fba7e938 Mon Sep 17 00:00:00 2001 From: bculkin2442 Date: Thu, 18 Oct 2018 20:43:44 -0400 Subject: Fix levelSplitterRX, and add tests to ensure that it stays fixed It would also be fairly easy to convert this to a general splitRX, or add support for additional expressions. This might be a better interface than the one in ConfigurableTokenSplitter. (It'd almost certainly be easier to debug/introspect than the bodged together regex that CTS uses,) --- .../java/bjc/utils/ioutils/LevelSplitterTest.java | 50 ++++++++++++++++++++++ 1 file changed, 50 insertions(+) create mode 100644 base/src/test/java/bjc/utils/ioutils/LevelSplitterTest.java (limited to 'base/src/test') diff --git a/base/src/test/java/bjc/utils/ioutils/LevelSplitterTest.java b/base/src/test/java/bjc/utils/ioutils/LevelSplitterTest.java new file mode 100644 index 0000000..30ec919 --- /dev/null +++ b/base/src/test/java/bjc/utils/ioutils/LevelSplitterTest.java @@ -0,0 +1,50 @@ +package bjc.utils.ioutils; + +import static org.junit.Assert.*; + +import java.util.Arrays; +import java.util.List; + +import org.junit.Test; +import static bjc.utils.funcutils.TestUtils.*; +import static bjc.utils.ioutils.LevelSplitterTest.RXPair.pair; + +/** + * Test of LevelSplitter. + * + * @author bjculkin + * + */ +public class LevelSplitterTest { + static final class RXPair { + public String inp; + public String[] outp; + + public RXPair(String inp, String... outp) { + this.inp = inp; + this.outp = outp; + } + + public static RXPair pair(String inp, String... outp) { + return new RXPair(inp, outp); + } + } + + /** + * Test regex splitter. + */ + @Test + public void testRXSplit() { + LevelSplitter splitter = LevelSplitter.def; + + // Check generic splitting works + assertRXSplit("\\s+", pair("", ""), pair("a", "a"), pair("a b", "a", "b"), pair("a b", "a", "b"), + pair("a\t \tb", "a", "b")); + } + + private static void assertRXSplit(String pat, RXPair... pairs) { + for (RXPair pair : pairs) { + assertListEquals(LevelSplitter.def.levelSplitRX(pair.inp, pat), pair.outp); + } + } +} -- cgit v1.2.3