Commit bb3b24bf authored by Rob Pike's avatar Rob Pike

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/151218Reviewed-by: 's avatarBrad Fitzpatrick <bradfitz@golang.org>
Run-TryBot: Brad Fitzpatrick <bradfitz@golang.org>
parent cf205408
......@@ -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"]
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment