@@ -31,7 +31,41 @@ func TestParsePseudoBigInt(t *testing.T) {
31
31
}
32
32
})
33
33
34
- // TODO(jakebailey): tests for other bases
34
+ t .Run ("parse non-decimal bases (small numbers)" , func (t * testing.T ) {
35
+ t .Parallel ()
36
+
37
+ type tc struct {
38
+ lit string
39
+ out string
40
+ }
41
+ cases := []tc {
42
+ // binary
43
+ {lit : "0b0n" , out : "0" },
44
+ {lit : "0b1n" , out : "1" },
45
+ {lit : "0b1010n" , out : "10" },
46
+ {lit : "0b1010_0101n" , out : "165" },
47
+ {lit : "0B1101n" , out : "13" }, // uppercase prefix
48
+
49
+ // octal
50
+ {lit : "0o0n" , out : "0" },
51
+ {lit : "0o7n" , out : "7" },
52
+ {lit : "0o755n" , out : "493" },
53
+ {lit : "0o7_5_5n" , out : "493" },
54
+ {lit : "0O12n" , out : "10" }, // uppercase prefix
55
+
56
+ // hex
57
+ {lit : "0x0n" , out : "0" },
58
+ {lit : "0xFn" , out : "15" },
59
+ {lit : "0xFFn" , out : "255" },
60
+ {lit : "0xF_Fn" , out : "255" },
61
+ {lit : "0X1Fn" , out : "31" }, // uppercase prefix
62
+ }
63
+
64
+ for _ , c := range cases {
65
+ got := ParsePseudoBigInt (c .lit )
66
+ assert .Equal (t , got , c .out , "literal: %q" , c .lit )
67
+ }
68
+ })
35
69
36
70
t .Run ("can parse large literals" , func (t * testing.T ) {
37
71
t .Parallel ()
0 commit comments