Skip to content

Commit

Permalink
fmt: update formatting example for maps
Browse files Browse the repository at this point in the history
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 <[email protected]>
Run-TryBot: Brad Fitzpatrick <[email protected]>
  • Loading branch information
robpike committed Nov 26, 2018
1 parent cf20540 commit bb3b24b
Showing 1 changed file with 6 additions and 7 deletions.
13 changes: 6 additions & 7 deletions src/fmt/example_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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"]
Expand Down

0 comments on commit bb3b24b

Please sign in to comment.