A RetroSearch Logo

Home - News ( United States | United Kingdom | Italy | Germany ) - Football scores

Search Query:

Showing content from https://github.com/golang/go/issues/22936 below:

for test only check format strings for core libraries · Issue #22936 · golang/go · GitHub

Please answer these questions before submitting your issue. Thanks!

What version of Go are you using (go version)?

tip

What did you do?

$ go test
// file: foo_test.go
package foo

import (
"testing"

"golang.org/x/text/number"
"golang.org/x/text/language"
"golang.org/x/text/message"

)

func TestPrint(t *testing.T) {
p := message.NewPrinter(language.English)
p.Printf("num %f", number.Decimal(1.0))
}

What did you expect to see?

Print "num 1"

What did you see instead?

./foo_test.go:13: Printf format %f has arg number.Decimal(1.0) of wrong type golang.org/x/text/number.Formatter

Package message is mostly plug-in compatible with fmt. However, it has its own implementation of the parser which is more relaxed. In this case, the passed formatter implements an extended version of fmt.Formatter, which is not compatible. It is possible fmt.Format and cast it's State argument to the x/text version, but the more general point is that one cannot generally assume that format string passed to fmt are the same as those passed to other packages.
For go test, the format vet checks should, regrettably, only apply to packages defined in core.

Other examples where x/text may differ:

See Issue #18085.


RetroSearch is an open source project built by @garambo | Open a GitHub Issue

Search and Browse the WWW like it's 1997 | Search results from DuckDuckGo

HTML: 3.2 | Encoding: UTF-8 | Version: 0.7.4