From: Rob Pike Date: Mon, 26 Nov 2018 04:58:56 +0000 (+1100) Subject: fmt: update formatting example for maps X-Git-Tag: go1.12beta1~278 X-Git-Url: http://www.git.cypherpunks.su/?a=commitdiff_plain;h=bb3b24bffc4f50c64504c1c5f899aad0281a449a;p=gostls13.git fmt: update formatting example for maps Now that maps are printed in deterministic order, the map example can have multiple keys without breaking the build. Change-Id: Iccec0cd76a3d41c75d8d4eb768ec0ac09ad9f2ad Reviewed-on: https://go-review.googlesource.com/c/151218 Reviewed-by: Brad Fitzpatrick Run-TryBot: Brad Fitzpatrick --- diff --git a/src/fmt/example_test.go b/src/fmt/example_test.go index c285175976..56ce47f836 100644 --- a/src/fmt/example_test.go +++ b/src/fmt/example_test.go @@ -290,15 +290,14 @@ func Example_formats() { // Maps formatted with %v show keys and values in their default formats. // The %#v form (the # is called a "flag" in this context) shows the map in - // the Go source format. + // the Go source format. Maps are printed in a consistent order, sorted + // by the values of the keys. isLegume := map[string]bool{ - "peanut": true, - // TODO: Include this line when maps are printed in deterministic order. - // See Issue #21095 - // "dachshund": false, + "peanut": true, + "dachshund": false, } fmt.Printf("%v %#v\n", isLegume, isLegume) - // Result: map[peanut:true] map[string]bool{"peanut":true} + // Result: map[dachshund:false peanut:true] map[string]bool{"dachshund":false, "peanut":true} // Structs formatted with %v show field values in their default formats. // The %+v form shows the fields by name, while %#v formats the struct in @@ -356,7 +355,7 @@ func Example_formats() { // (110.7+22.5i) (110.7+22.5i) (110.70+22.50i) (1.11e+02+2.25e+01i) // 128512 128512 😀 '😀' U+1F600 U+1F600 '😀' // foo "bar" foo "bar" "foo \"bar\"" `foo "bar"` - // map[peanut:true] map[string]bool{"peanut":true} + // map[dachshund:false peanut:true] map[string]bool{"dachshund":false, "peanut":true} // {Kim 22} {Name:Kim Age:22} struct { Name string; Age int }{Name:"Kim", Age:22} // &{Kim 22} 0x0 // [Katano Kobayashi Kurosawa Miyazaki Ozu] ["Katano" "Kobayashi" "Kurosawa" "Miyazaki" "Ozu"]