@@ -11,25 +11,37 @@ fn compare_docs(doc1: &Document, doc2: &Document) -> bool {
11
11
return false ;
12
12
}
13
13
for ( key, value) in doc1 {
14
- if !doc2. contains_key ( key) {
14
+ if let Some ( val2) = doc2. get ( key) {
15
+ if !compare_values ( value, val2) {
16
+ return false ;
17
+ }
18
+ } else {
15
19
return false ;
16
20
}
17
- if let Some ( val2) = doc2. get ( key) {
18
- match ( value, val2) {
19
- ( Bson :: Double ( d1) , Bson :: Double ( d2) ) => {
20
- if ( !d1. is_nan ( ) || !d2. is_nan ( ) ) && d1 != d2 {
21
- return false ;
22
- }
23
- }
24
- ( v1, v2) => {
25
- if v1 != v2 {
26
- return false ;
27
- }
21
+ }
22
+ true
23
+ }
24
+
25
+ fn compare_values ( val1 : & Bson , val2 : & Bson ) -> bool {
26
+ match ( val1, val2) {
27
+ ( Bson :: Double ( d1) , Bson :: Double ( d2) ) => ( d1. is_nan ( ) && d2. is_nan ( ) ) || d1 == d2,
28
+ ( Bson :: Document ( doc1) , Bson :: Document ( doc2) ) => compare_docs ( doc1, doc2) ,
29
+ ( Bson :: Array ( arr1) , Bson :: Array ( arr2) ) => {
30
+ if arr1. len ( ) != arr2. len ( ) {
31
+ return false ;
32
+ }
33
+ for ( subval1, subval2) in std:: iter:: zip ( arr1, arr2) {
34
+ if !compare_values ( subval1, subval2) {
35
+ return false ;
28
36
}
29
37
}
38
+ true
30
39
}
40
+ ( Bson :: JavaScriptCodeWithScope ( jsc1) , Bson :: JavaScriptCodeWithScope ( jsc2) ) => {
41
+ jsc1. code == jsc2. code && compare_docs ( & jsc1. scope , & jsc2. scope )
42
+ }
43
+ ( v1, v2) => v1 == v2,
31
44
}
32
- true
33
45
}
34
46
35
47
fuzz_target ! ( |input: & [ u8 ] | {
0 commit comments