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