From 3757f226320c77424668093a0c99f1bc6d67c102 Mon Sep 17 00:00:00 2001 From: Nathan VanBenschoten Date: Wed, 14 Aug 2024 14:41:26 -0400 Subject: [PATCH 1/2] apd: fix TestFormatFlags on go 1.23 Fixes #138. The test was failing due to https://github.com/golang/go/commit/6dfd7a543517db868ef4f31e91fe56aba5bc8ea0. This commit fixes it. --- decimal_test.go | 33 ++++++++++++++++++++++++++++++++- 1 file changed, 32 insertions(+), 1 deletion(-) diff --git a/decimal_test.go b/decimal_test.go index ef6a475..bc00e04 100644 --- a/decimal_test.go +++ b/decimal_test.go @@ -491,6 +491,22 @@ func TestFormat(t *testing.T) { } } +// fmtAllowsPaddingAndMinusFlags is set to true if the %-0 flag combination is +// allowed. This combination was not allowed before Go 1.23, but it is allowed +// in Go 1.23 and later. See https://github.com/golang/go/issues/61784 for +// details. +var fmtAllowsPaddingAndMinusFlags bool + +// The following type definition, customer formatter implementation, and init +// function are used to test for fmtAllowsPaddingAndMinusFlags. +type fmtAllowsPaddingAndMinusFlagsHelper struct{} + +func (fmtAllowsPaddingAndMinusFlagsHelper) Format(s fmt.State, format rune) { + fmtAllowsPaddingAndMinusFlags = s.Flag('-') && s.Flag('0') +} + +func init() { fmt.Printf("%-0s", fmtAllowsPaddingAndMinusFlagsHelper{}) } + func TestFormatFlags(t *testing.T) { const stdD = "1.23E+56" tests := []struct { @@ -531,7 +547,22 @@ func TestFormatFlags(t *testing.T) { { d: stdD, fmt: "%-010G", - out: "1.23E+56 ", + out: func() string { + if !fmtAllowsPaddingAndMinusFlags { + return "1.23E+56 " + } + return "001.23E+56" + }(), + }, + { + d: stdD, + fmt: "%0-10G", + out: func() string { + if !fmtAllowsPaddingAndMinusFlags { + return "1.23E+56 " + } + return "001.23E+56" + }(), }, { d: "nan", From 137c9cd96f6741b397eb4233a7e0924687df1697 Mon Sep 17 00:00:00 2001 From: Nathan VanBenschoten Date: Wed, 14 Aug 2024 14:42:40 -0400 Subject: [PATCH 2/2] apd: add go 1.23 testing to CI This commit adds a test variant for go 1.23. --- .github/workflows/go.yml | 7 ++++--- bigint_go1.15_test.go | 2 +- 2 files changed, 5 insertions(+), 4 deletions(-) diff --git a/.github/workflows/go.yml b/.github/workflows/go.yml index 6ff073a..db2bc74 100644 --- a/.github/workflows/go.yml +++ b/.github/workflows/go.yml @@ -27,6 +27,7 @@ jobs: - '1.20' - '1.21' - '1.22' + - '1.23' steps: - uses: actions/checkout@v2 @@ -62,10 +63,10 @@ jobs: run: go vet -unsafeptr=false ./... - name: 'Staticcheck' - # staticcheck requires go1.19. - if: ${{ matrix.arch == 'x64' && matrix.go >= '1.19' }} + # staticcheck requires go1.22. + if: ${{ matrix.arch == 'x64' && matrix.go >= '1.22' }} run: | - go install honnef.co/go/tools/cmd/staticcheck@v0.4.3 + go install honnef.co/go/tools/cmd/staticcheck@v0.5.0 staticcheck ./... - name: 'GCAssert' diff --git a/bigint_go1.15_test.go b/bigint_go1.15_test.go index fd04115..83a16bf 100644 --- a/bigint_go1.15_test.go +++ b/bigint_go1.15_test.go @@ -65,7 +65,7 @@ func TestBigIntFillBytes(t *testing.T) { "0xffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff", } { t.Run(n, func(t *testing.T) { - t.Logf(n) + t.Log(n) x, ok := new(BigInt).SetString(n, 0) if !ok { panic("invalid test entry")