From 08e5e4d9560ac248bb84e623eee4a25017c8637c Mon Sep 17 00:00:00 2001 From: Daniele Sluijters Date: Sun, 2 Oct 2022 19:11:37 +0200 Subject: Support different integer formats In Go you can format numbers in different ways, as doucment in https://go.dev/ref/spec#Integer_literals. ParseInt with a base of 0 will infer the correct base for the number based on a prefix 0x, 0b etc, and also supports the use of the _ to separate digits. This can be helpful with long numbers, to make things easier to read. This switches the ParseInt() calls to use a base of 0, ensuring that if ParseValue is called with an int like 100_000 it'll parse correctly instead of throw an error. --- scalar_test.go | 2 ++ 1 file changed, 2 insertions(+) (limited to 'scalar_test.go') diff --git a/scalar_test.go b/scalar_test.go index 1c51c77..e1fc03d 100644 --- a/scalar_test.go +++ b/scalar_test.go @@ -48,6 +48,7 @@ func TestParseValue(t *testing.T) { // integers assertParse(t, int(123), "123") + assertParse(t, int(123), "1_2_3") assertParse(t, int8(123), "123") assertParse(t, int16(123), "123") assertParse(t, int32(123), "123") @@ -55,6 +56,7 @@ func TestParseValue(t *testing.T) { // unsigned integers assertParse(t, uint(123), "123") + assertParse(t, uint(123), "1_2_3") assertParse(t, byte(123), "123") assertParse(t, uint8(123), "123") assertParse(t, uint16(123), "123") -- cgit v1.2.3