@@ -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
@@ -134,6 +190,20 @@ type List struct {
134
190
Items []Value
135
191
}
136
192
193
+ // Equals compares two lists lexically.
194
+ func (l * List ) Equals (rhs * List ) bool {
195
+ if len (l .Items ) != len (rhs .Items ) {
196
+ return false
197
+ }
198
+
199
+ for i , lv := range l .Items {
200
+ if ! lv .Equals (rhs .Items [i ]) {
201
+ return false
202
+ }
203
+ }
204
+ return true
205
+ }
206
+
137
207
// Less compares two lists lexically.
138
208
func (l * List ) Less (rhs * List ) bool {
139
209
i := 0
@@ -191,6 +261,23 @@ func (m *Map) computeOrder() []int {
191
261
return m .order
192
262
}
193
263
264
+ // Equals compares two maps lexically.
265
+ func (m * Map ) Equals (rhs * Map ) bool {
266
+ if len (m .Items ) != len (rhs .Items ) {
267
+ return false
268
+ }
269
+ for _ , lfield := range m .Items {
270
+ rfield , ok := rhs .Get (lfield .Name )
271
+ if ! ok {
272
+ return false
273
+ }
274
+ if ! lfield .Value .Equals (rfield .Value ) {
275
+ return false
276
+ }
277
+ }
278
+ return true
279
+ }
280
+
194
281
// Less compares two maps lexically.
195
282
func (m * Map ) Less (rhs * Map ) bool {
196
283
var noAllocL , noAllocR [2 ]int
0 commit comments