(t *testing.T)
| 24 | ) |
| 25 | |
| 26 | func TestHexOrDecimal256(t *testing.T) { |
| 27 | tests := []struct { |
| 28 | input string |
| 29 | num *big.Int |
| 30 | ok bool |
| 31 | }{ |
| 32 | {"", big.NewInt(0), true}, |
| 33 | {"0", big.NewInt(0), true}, |
| 34 | {"0x0", big.NewInt(0), true}, |
| 35 | {"12345678", big.NewInt(12345678), true}, |
| 36 | {"0x12345678", big.NewInt(0x12345678), true}, |
| 37 | {"0X12345678", big.NewInt(0x12345678), true}, |
| 38 | // Tests for leading zero behaviour: |
| 39 | {"0123456789", big.NewInt(123456789), true}, // note: not octal |
| 40 | {"00", big.NewInt(0), true}, |
| 41 | {"0x00", big.NewInt(0), true}, |
| 42 | {"0x012345678abc", big.NewInt(0x12345678abc), true}, |
| 43 | // Invalid syntax: |
| 44 | {"abcdef", nil, false}, |
| 45 | {"0xgg", nil, false}, |
| 46 | // Larger than 256 bits: |
| 47 | {"115792089237316195423570985008687907853269984665640564039457584007913129639936", nil, false}, |
| 48 | } |
| 49 | for _, test := range tests { |
| 50 | var num HexOrDecimal256 |
| 51 | err := num.UnmarshalText([]byte(test.input)) |
| 52 | if (err == nil) != test.ok { |
| 53 | t.Errorf("ParseBig(%q) -> (err == nil) == %t, want %t", test.input, err == nil, test.ok) |
| 54 | continue |
| 55 | } |
| 56 | if test.num != nil && (*big.Int)(&num).Cmp(test.num) != 0 { |
| 57 | t.Errorf("ParseBig(%q) -> %d, want %d", test.input, (*big.Int)(&num), test.num) |
| 58 | } |
| 59 | } |
| 60 | } |
| 61 | |
| 62 | func TestMustParseBig256(t *testing.T) { |
| 63 | defer func() { |
nothing calls this directly
no test coverage detected