use of com.esaulpaugh.headlong.abi.IntType in project headlong by esaulpaugh.
the class SuperSerialTest method testParseArgs.
@Test
public void testParseArgs() throws Throwable {
String boolArrStr = "['00', '01', '01']";
TupleType tt = TupleType.parse("(bool[])");
Tuple tuple = tt.parseArgument("(\n" + boolArrStr + "\n)");
boolean[] arr0 = tuple.get(0);
assertArrayEquals(new boolean[] { false, true, true }, arr0);
boolean[] arr1 = (boolean[]) tt.get(0).parseArgument(boolArrStr);
assertArrayEquals(arr0, arr1);
IntType int32 = TupleType.parse("(int32)").get(0);
assertEquals(Integer.MIN_VALUE, int32.parseArgument(Integer.toString(Integer.MIN_VALUE)));
assertEquals(Integer.MAX_VALUE, int32.parseArgument(Integer.toString(Integer.MAX_VALUE)));
IntType int8 = TupleType.parse("(int8)").get(0);
TestUtils.assertThrown(IllegalArgumentException.class, "signed val exceeds bit limit: 8 >= 8", () -> int8.parseArgument("-129"));
TestUtils.assertThrown(IllegalArgumentException.class, "signed val exceeds bit limit: 8 >= 8", () -> int8.parseArgument("128"));
BooleanType bool = TupleType.parse("(bool)").get(0);
Object bool2 = TypeFactory.create("bool");
assertEquals(bool, bool2);
TypeFactory.createNonCapturing("bool").encode(true);
assertEquals(true, bool.parseArgument("true"));
assertEquals(true, bool.parseArgument("TRUE"));
assertEquals(true, bool.parseArgument("tRUe"));
assertEquals(false, bool.parseArgument("false"));
assertEquals(false, bool.parseArgument(""));
assertEquals(false, bool.parseArgument("?\t*jjgHJge"));
assertEquals(127, int8.parseArgument("127"));
assertEquals(127, int8.parseArgument("0127"));
assertEquals(127, int8.parseArgument("00127"));
}
Aggregations