From: Russ Cox Date: Mon, 30 Jan 2012 18:20:38 +0000 (-0500) Subject: fmt: add test of NaN map keys X-Git-Tag: weekly.2012-02-07~219 X-Git-Url: http://www.git.cypherpunks.su/?a=commitdiff_plain;h=e451fb8ffbca501b12611f97ec875e9544339aa0;p=gostls13.git fmt: add test of NaN map keys R=r CC=golang-dev https://golang.org/cl/5564063 --- diff --git a/src/pkg/fmt/fmt_test.go b/src/pkg/fmt/fmt_test.go index 2f92f947cd..cd0b0ce66b 100644 --- a/src/pkg/fmt/fmt_test.go +++ b/src/pkg/fmt/fmt_test.go @@ -443,6 +443,14 @@ var fmttests = []struct { {"%s", nil, "%!s()"}, {"%T", nil, ""}, {"%-1", 100, "%!(NOVERB)%!(EXTRA int=100)"}, + + // The "" show up because maps are printed by + // first obtaining a list of keys and then looking up + // each key. Since NaNs can be map keys but cannot + // be fetched directly, the lookup fails and returns a + // zero reflect.Value, which formats as . + // This test is just to check that it shows the two NaNs at all. + {"%v", map[float64]int{math.NaN(): 1, math.NaN(): 2}, "map[NaN: NaN:]"}, } func TestSprintf(t *testing.T) {