Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
36 changes: 35 additions & 1 deletion internal/jsnum/pseudobigint_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,41 @@ func TestParsePseudoBigInt(t *testing.T) {
}
})

// TODO(jakebailey): tests for other bases
t.Run("parse non-decimal bases (small numbers)", func(t *testing.T) {
t.Parallel()

type tc struct {
lit string
out string
}
cases := []tc{
// binary
{lit: "0b0n", out: "0"},
{lit: "0b1n", out: "1"},
{lit: "0b1010n", out: "10"},
{lit: "0b1010_0101n", out: "165"},
{lit: "0B1101n", out: "13"}, // uppercase prefix

// octal
{lit: "0o0n", out: "0"},
{lit: "0o7n", out: "7"},
{lit: "0o755n", out: "493"},
{lit: "0o7_5_5n", out: "493"},
{lit: "0O12n", out: "10"}, // uppercase prefix

// hex
{lit: "0x0n", out: "0"},
{lit: "0xFn", out: "15"},
{lit: "0xFFn", out: "255"},
{lit: "0xF_Fn", out: "255"},
{lit: "0X1Fn", out: "31"}, // uppercase prefix
}

for _, c := range cases {
got := ParsePseudoBigInt(c.lit)
assert.Equal(t, got, c.out, "literal: %q", c.lit)
}
})

t.Run("can parse large literals", func(t *testing.T) {
t.Parallel()
Expand Down
Loading