@@ -11,25 +11,37 @@ fn compare_docs(doc1: &Document, doc2: &Document) -> bool {
1111 return false ;
1212 }
1313 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 {
1519 return false ;
1620 }
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 ;
2836 }
2937 }
38+ true
3039 }
40+ ( Bson :: JavaScriptCodeWithScope ( jsc1) , Bson :: JavaScriptCodeWithScope ( jsc2) ) => {
41+ jsc1. code == jsc2. code && compare_docs ( & jsc1. scope , & jsc2. scope )
42+ }
43+ ( v1, v2) => v1 == v2,
3144 }
32- true
3345}
3446
3547fuzz_target ! ( |input: & [ u8 ] | {
0 commit comments