From 5a1b096b47fbcca7e9cc6a24db558128f4cdd87f Mon Sep 17 00:00:00 2001 From: bculkin2442 Date: Tue, 2 Jul 2019 16:59:14 -0400 Subject: Convert to using ControlledString All of the places that parse controls now use ControlledString instead of doing their own stuff. -\(o-o)/- --- src/test/java/bjc/everge/TestUtils.java | 72 +++++++++++++++++++++++++++++++-- 1 file changed, 68 insertions(+), 4 deletions(-) (limited to 'src/test/java/bjc/everge/TestUtils.java') diff --git a/src/test/java/bjc/everge/TestUtils.java b/src/test/java/bjc/everge/TestUtils.java index 2b9dc8d..e30a74e 100644 --- a/src/test/java/bjc/everge/TestUtils.java +++ b/src/test/java/bjc/everge/TestUtils.java @@ -1,5 +1,8 @@ package bjc.everge; +import bjc.everge.ControlledString.Control; +import bjc.everge.ControlledString.ParseStrings; + import java.io.FileInputStream; import java.io.IOException; @@ -61,8 +64,13 @@ public class TestUtils { } public static void assertMultiReplace(boolean logRep, String fle, String... inps) { - if (inps.length < 2) throw new IllegalArgumentException("ERROR: Must provide at least two strings to assertMultiReplace"); - if (inps.length % 2 != 0) throw new IllegalArgumentException("ERROR: Odd number of strings passed to assertMultiReplace"); + if (inps.length < 2) { + throw new IllegalArgumentException("ERROR: Must provide at least two strings to assertMultiReplace"); + } + + if (inps.length % 2 != 0) { + throw new IllegalArgumentException("ERROR: Odd number of strings passed to assertMultiReplace"); + } List lrp = null; @@ -98,7 +106,9 @@ public class TestUtils { } public static void assertReplacesTo(boolean logRep, String right, List rps, String inp) { - if (logRep) System.err.printf("\t[LOG] Checking '%s' -> '%s'\n", inp, right); + if (logRep) { + System.err.printf("\t[LOG] Checking '%s' -> '%s'\n", inp, right); + } String tmp = inp; @@ -107,9 +117,63 @@ public class TestUtils { tmp = rp.apply(tmp); - if (logRep) System.err.printf("\t[LOG] '%s' -> '%s'\t%s\n", oldTmp, tmp, rp); + if (logRep) { + System.err.printf("\t\t[LOG-STEP] '%s' -> '%s'\t%s\n", oldTmp, tmp, rp); + } } assertEquals(right, tmp); } + + public static void assertSplitsTo(String inp, String esc, String splat, String... right) { + assertSplitsTo(false, inp, esc, splat, right); + } + + public static void assertSplitsTo(boolean doLog, String inp, String esc, String splat, String... right) { + try { + if (doLog) StringUtils.isDebug = true; + + String[] lst = StringUtils.escapeSplit(esc, splat, inp); + + if (doLog) { + System.err.printf("[TRACE] Returned "); + + for (String str : lst) { + System.err.printf("(%s) ", str); + } + + System.err.println(); + } + + assertArrayEquals(right, lst); + } catch (Exception ex) { + System.err.println("EXCEPTION"); + ex.printStackTrace(); + System.err.println(); + + assertTrue(false); + } finally { + if (doLog) StringUtils.isDebug = false; + } + } + + public static void assertIsControl(String inp, String strang, Control... args) { + assertIsControl(false, inp, strang, args); + } + + public static void assertIsControl(boolean doLog, String inp, String strang, Control... args) { + ControlledString cs = ControlledString.parse(inp, new ParseStrings("//", ";", "/", "|")); + + if (doLog) { + System.err.printf("[LOG] CS: %s\n", cs); + } + + assertEquals(strang, cs.strang); + + assertEquals("array length mismatch:", args.length, cs.count()); + + for (int i = 0; i < args.length; i++) { + assertEquals("array value mismatch:", args[i], cs.controls[i]); + } + } } -- cgit v1.2.3