@@ -36,7 +36,60 @@ type Value struct {
36
36
37
37
// Equals returns true iff the two values are equal.
38
38
func (v Value ) Equals (rhs Value ) bool {
39
- return ! v .Less (rhs ) && ! rhs .Less (v )
39
+ if v .IntValue != nil && rhs .IntValue != nil {
40
+ return * v .IntValue == * rhs .IntValue
41
+ }
42
+ if v .FloatValue != nil || rhs .FloatValue != nil {
43
+ lf := float64 (0.0 )
44
+ if v .FloatValue != nil {
45
+ lf = float64 (* v .FloatValue )
46
+ } else if v .IntValue != nil {
47
+ lf = float64 (* v .IntValue )
48
+ } else {
49
+ return false
50
+ }
51
+ rf := 0.0
52
+ if rhs .FloatValue != nil {
53
+ rf = float64 (* rhs .FloatValue )
54
+ } else if rhs .IntValue != nil {
55
+ rf = float64 (* rhs .IntValue )
56
+ } else {
57
+ return false
58
+ }
59
+ return lf == rf
60
+ }
61
+ if v .StringValue != nil {
62
+ if rhs .StringValue != nil {
63
+ return * v .StringValue == * rhs .StringValue
64
+ }
65
+ return false
66
+ }
67
+ if v .BooleanValue != nil {
68
+ if rhs .BooleanValue != nil {
69
+ return * v .BooleanValue == * rhs .BooleanValue
70
+ }
71
+ return false
72
+ }
73
+ if v .ListValue != nil {
74
+ if rhs .ListValue != nil {
75
+ return v .ListValue .Equals (rhs .ListValue )
76
+ }
77
+ return false
78
+ }
79
+ if v .MapValue != nil {
80
+ if rhs .MapValue != nil {
81
+ return v .MapValue .Equals (rhs .MapValue )
82
+ }
83
+ return false
84
+ }
85
+ if v .Null {
86
+ if rhs .Null {
87
+ return true
88
+ }
89
+ return false
90
+ }
91
+ // No field is set, on either objects.
92
+ return true
40
93
}
41
94
42
95
// Less provides a total ordering for Value (so that they can be sorted, even
@@ -187,6 +240,20 @@ type List struct {
187
240
Items []Value
188
241
}
189
242
243
+ // Equals compares two lists lexically.
244
+ func (l * List ) Equals (rhs * List ) bool {
245
+ if len (l .Items ) != len (rhs .Items ) {
246
+ return false
247
+ }
248
+
249
+ for i , lv := range l .Items {
250
+ if ! lv .Equals (rhs .Items [i ]) {
251
+ return false
252
+ }
253
+ }
254
+ return true
255
+ }
256
+
190
257
// Less compares two lists lexically.
191
258
func (l * List ) Less (rhs * List ) bool {
192
259
i := 0
@@ -244,6 +311,23 @@ func (m *Map) computeOrder() []int {
244
311
return m .order
245
312
}
246
313
314
+ // Equals compares two maps lexically.
315
+ func (m * Map ) Equals (rhs * Map ) bool {
316
+ if len (m .Items ) != len (rhs .Items ) {
317
+ return false
318
+ }
319
+ for _ , lfield := range m .Items {
320
+ rfield , ok := rhs .Get (lfield .Name )
321
+ if ! ok {
322
+ return false
323
+ }
324
+ if ! lfield .Value .Equals (rfield .Value ) {
325
+ return false
326
+ }
327
+ }
328
+ return true
329
+ }
330
+
247
331
// Less compares two maps lexically.
248
332
func (m * Map ) Less (rhs * Map ) bool {
249
333
var noAllocL , noAllocR [2 ]int
0 commit comments