|
|
@@ -17,13 +17,56 @@ import java.util.regex.Pattern;
|
|
|
import net.ranides.assira.generic.HashUtils;
|
|
|
import net.ranides.assira.generic.SerializationUtils;
|
|
|
import org.junit.Test;
|
|
|
-import static org.junit.Assert.*;
|
|
|
+import static net.ranides.assira.junit.NewAssert.*;
|
|
|
|
|
|
/**
|
|
|
*
|
|
|
* @author Ranides Atterwim <ranides@gmail.com>
|
|
|
*/
|
|
|
+@SuppressWarnings("PMD.AvoidDuplicateLiterals")
|
|
|
public class ResolveFormatTest {
|
|
|
+
|
|
|
+ @Test
|
|
|
+ public void testSerialization() throws IOException {
|
|
|
+ ResolveFormat a = ResolveFormat.compile("{x} {y} {z}");
|
|
|
+ ResolveFormat b = SerializationUtils.copy(a);
|
|
|
+
|
|
|
+ assertNotSame(a, b);
|
|
|
+ assertEquals(a, b);
|
|
|
+
|
|
|
+ assertEquals("5 6 7", b.format(new A(5,6,7)));
|
|
|
+ }
|
|
|
+
|
|
|
+ @Test
|
|
|
+ public void testBasics() throws IOException {
|
|
|
+ ResolveFormat a = ResolveFormat.compile("{x} {y} {z}");
|
|
|
+ ResolveFormat b = ResolveFormat.compile("US","{x} {y} {z}");
|
|
|
+
|
|
|
+ assertEquals("{x} {y} {z}", a.pattern());
|
|
|
+ assertEquals("{x} {y} {z}", b.pattern());
|
|
|
+
|
|
|
+ assertEquals(ResolveDialect.getDefault(), a.dialect());
|
|
|
+ assertEquals(ResolveDialect.getInstance("US"), b.dialect());
|
|
|
+ }
|
|
|
+
|
|
|
+ @Test
|
|
|
+ public void testEquals() {
|
|
|
+ ResolveFormat a = ResolveFormat.compile("PL", "{x} {y} {z}");
|
|
|
+ ResolveFormat b = ResolveFormat.compile("PL", "{x} {y} {z}");
|
|
|
+ ResolveFormat c = ResolveFormat.compile("PL", "{x} {y} {r}");
|
|
|
+ ResolveFormat d = ResolveFormat.compile("US", "{x} {y} {z}");
|
|
|
+ ResolveFormat e = ResolveFormat.compile("US", "{x} {y} {r}");
|
|
|
+ String f = "Hello";
|
|
|
+
|
|
|
+ assertSymNotEquals(a, null);
|
|
|
+ assertSymNotEquals(a, c);
|
|
|
+ assertSymNotEquals(a, d);
|
|
|
+ assertSymNotEquals(a, e);
|
|
|
+ assertSymNotEquals(a, f);
|
|
|
+
|
|
|
+ assertSymEquals(a, a);
|
|
|
+ assertSymEquals(a, b);
|
|
|
+ }
|
|
|
|
|
|
@Test
|
|
|
public void testFormat_Number() {
|
|
|
@@ -158,6 +201,17 @@ public class ResolveFormatTest {
|
|
|
assertEquals("-1.5E3", ResolveFormat.compile("{bdvalue,metric/e,#.0}").format(ITEM));
|
|
|
}
|
|
|
|
|
|
+ @Test
|
|
|
+ public void testFormat_Metric_BigInteger_128() {
|
|
|
+ assertEquals("-1.542Y", ResolveFormat.compile("{value128,metric}").format(ITEM));
|
|
|
+ assertEquals("-1.542Y", ResolveFormat.compile("{value128,metric/si}").format(ITEM));
|
|
|
+ assertEquals("-1.542E24", ResolveFormat.compile("{value128,metric/e}").format(ITEM));
|
|
|
+
|
|
|
+ assertEquals("-1.5Y", ResolveFormat.compile("{value128,metric,#.0}").format(ITEM));
|
|
|
+ assertEquals("-1.5Y", ResolveFormat.compile("{value128,metric/si,#.0}").format(ITEM));
|
|
|
+ assertEquals("-1.5E24", ResolveFormat.compile("{value128,metric/e,#.0}").format(ITEM));
|
|
|
+ }
|
|
|
+
|
|
|
@Test
|
|
|
public void testFormat_Metric_BigDecimal() {
|
|
|
assertEquals("-154.2k", ResolveFormat.compile("{bivalue,metric}").format(ITEM));
|
|
|
@@ -221,17 +275,7 @@ public class ResolveFormatTest {
|
|
|
assertEquals("-150.6KK", ResolveFormat.compile("{bivalue,binary/knuth,#.0}").format(ITEM));
|
|
|
assertEquals("-150.6B3", ResolveFormat.compile("{bivalue,binary/e,#.0}").format(ITEM));
|
|
|
}
|
|
|
-
|
|
|
- @Test
|
|
|
- public void testFormat_Pattern_Array() {
|
|
|
- String r1 = ResolveUtils.format("Hello {1} world {2}{3}!", new int[]{17, 19, 47, 33});
|
|
|
- String r2 = ResolveUtils.vformat("Hello {1} world {2}{3}!", 17, 19, 47, 33);
|
|
|
- String r3 = ResolveUtils.vformat("Hello {0} world!", 17);
|
|
|
- assertEquals("Hello 19 world 4733!", r1);
|
|
|
- assertEquals("Hello 19 world 4733!", r2);
|
|
|
- assertEquals("Hello 17 world!", r3);
|
|
|
- }
|
|
|
-
|
|
|
+
|
|
|
@Test
|
|
|
public void testFormat_Pattern_Matcher() {
|
|
|
String source ="AH-ello";
|
|
|
@@ -256,17 +300,6 @@ public class ResolveFormatTest {
|
|
|
assertEquals("Hello 77 t world ?", r2);
|
|
|
}
|
|
|
|
|
|
- @Test
|
|
|
- public void testSerialization() throws IOException {
|
|
|
- ResolveFormat a = ResolveFormat.compile("{x} {y} {z}");
|
|
|
- ResolveFormat b = SerializationUtils.copy(a);
|
|
|
-
|
|
|
- assertNotSame(a, b);
|
|
|
- assertEquals(a, b);
|
|
|
-
|
|
|
- assertEquals("5 6 7", b.format(new A(5,6,7)));
|
|
|
- }
|
|
|
-
|
|
|
private static final class Wrapper {
|
|
|
public Object[] items;
|
|
|
|
|
|
@@ -343,5 +376,8 @@ public class ResolveFormatTest {
|
|
|
|
|
|
public BigDecimal bdvalue = BigDecimal.valueOf(-1542.50);
|
|
|
|
|
|
+ public BigInteger value128 = new BigInteger("-1542000000000000000000000");
|
|
|
+
|
|
|
};
|
|
|
+
|
|
|
}
|