From 9186fe0a9773447dac5764548d3c2545f900f58c Mon Sep 17 00:00:00 2001 From: Harsh1925 Date: Tue, 2 Sep 2025 13:26:40 -0400 Subject: [PATCH 1/3] test(jsnum): add binary/oct/hex BigInt cases incl. underscores and uppercase prefixes --- internal/jsnum/pseudobigint_test.go | 37 +++++++++++++++++++++++++++++ 1 file changed, 37 insertions(+) diff --git a/internal/jsnum/pseudobigint_test.go b/internal/jsnum/pseudobigint_test.go index fbd2bcaacd..494c30cb03 100644 --- a/internal/jsnum/pseudobigint_test.go +++ b/internal/jsnum/pseudobigint_test.go @@ -33,6 +33,42 @@ 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() assert.Equal(t, ParsePseudoBigInt("123456789012345678901234567890n"), "123456789012345678901234567890") @@ -41,3 +77,4 @@ func TestParsePseudoBigInt(t *testing.T) { assert.Equal(t, ParsePseudoBigInt("0x18ee90ff6c373e0ee4e3f0ad2n"), "123456789012345678901234567890") }) } + From 81a982eab951123c112b4253498871942f3ea00b Mon Sep 17 00:00:00 2001 From: Harsh1925 Date: Tue, 9 Sep 2025 11:58:56 -0400 Subject: [PATCH 2/3] format(jsnum): apply dprint to pseudobigint_test.go --- internal/jsnum/pseudobigint_test.go | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/internal/jsnum/pseudobigint_test.go b/internal/jsnum/pseudobigint_test.go index 494c30cb03..603f752246 100644 --- a/internal/jsnum/pseudobigint_test.go +++ b/internal/jsnum/pseudobigint_test.go @@ -33,7 +33,7 @@ func TestParsePseudoBigInt(t *testing.T) { // TODO(jakebailey): tests for other bases - t.Run("parse non-decimal bases (small numbers)", func(t *testing.T) { + t.Run("parse non-decimal bases (small numbers)", func(t *testing.T) { t.Parallel() type tc struct { @@ -77,4 +77,3 @@ func TestParsePseudoBigInt(t *testing.T) { assert.Equal(t, ParsePseudoBigInt("0x18ee90ff6c373e0ee4e3f0ad2n"), "123456789012345678901234567890") }) } - From 9c4a87b6e409575baabb840dd0855999d30b2a46 Mon Sep 17 00:00:00 2001 From: Harsh1925 Date: Wed, 10 Sep 2025 11:22:10 -0400 Subject: [PATCH 3/3] test(jsnum): remove resolved TODO --- internal/jsnum/pseudobigint_test.go | 2 -- 1 file changed, 2 deletions(-) diff --git a/internal/jsnum/pseudobigint_test.go b/internal/jsnum/pseudobigint_test.go index 603f752246..db34ae4c5e 100644 --- a/internal/jsnum/pseudobigint_test.go +++ b/internal/jsnum/pseudobigint_test.go @@ -31,8 +31,6 @@ 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()