@@ -181,8 +181,26 @@ describe('BSON Corpus', function () {
181
181
// convert inputs to native Javascript objects
182
182
const nativeFromCB = bsonToNative ( cB ) ;
183
183
184
- // round tripped EJSON should match the original
185
- expect ( nativeToCEJSON ( jsonToNative ( cEJ ) ) ) . to . equal ( cEJ ) ;
184
+ if ( cEJ . includes ( '1.2345678921232E+18' ) ) {
185
+ // The following is special test logic for a "Double type" bson corpus test that uses a different
186
+ // string format for the resulting double value
187
+ // The test does not have a loss in precision, just different exponential output
188
+ // We want to ensure that the stringified value when interpreted as a double is equal
189
+ // as opposed to the string being precisely the same
190
+ if ( description !== 'Double type' ) {
191
+ throw new Error ( 'Unexpected test using 1.2345678921232E+18' ) ;
192
+ }
193
+ const eJSONParsedAsJSON = JSON . parse ( cEJ ) ;
194
+ const eJSONParsed = EJSON . parse ( cEJ , { relaxed : false } ) ;
195
+ expect ( eJSONParsedAsJSON ) . to . have . nested . property ( 'd.$numberDouble' ) ;
196
+ expect ( eJSONParsed ) . to . have . nested . property ( 'd._bsontype' , 'Double' ) ;
197
+ const testInputAsFloat = Number . parseFloat ( eJSONParsedAsJSON . d . $numberDouble ) ;
198
+ const ejsonOutputAsFloat = eJSONParsed . d . valueOf ( ) ;
199
+ expect ( ejsonOutputAsFloat ) . to . equal ( testInputAsFloat ) ;
200
+ } else {
201
+ // round tripped EJSON should match the original
202
+ expect ( nativeToCEJSON ( jsonToNative ( cEJ ) ) ) . to . equal ( cEJ ) ;
203
+ }
186
204
187
205
// invalid, but still parseable, EJSON. if provided, make sure that we
188
206
// properly convert it to canonical EJSON and BSON.
@@ -202,8 +220,22 @@ describe('BSON Corpus', function () {
202
220
expect ( nativeToBson ( jsonToNative ( cEJ ) ) ) . to . deep . equal ( cB ) ;
203
221
}
204
222
205
- // the reverse direction, BSON -> native -> EJSON, should match canonical EJSON.
206
- expect ( nativeToCEJSON ( nativeFromCB ) ) . to . equal ( cEJ ) ;
223
+ if ( cEJ . includes ( '1.2345678921232E+18' ) ) {
224
+ // The round tripped value should be equal in interpreted value, not in exact character match
225
+ const eJSONFromBSONAsJSON = JSON . parse (
226
+ EJSON . stringify ( BSON . deserialize ( cB ) , { relaxed : false } )
227
+ ) ;
228
+ const eJSONParsed = EJSON . parse ( cEJ , { relaxed : false } ) ;
229
+ // TODO(NODE-4377): EJSON transforms large doubles into longs
230
+ expect ( eJSONFromBSONAsJSON ) . to . have . nested . property ( 'd.$numberLong' ) ;
231
+ expect ( eJSONParsed ) . to . have . nested . property ( 'd._bsontype' , 'Double' ) ;
232
+ const testInputAsFloat = Number . parseFloat ( eJSONFromBSONAsJSON . d . $numberLong ) ;
233
+ const ejsonOutputAsFloat = eJSONParsed . d . valueOf ( ) ;
234
+ expect ( ejsonOutputAsFloat ) . to . equal ( testInputAsFloat ) ;
235
+ } else {
236
+ // the reverse direction, BSON -> native -> EJSON, should match canonical EJSON.
237
+ expect ( nativeToCEJSON ( nativeFromCB ) ) . to . equal ( cEJ ) ;
238
+ }
207
239
208
240
if ( v . relaxed_extjson ) {
209
241
let rEJ = normalize ( v . relaxed_extjson ) ;
0 commit comments