From 121b6d8e6f7a07cd119def27aaddc9e1e83dae1d Mon Sep 17 00:00:00 2001 From: Rose Hogenson Date: Sun, 26 Oct 2025 08:31:12 -0700 Subject: Refine numeric literal syntax Leading zeros are no longer permitted in decimal literals, which is technically a backwards-incompatible change, but I consider it to be something like a bug fix. Anyway, the project is unlikely to have any users that would be impacted. --- asspb_test.go | 27 +++++++++++++++++++++++++++ 1 file changed, 27 insertions(+) (limited to 'asspb_test.go') diff --git a/asspb_test.go b/asspb_test.go index 7600dee..2425571 100644 --- a/asspb_test.go +++ b/asspb_test.go @@ -42,18 +42,38 @@ field_repeated [5, 6] msg: `field: "strings can just span multiple lines"`, want: map[string]any{"field": "strings\ncan just span multiple lines"}, + }, { + desc: "Zero", + msg: `field: 0`, + want: map[string]any{"field": 0.}, }, { desc: "Hex", msg: `field: 0xff`, want: map[string]any{"field": 255.}, + }, { + desc: "CapitalHex", + msg: `field: 0XfF`, + want: map[string]any{"field": 255.}, + }, { + desc: "HexLeadingZero", + msg: `field: 0x0f`, + want: map[string]any{"field": 15.}, }, { desc: "Float", msg: `field: 1.5e10`, want: map[string]any{"field": 1.5e10}, + }, { + desc: "FloatCapitalE", + msg: `field: 1.5E10`, + want: map[string]any{"field": 1.5e10}, }, { desc: "NegativeFloat", msg: `field: -1.5e-10`, want: map[string]any{"field": -1.5e-10}, + }, { + desc: "PositiveFloat", + msg: `field: +1.5e+10`, + want: map[string]any{"field": 1.5e10}, }, { desc: "Int", msg: `field: 10`, @@ -62,6 +82,10 @@ can just span multiple lines"`, desc: "NegativeInt", msg: `field: -10`, want: map[string]any{"field": -10.}, + }, { + desc: "PositiveInt", + msg: `field: +10`, + want: map[string]any{"field": 10.}, }, { desc: "String", msg: `field: 'asdf'`, @@ -238,6 +262,9 @@ func TestUnmarshal_Invalid(t *testing.T) { }, { desc: "ListBadMsgVal", msg: `field [{asdf}]`, + }, { + desc: "IntLeadingZero", + msg: `field: 0644`, }} { t.Run(tc.desc, func(t *testing.T) { t.Parallel() -- cgit v1.3.1