@@ -36,7 +36,44 @@ 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 && rhs .StringValue != nil {
62
+ return * v .StringValue == * rhs .StringValue
63
+ }
64
+ if v .BooleanValue != nil && rhs .BooleanValue != nil {
65
+ return * v .BooleanValue == * rhs .BooleanValue
66
+ }
67
+ if v .ListValue != nil && rhs .ListValue != nil {
68
+ return v .ListValue .Equals (rhs .ListValue )
69
+ }
70
+ if v .MapValue != nil && rhs .MapValue != nil {
71
+ return v .MapValue .Equals (rhs .MapValue )
72
+ }
73
+ if v .Null && rhs .Null {
74
+ return true
75
+ }
76
+ return false
40
77
}
41
78
42
79
// Less provides a total ordering for Value (so that they can be sorted, even
@@ -187,6 +224,20 @@ type List struct {
187
224
Items []Value
188
225
}
189
226
227
+ // Equals compares two lists lexically.
228
+ func (l * List ) Equals (rhs * List ) bool {
229
+ if len (l .Items ) != len (rhs .Items ) {
230
+ return false
231
+ }
232
+
233
+ for i , lv := range l .Items {
234
+ if ! lv .Equals (rhs .Items [i ]) {
235
+ return false
236
+ }
237
+ }
238
+ return true
239
+ }
240
+
190
241
// Less compares two lists lexically.
191
242
func (l * List ) Less (rhs * List ) bool {
192
243
i := 0
@@ -244,6 +295,23 @@ func (m *Map) computeOrder() []int {
244
295
return m .order
245
296
}
246
297
298
+ // Equals compares two maps lexically.
299
+ func (m * Map ) Equals (rhs * Map ) bool {
300
+ if len (m .Items ) != len (rhs .Items ) {
301
+ return false
302
+ }
303
+ for _ , lfield := range m .Items {
304
+ rfield , ok := rhs .Get (lfield .Name )
305
+ if ! ok {
306
+ return false
307
+ }
308
+ if ! lfield .Value .Equals (rfield .Value ) {
309
+ return false
310
+ }
311
+ }
312
+ return true
313
+ }
314
+
247
315
// Less compares two maps lexically.
248
316
func (m * Map ) Less (rhs * Map ) bool {
249
317
var noAllocL , noAllocR [2 ]int
0 commit comments