summaryrefslogtreecommitdiff
path: root/src/test/java/bjc/everge/TestUtils.java
diff options
context:
space:
mode:
authorbculkin2442 <bjculkin@mix.wvu.edu>2019-07-02 16:59:14 -0400
committerbculkin2442 <bjculkin@mix.wvu.edu>2019-07-02 16:59:14 -0400
commit5a1b096b47fbcca7e9cc6a24db558128f4cdd87f (patch)
tree8e5046c58978e0fd62a2758889cf61defdd807b5 /src/test/java/bjc/everge/TestUtils.java
parent20000281fc88c188eb81d9d3d954119725a03ca6 (diff)
Convert to using ControlledString
All of the places that parse controls now use ControlledString instead of doing their own stuff. -\(o-o)/-
Diffstat (limited to 'src/test/java/bjc/everge/TestUtils.java')
-rw-r--r--src/test/java/bjc/everge/TestUtils.java72
1 files changed, 68 insertions, 4 deletions
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<ReplPair> lrp = null;
@@ -98,7 +106,9 @@ public class TestUtils {
}
public static void assertReplacesTo(boolean logRep, String right, List<ReplPair> 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]);
+ }
+ }
}