diff options
| author | Ben Culkin <scorpress@gmail.com> | 2020-10-06 20:05:00 -0400 |
|---|---|---|
| committer | Ben Culkin <scorpress@gmail.com> | 2020-10-06 20:05:00 -0400 |
| commit | 3a818da77acf50e7ea0d2c02d669cb67b9f114e3 (patch) | |
| tree | a50b5bfe0490d9d6c585c695fc6369ef8936f470 /base/src/test/java | |
| parent | a7a87f682a039d4761112f1dedb9351f3d7a2bbf (diff) | |
Add unit tests for defines
Adds unit tests for SimpleDefine and IteratedDefine.
This also fixes an issue with IteratedDefine, where once you had
consumed a replacer, it was consumed for good; you couldn't use it in
the future, even in a different call to apply().
This was fixed through the introduction of a new iterator type from
esodata - ResettableIterator. See that project/type for more details on
what exactly this does; but suffice to say, it allows to restore our
iterator and re-iterate over the same elements on every call to apply.
Diffstat (limited to 'base/src/test/java')
| -rw-r--r-- | base/src/test/java/bjc/utils/test/parserutils/defines/IteratedDefineTest.java | 54 | ||||
| -rw-r--r-- | base/src/test/java/bjc/utils/test/parserutils/defines/SimpleDefineTest.java | 42 |
2 files changed, 96 insertions, 0 deletions
diff --git a/base/src/test/java/bjc/utils/test/parserutils/defines/IteratedDefineTest.java b/base/src/test/java/bjc/utils/test/parserutils/defines/IteratedDefineTest.java new file mode 100644 index 0000000..944ae07 --- /dev/null +++ b/base/src/test/java/bjc/utils/test/parserutils/defines/IteratedDefineTest.java @@ -0,0 +1,54 @@ +package bjc.utils.test.parserutils.defines; + +import static org.junit.Assert.*; + +import org.junit.Test; + +import bjc.utils.parserutils.defines.IteratedDefine; + +/** + * Test {@link IteratedDefine} + * @author Ben Culkin + * + */ +public class IteratedDefineTest { + + /** + * Do testing of iterated define. + */ + @Test + public void testSingle() { + IteratedDefine itrd = new IteratedDefine("a", false, "b"); + + assertEquals("c", itrd.apply("c")); + assertEquals("b", itrd.apply("a")); + assertEquals("bb", itrd.apply("aa")); + } + + /** + * Test iterated define with multiple patterns. + */ + @Test + public void testMultiple() { + IteratedDefine itrd = new IteratedDefine("a", false, "b", "c"); + + assertEquals("d", itrd.apply("d")); + assertEquals("b", itrd.apply("a")); + assertEquals("bc", itrd.apply("aa")); + assertEquals("bcc", itrd.apply("aaa")); + } + + /** + * Test iterated define with circular patterns. + */ + @Test + public void testCircular() { + IteratedDefine itrd = new IteratedDefine("a", true, "b", "c"); + + assertEquals("d", itrd.apply("d")); + assertEquals("b", itrd.apply("a")); + assertEquals("bc", itrd.apply("aa")); + assertEquals("bcb", itrd.apply("aaa")); + assertEquals("bcbcb", itrd.apply("aaaaa")); + } +} diff --git a/base/src/test/java/bjc/utils/test/parserutils/defines/SimpleDefineTest.java b/base/src/test/java/bjc/utils/test/parserutils/defines/SimpleDefineTest.java new file mode 100644 index 0000000..035d33b --- /dev/null +++ b/base/src/test/java/bjc/utils/test/parserutils/defines/SimpleDefineTest.java @@ -0,0 +1,42 @@ +package bjc.utils.test.parserutils.defines; + +import static org.junit.Assert.*; + +import org.junit.Test; + +import bjc.utils.parserutils.defines.SimpleDefine; + +/** + * Test of SimpleDefine. + * @author Ben Culkin + * + */ +public class SimpleDefineTest { + + /** + * Test literal patterns. + */ + @Test + public void testLiteralPatterns() { + SimpleDefine sd = new SimpleDefine("a b", "b a"); + + assertEquals("a a a a", sd.apply("a a a a")); + assertEquals("b a", sd.apply("a b")); + assertEquals("a a b a", sd.apply("a a a b")); + assertEquals("b a b a", sd.apply("a b a b")); + } + + /** + * Test regex patterns. + */ + @Test + public void testRegexPatterns() { + SimpleDefine sd2 = new SimpleDefine("a+", "b"); + + assertEquals("c", sd2.apply("c")); + assertEquals("b", sd2.apply("a")); + assertEquals("b", sd2.apply("aaa")); + assertEquals("bb", sd2.apply("aaab")); + } + +} |
