@@ -164,3 +164,79 @@ func TestBSONWalk6(test *testing.T) {
164
164
}
165
165
166
166
}
167
+
168
+ func TestBSONWalk7 (test * testing.T ) {
169
+ doc := bson.D {{"a" , 111 }, {"b" , 3 }}
170
+ walker := & testWalker {}
171
+ doc , err := BSONWalk (doc , "a" , walker )
172
+ if err != nil {
173
+ test .Errorf ("why did we get an error %s" , err )
174
+ }
175
+ if len (doc ) != 1 {
176
+ test .Errorf ("didn't delete 1 %s" , doc )
177
+ }
178
+ if doc [0 ].Name != "b" {
179
+ test .Errorf ("deleted wrong one? %s" , doc )
180
+ }
181
+
182
+ }
183
+
184
+ func TestBSONWalk8 (test * testing.T ) {
185
+ doc := bson.D {{"b" , 11 }, {"a" , 111 }}
186
+ walker := & testWalker {}
187
+ doc , err := BSONWalk (doc , "a" , walker )
188
+ if err != nil {
189
+ test .Errorf ("why did we get an error %s" , err )
190
+ }
191
+ if len (doc ) != 1 {
192
+ test .Errorf ("didn't delete 1 %s" , doc )
193
+ }
194
+ if doc [0 ].Name != "b" {
195
+ test .Errorf ("deleted wrong one? %s" , doc )
196
+ }
197
+
198
+ }
199
+
200
+ func TestBSONWalk9 (test * testing.T ) {
201
+ doc := bson.D {{"b" , 11 }, {"a" , 111 }, {"c" , 12 }}
202
+ walker := & testWalker {}
203
+ doc , err := BSONWalk (doc , "a" , walker )
204
+ if err != nil {
205
+ test .Errorf ("why did we get an error %s" , err )
206
+ }
207
+ if len (doc ) != 2 {
208
+ test .Errorf ("didn't delete 1 %s" , doc )
209
+ }
210
+ if doc [0 ].Name != "b" {
211
+ test .Errorf ("deleted wrong one? %s" , doc )
212
+ }
213
+ if doc [1 ].Name != "c" {
214
+ test .Errorf ("deleted wrong one? %s" , doc )
215
+ }
216
+
217
+ }
218
+
219
+ func TestBSONWalk10 (test * testing.T ) {
220
+ doc := bson.D {{"b" , 11 }, {"a" , bson.D {{"x" , 1 }, {"y" , 111 }}}, {"c" , 12 }}
221
+ walker := & testWalker {}
222
+ doc , err := BSONWalk (doc , "a.y" , walker )
223
+ if err != nil {
224
+ test .Errorf ("why did we get an error %s" , err )
225
+ }
226
+ if len (doc ) != 3 {
227
+ test .Errorf ("what did i do! %s" , doc )
228
+ }
229
+
230
+ if doc [1 ].Name != "a" {
231
+ test .Errorf ("what did i do! %s" , doc )
232
+ }
233
+
234
+ sub := doc [1 ].Value .(bson.D )
235
+ if len (sub ) != 1 {
236
+ test .Errorf ("didn't delete %s" , doc )
237
+ }
238
+ if sub [0 ].Name != "x" {
239
+ test .Errorf ("deleted wrong one? %s" , doc )
240
+ }
241
+
242
+ }
0 commit comments