]> Cypherpunks repositories - gostls13.git/commitdiff
fmt: add test of NaN map keys
authorRuss Cox <rsc@golang.org>
Mon, 30 Jan 2012 18:20:38 +0000 (13:20 -0500)
committerRuss Cox <rsc@golang.org>
Mon, 30 Jan 2012 18:20:38 +0000 (13:20 -0500)
R=r
CC=golang-dev
https://golang.org/cl/5564063

src/pkg/fmt/fmt_test.go

index 2f92f947cd8a6d998440f072e37b33c1765dad36..cd0b0ce66be2e9f26e02065ace7fb7295ba79316 100644 (file)
@@ -443,6 +443,14 @@ var fmttests = []struct {
        {"%s", nil, "%!s(<nil>)"},
        {"%T", nil, "<nil>"},
        {"%-1", 100, "%!(NOVERB)%!(EXTRA int=100)"},
+
+       // The "<nil>" 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 <nil>.
+       // 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:<nil> NaN:<nil>]"},
 }
 
 func TestSprintf(t *testing.T) {