MCPcopy Create free account
hub / github.com/CovenantSQL/CovenantSQL / TestHexOrDecimal256

Function TestHexOrDecimal256

utils/big_test.go:26–60  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

24)
25
26func 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
62func TestMustParseBig256(t *testing.T) {
63 defer func() {

Callers

nothing calls this directly

Calls 2

UnmarshalTextMethod · 0.95
ErrorfMethod · 0.80

Tested by

no test coverage detected