Search in sources :

Example 1 with IntType

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"));
}
Also used : TupleType(com.esaulpaugh.headlong.abi.TupleType) BooleanType(com.esaulpaugh.headlong.abi.BooleanType) Tuple(com.esaulpaugh.headlong.abi.Tuple) IntType(com.esaulpaugh.headlong.abi.IntType) Test(org.junit.jupiter.api.Test)

Aggregations

BooleanType (com.esaulpaugh.headlong.abi.BooleanType)1 IntType (com.esaulpaugh.headlong.abi.IntType)1 Tuple (com.esaulpaugh.headlong.abi.Tuple)1 TupleType (com.esaulpaugh.headlong.abi.TupleType)1 Test (org.junit.jupiter.api.Test)1