|
|
@@ -0,0 +1,83 @@
|
|
|
+/*
|
|
|
+ * @author Ranides Atterwim <ranides@gmail.com>
|
|
|
+ * @copyright Ranides Atterwim
|
|
|
+ * @license WTFPL
|
|
|
+ * @url http://ranides.net/projects/assira
|
|
|
+ */
|
|
|
+package net.ranides.assira.text;
|
|
|
+
|
|
|
+import net.ranides.assira.math.HashHelper;
|
|
|
+import org.junit.Test;
|
|
|
+import static org.junit.Assert.*;
|
|
|
+
|
|
|
+/**
|
|
|
+ *
|
|
|
+ * @author Ranides Atterwim <ranides@gmail.com>
|
|
|
+ */
|
|
|
+public class ResolveScannerTest {
|
|
|
+
|
|
|
+ public ResolveScannerTest() {
|
|
|
+ }
|
|
|
+
|
|
|
+ @Test
|
|
|
+ public void testCompile() {
|
|
|
+ // that's only "smoke test"
|
|
|
+ // we will test if compilation is correct in other tests
|
|
|
+ ResolveScanner scanner1 = ResolveScanner.compile("{x} {y} {z}");
|
|
|
+ assertEquals("{x} {y} {z}", scanner1.pattern());
|
|
|
+ }
|
|
|
+
|
|
|
+ @Test
|
|
|
+ public void testScan() {
|
|
|
+ A target = new A();
|
|
|
+
|
|
|
+ assertTrue( ResolveScanner.scan("12/37 45", "{x}/{y} {z}", target) );
|
|
|
+ assertEquals(new A(12, 37, 45), target);
|
|
|
+
|
|
|
+ assertTrue( ResolveScanner.scan("23 45 56", "{x} {y} {z}", target) );
|
|
|
+ assertEquals(new A(23, 45, 56), target);
|
|
|
+
|
|
|
+ assertTrue( ResolveScanner.scan("32-54-65", "{x}-{y}-{z}", target) );
|
|
|
+ assertEquals(new A(32, 54, 65), target);
|
|
|
+ }
|
|
|
+
|
|
|
+ private static class A {
|
|
|
+
|
|
|
+ public int x;
|
|
|
+ public int y;
|
|
|
+ public int z;
|
|
|
+
|
|
|
+ public A() {
|
|
|
+ this(0,0,0);
|
|
|
+ }
|
|
|
+
|
|
|
+ public A(int x, int y, int z) {
|
|
|
+ this.x = x;
|
|
|
+ this.y = y;
|
|
|
+ this.z = z;
|
|
|
+ }
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public int hashCode() {
|
|
|
+ return HashHelper.hashValues(5, 37, x, y, z);
|
|
|
+ }
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public boolean equals(Object object) {
|
|
|
+ if(!(object instanceof A)) {
|
|
|
+ return false;
|
|
|
+ }
|
|
|
+ final A other = (A) object;
|
|
|
+ return
|
|
|
+ (this.x == other.x) &&
|
|
|
+ (this.y == other.y) &&
|
|
|
+ (this.z == other.z);
|
|
|
+ }
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public String toString() {
|
|
|
+ return "A{" + "x=" + x + ", y=" + y + ", z=" + z + '}';
|
|
|
+ }
|
|
|
+
|
|
|
+ }
|
|
|
+}
|