Skip to content

Commit

Permalink
Merge pull request #139 from nvanbenschoten/nvanbenschoten/testGo23
Browse files Browse the repository at this point in the history
apd: fix TestFormatFlags on go 1.23, add go 1.23 to CI
  • Loading branch information
nvanbenschoten authored Aug 15, 2024
2 parents 1ebf545 + 137c9cd commit 9cfbeb8
Show file tree
Hide file tree
Showing 3 changed files with 37 additions and 5 deletions.
7 changes: 4 additions & 3 deletions .github/workflows/go.yml
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ jobs:
- '1.20'
- '1.21'
- '1.22'
- '1.23'

steps:
- uses: actions/checkout@v2
Expand Down Expand Up @@ -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'
Expand Down
2 changes: 1 addition & 1 deletion bigint_go1.15_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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")
Expand Down
33 changes: 32 additions & 1 deletion decimal_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down Expand Up @@ -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",
Expand Down

0 comments on commit 9cfbeb8

Please sign in to comment.