@@ -10,7 +10,6 @@ import (
1010"reflect"
1111"sort"
1212"strings"
13- "time"
1413
1514"github.com/google/go-cmp/cmp"
1615)
@@ -135,56 +134,6 @@ func ExampleOption_equalEmpty() {
135134// false
136135}
137136
138- // Equal compares map keys using Go's == operator. To use Equal itself on
139- // map keys, transform the map into something else, like a slice of
140- // key-value pairs.
141- func ExampleOption_transformMap () {
142- type KV struct {
143- K time.Time
144- V string
145- }
146- // This transformer flattens the map as a slice of sorted key-value pairs.
147- // We can now safely rely on the Time.Equal to be used for equality.
148- trans := cmp .Transformer ("" , func (m map [time.Time ]string ) (s []KV ) {
149- for k , v := range m {
150- s = append (s , KV {k , v })
151- }
152- sort .Slice (s , func (i , j int ) bool {
153- return s [i ].K .Before (s [j ].K )
154- })
155- return s
156- })
157-
158- t1 := time .Date (2009 , time .November , 10 , 23 , 0 , 0 , 0 , time .UTC )
159- t2 := time .Date (2010 , time .November , 10 , 23 , 0 , 0 , 0 , time .UTC )
160- t3 := time .Date (2011 , time .November , 10 , 23 , 0 , 0 , 0 , time .UTC )
161-
162- x := map [time.Time ]string {
163- t1 .In (time .UTC ): "0th birthday" ,
164- t2 .In (time .UTC ): "1st birthday" ,
165- t3 .In (time .UTC ): "2nd birthday" ,
166- }
167- y := map [time.Time ]string {
168- t1 .In (time .Local ): "0th birthday" ,
169- t2 .In (time .Local ): "1st birthday" ,
170- t3 .In (time .Local ): "2nd birthday" ,
171- }
172- z := map [time.Time ]string {
173- time .Now (): "a long long" ,
174- time .Now (): "time ago" ,
175- time .Now (): "in a galaxy far far away" ,
176- }
177-
178- fmt .Println (cmp .Equal (x , y , trans ))
179- fmt .Println (cmp .Equal (y , z , trans ))
180- fmt .Println (cmp .Equal (z , x , trans ))
181-
182- // Output:
183- // true
184- // false
185- // false
186- }
187-
188137// Two slices may be considered equal if they have the same elements,
189138// regardless of the order that they appear in. Transformations can be used
190139// to sort the slice.
0 commit comments