diff --git a/lib/double.js b/lib/double.js index 534336a5..5b580eb7 100644 --- a/lib/double.js +++ b/lib/double.js @@ -49,9 +49,17 @@ class Double { return { $numberDouble: `-${this.value.toFixed(1)}` }; } - return { - $numberDouble: Number.isInteger(this.value) ? this.value.toFixed(1) : this.value.toString() - }; + let $numberDouble; + if (Number.isInteger(this.value)) { + $numberDouble = this.value.toFixed(1); + if ($numberDouble.length >= 13) { + $numberDouble = this.value.toExponential(13).toUpperCase(); + } + } else { + $numberDouble = this.value.toString(); + } + + return { $numberDouble }; } /** diff --git a/test/node/bson_corpus_tests.js b/test/node/bson_corpus_tests.js index d2c61880..6120bf5d 100644 --- a/test/node/bson_corpus_tests.js +++ b/test/node/bson_corpus_tests.js @@ -58,9 +58,7 @@ const skipBSON = { const skipExtendedJSON = { 'Timestamp with high-order bit set on both seconds and increment': - 'Current BSON implementation of timestamp/long cannot hold these values - 1 too large.', - '1.23456789012345677E+18': 'NODE-2519', - '-1.23456789012345677E+18': 'NODE-2519' + 'Current BSON implementation of timestamp/long cannot hold these values - 1 too large.' }; const corpus = require('./tools/bson_corpus_test_loader'); diff --git a/test/node/specs/bson-corpus/README.md b/test/node/specs/bson-corpus/README.md deleted file mode 100644 index 36a51c35..00000000 --- a/test/node/specs/bson-corpus/README.md +++ /dev/null @@ -1,96 +0,0 @@ -# BSON Corpus - -This BSON test data corpus consists of a JSON file for each BSON type, plus -a `top.json` file for testing the overall, enclosing document. - -Top level keys include: - -* `description`: human-readable description of what is in the file -* `bson_type`: hex string of the first byte of a BSON element (e.g. "0x01" - for type "double"); this will be the synthetic value "0x00" for `top.json`. -* `test_key`: name of a field in a `valid` test case `extjson` document - should be checked against the case's `string` field. -* `valid` (optional): an array of valid test cases (see below). -* `decodeErrors` (optional): an array of decode error cases (see below). -* `parseErrors` (optional): an array of type-specific parse error case (see - below). - -Valid test case keys include: - -* `description`: human-readable test case label. -* `subject`: an (uppercase) big-endian hex representation of a BSON byte - string. Be sure to mangle the case as appropriate in any roundtrip - tests. -* `string`: (optional) a representation of an element in the `extjson` - field that can be checked to verify correct extjson decoding. How to - check is language and bson-type specific. -* `extjson`: a document representing the decoded extended JSON document - equivalent to the subject. -* `decodeOnly` (optional): if true, indicates that the BSON can not - roundtrip; decoding the BSON in 'subject' and re-encoding the result will - not generate identical BSON; otherwise, encode(decode(subject)) should be - the same as the subject. - -Decode error cases provide an invalid BSON document or field that -should result in an error. For each case, keys include: - -* `description`: human-readable test case label. -* `subject`: an (uppercase) big-endian hex representation of an invalid - BSON string that should fail to decode correctly. - -Parse error cases are type-specific and represent some input that can not -be encoded to the `bson_type` under test. For each case, keys include: - -* `description`: human-readable test case label. -* `subject`: a text or numeric representation of an input that can't be - encoded. - -## Extended JSON extensions - -The extended JSON documentation doesn't include extensions for all BSON -types. These are supported by `mongoexport`: - - # Javascript - { "$code": "" } - - # Javascript with scope - { "$code": "": "$scope": { "x":1, "y":1 } } - - # Int32 - { "$numberInt": "" } - -However, this corpus extends JSON further to include the following: - - # Double (needed for NaN, etc.) - { "$numberDouble": "" } - - # DBpointer (deprecated): is 24 hex chars - { "$dbpointer": "", "$ns":"" } - - # Symbol (deprecated) - { "$symbol": "" } - -## Visualizing BSON - -The directory includes a Perl script `bsonview`, which will decompose and -highlight elements of a BSON document. It may be used like this: - - echo "0900000010610005000000" | perl bsonview -x - -## Open Questions - -These issues are still TBD: - -* Can "-0.0" be represented "canonically" in bson? Some languages might - not round-trip it. (Do we need a "lossy_bson" field to capture this?) - -* How should DBPointer round-trip? Should we expect it to be turned into a - DBRef or round-trip faithfully? - -* How should Symbol roundtrip? Should we expect it to be turned into a - string? - -* How should Undefined roundtrip? Should we expect it to be turned into a - null? - -* Should we flag cases where extjson is lossy compared to bson? diff --git a/test/node/specs/bson-corpus/array.json b/test/node/specs/bson-corpus/array.json old mode 100755 new mode 100644 index 1c654cf3..9ff953e5 --- a/test/node/specs/bson-corpus/array.json +++ b/test/node/specs/bson-corpus/array.json @@ -14,16 +14,22 @@ "canonical_extjson": "{\"a\" : [{\"$numberInt\": \"10\"}]}" }, { - "description": "Single Element Array with index set incorrectly", + "description": "Single Element Array with index set incorrectly to empty string", "degenerate_bson": "130000000461000B00000010000A0000000000", "canonical_bson": "140000000461000C0000001030000A0000000000", "canonical_extjson": "{\"a\" : [{\"$numberInt\": \"10\"}]}" }, { - "description": "Single Element Array with index set incorrectly", + "description": "Single Element Array with index set incorrectly to ab", "degenerate_bson": "150000000461000D000000106162000A0000000000", "canonical_bson": "140000000461000C0000001030000A0000000000", "canonical_extjson": "{\"a\" : [{\"$numberInt\": \"10\"}]}" + }, + { + "description": "Multi Element Array with duplicate indexes", + "degenerate_bson": "1b000000046100130000001030000a000000103000140000000000", + "canonical_bson": "1b000000046100130000001030000a000000103100140000000000", + "canonical_extjson": "{\"a\" : [{\"$numberInt\": \"10\"}, {\"$numberInt\": \"20\"}]}" } ], "decodeErrors": [ diff --git a/test/node/specs/bson-corpus/binary.json b/test/node/specs/bson-corpus/binary.json old mode 100755 new mode 100644 diff --git a/test/node/specs/bson-corpus/boolean.json b/test/node/specs/bson-corpus/boolean.json old mode 100755 new mode 100644 diff --git a/test/node/specs/bson-corpus/code.json b/test/node/specs/bson-corpus/code.json old mode 100755 new mode 100644 diff --git a/test/node/specs/bson-corpus/code_w_scope.json b/test/node/specs/bson-corpus/code_w_scope.json old mode 100755 new mode 100644 diff --git a/test/node/specs/bson-corpus/datetime.json b/test/node/specs/bson-corpus/datetime.json old mode 100755 new mode 100644 index 60506ce1..f857afdc --- a/test/node/specs/bson-corpus/datetime.json +++ b/test/node/specs/bson-corpus/datetime.json @@ -25,6 +25,12 @@ "description" : "Y10K", "canonical_bson" : "1000000009610000DC1FD277E6000000", "canonical_extjson" : "{\"a\":{\"$date\":{\"$numberLong\":\"253402300800000\"}}}" + }, + { + "description": "leading zero ms", + "canonical_bson": "10000000096100D1D6D6CC3B01000000", + "relaxed_extjson": "{\"a\" : {\"$date\" : \"2012-12-24T12:15:30.001Z\"}}", + "canonical_extjson": "{\"a\" : {\"$date\" : {\"$numberLong\" : \"1356351330001\"}}}" } ], "decodeErrors": [ diff --git a/test/node/specs/bson-corpus/dbpointer.json b/test/node/specs/bson-corpus/dbpointer.json old mode 100755 new mode 100644 diff --git a/test/node/specs/bson-corpus/dbref.json b/test/node/specs/bson-corpus/dbref.json old mode 100755 new mode 100644 diff --git a/test/node/specs/bson-corpus/decimal128-1.json b/test/node/specs/bson-corpus/decimal128-1.json old mode 100755 new mode 100644 diff --git a/test/node/specs/bson-corpus/decimal128-2.json b/test/node/specs/bson-corpus/decimal128-2.json old mode 100755 new mode 100644 diff --git a/test/node/specs/bson-corpus/decimal128-3.json b/test/node/specs/bson-corpus/decimal128-3.json old mode 100755 new mode 100644 diff --git a/test/node/specs/bson-corpus/decimal128-4.json b/test/node/specs/bson-corpus/decimal128-4.json old mode 100755 new mode 100644 index 05f7c460..09570193 --- a/test/node/specs/bson-corpus/decimal128-4.json +++ b/test/node/specs/bson-corpus/decimal128-4.json @@ -1,172 +1,165 @@ { - "description": "Decimal128", - "bson_type": "0x13", - "test_key": "d", - "valid": [ - { - "description": "[basx023] conform to rules and exponent will be in permitted range).", - "canonical_bson": "1800000013640001000000000000000000000000003EB000", - "canonical_extjson": "{\"d\" : {\"$numberDecimal\" : \"-0.1\"}}" - }, + "description": "Decimal128", + "bson_type": "0x13", + "test_key": "d", + "valid": [ + { + "description": "[basx023] conform to rules and exponent will be in permitted range).", + "canonical_bson": "1800000013640001000000000000000000000000003EB000", + "canonical_extjson": "{\"d\" : {\"$numberDecimal\" : \"-0.1\"}}" + }, - { - "description": "[basx045] strings without E cannot generate E in result", - "canonical_bson": "1800000013640003000000000000000000000000003A3000", - "degenerate_extjson": "{\"d\" : {\"$numberDecimal\" : \"+0.003\"}}", - "canonical_extjson": "{\"d\" : {\"$numberDecimal\" : \"0.003\"}}" - }, - { - "description": "[basx610] Zeros", - "canonical_bson": "1800000013640000000000000000000000000000003E3000", - "degenerate_extjson": "{\"d\" : {\"$numberDecimal\" : \".0\"}}", - "canonical_extjson": "{\"d\" : {\"$numberDecimal\" : \"0.0\"}}" - }, - { - "description": "[basx612] Zeros", - "canonical_bson": "1800000013640000000000000000000000000000003EB000", - "degenerate_extjson": "{\"d\" : {\"$numberDecimal\" : \"-.0\"}}", - "canonical_extjson": "{\"d\" : {\"$numberDecimal\" : \"-0.0\"}}" - }, - { - "description": "[basx043] strings without E cannot generate E in result", - "canonical_bson": "18000000136400FC040000000000000000000000003C3000", - "degenerate_extjson": "{\"d\" : {\"$numberDecimal\" : \"+12.76\"}}", - "canonical_extjson": "{\"d\" : {\"$numberDecimal\" : \"12.76\"}}" - }, - { - "description": "[basx055] strings without E cannot generate E in result", - "canonical_bson": "180000001364000500000000000000000000000000303000", - "degenerate_extjson": "{\"d\" : {\"$numberDecimal\" : \"0.00000005\"}}", - "canonical_extjson": "{\"d\" : {\"$numberDecimal\" : \"5E-8\"}}" - }, - { - "description": "[basx054] strings without E cannot generate E in result", - "canonical_bson": "180000001364000500000000000000000000000000323000", - "degenerate_extjson": "{\"d\" : {\"$numberDecimal\" : \"0.0000005\"}}", - "canonical_extjson": "{\"d\" : {\"$numberDecimal\" : \"5E-7\"}}" - }, - { - "description": "[basx052] strings without E cannot generate E in result", - "canonical_bson": "180000001364000500000000000000000000000000343000", - "canonical_extjson": "{\"d\" : {\"$numberDecimal\" : \"0.000005\"}}" - }, - { - "description": "[basx051] strings without E cannot generate E in result", - "canonical_bson": "180000001364000500000000000000000000000000363000", - "degenerate_extjson": "{\"d\" : {\"$numberDecimal\" : \"00.00005\"}}", - "canonical_extjson": "{\"d\" : {\"$numberDecimal\" : \"0.00005\"}}" - }, - { - "description": "[basx050] strings without E cannot generate E in result", - "canonical_bson": "180000001364000500000000000000000000000000383000", - "canonical_extjson": "{\"d\" : {\"$numberDecimal\" : \"0.0005\"}}" - }, - { - "description": "[basx047] strings without E cannot generate E in result", - "canonical_bson": "1800000013640005000000000000000000000000003E3000", - "degenerate_extjson": "{\"d\" : {\"$numberDecimal\" : \".5\"}}", - "canonical_extjson": "{\"d\" : {\"$numberDecimal\" : \"0.5\"}}" - }, - { - "description": "[dqbsr431] check rounding modes heeded (Rounded)", - "canonical_bson": "1800000013640099761CC7B548F377DC80A131C836FE2F00", - "degenerate_extjson": - "{\"d\" : {\"$numberDecimal\" : \"1.1111111111111111111111111111123450\"}}", - "canonical_extjson": - "{\"d\" : {\"$numberDecimal\" : \"1.111111111111111111111111111112345\"}}" - }, - { - "description": "OK2", - "canonical_bson": "18000000136400000000000A5BC138938D44C64D31FC2F00", - "degenerate_extjson": - "{\"d\" : {\"$numberDecimal\" : \".100000000000000000000000000000000000000000000000000000000000\"}}", - "canonical_extjson": - "{\"d\" : {\"$numberDecimal\" : \"0.1000000000000000000000000000000000\"}}" - } - ], - "parseErrors": [ - { - "description": "[basx564] Near-specials (Conversion_syntax)", - "string": "Infi" - }, - { - "description": "[basx565] Near-specials (Conversion_syntax)", - "string": "Infin" - }, - { - "description": "[basx566] Near-specials (Conversion_syntax)", - "string": "Infini" - }, - { - "description": "[basx567] Near-specials (Conversion_syntax)", - "string": "Infinit" - }, - { - "description": "[basx568] Near-specials (Conversion_syntax)", - "string": "-Infinit" - }, - { - "description": - "[basx590] some baddies with dots and Es and dots and specials (Conversion_syntax)", - "string": ".Infinity" - }, - { - "description": "[basx562] Near-specials (Conversion_syntax)", - "string": "NaNq" - }, - { - "description": "[basx563] Near-specials (Conversion_syntax)", - "string": "NaNs" - }, - { - "description": - "[dqbas939] overflow results at different rounding modes (Overflow & Inexact & Rounded)", - "string": "-7e10000" - }, - { - "description": "[dqbsr534] negatives (Rounded & Inexact)", - "string": "-1.11111111111111111111111111111234650" - }, - { - "description": "[dqbsr535] negatives (Rounded & Inexact)", - "string": "-1.11111111111111111111111111111234551" - }, - { - "description": "[dqbsr533] negatives (Rounded & Inexact)", - "string": "-1.11111111111111111111111111111234550" - }, - { - "description": "[dqbsr532] negatives (Rounded & Inexact)", - "string": "-1.11111111111111111111111111111234549" - }, - { - "description": "[dqbsr432] check rounding modes heeded (Rounded & Inexact)", - "string": "1.11111111111111111111111111111234549" - }, - { - "description": "[dqbsr433] check rounding modes heeded (Rounded & Inexact)", - "string": "1.11111111111111111111111111111234550" - }, - { - "description": "[dqbsr435] check rounding modes heeded (Rounded & Inexact)", - "string": "1.11111111111111111111111111111234551" - }, - { - "description": "[dqbsr434] check rounding modes heeded (Rounded & Inexact)", - "string": "1.11111111111111111111111111111234650" - }, - { - "description": - "[dqbas938] overflow results at different rounding modes (Overflow & Inexact & Rounded)", - "string": "7e10000" - }, - { - "description": "Inexact rounding#1", - "string": "100000000000000000000000000000000000000000000000000000000001" - }, - { - "description": "Inexact rounding#2", - "string": "1E-6177" - } - ] + { + "description": "[basx045] strings without E cannot generate E in result", + "canonical_bson": "1800000013640003000000000000000000000000003A3000", + "degenerate_extjson": "{\"d\" : {\"$numberDecimal\" : \"+0.003\"}}", + "canonical_extjson": "{\"d\" : {\"$numberDecimal\" : \"0.003\"}}" + }, + { + "description": "[basx610] Zeros", + "canonical_bson": "1800000013640000000000000000000000000000003E3000", + "degenerate_extjson": "{\"d\" : {\"$numberDecimal\" : \".0\"}}", + "canonical_extjson": "{\"d\" : {\"$numberDecimal\" : \"0.0\"}}" + }, + { + "description": "[basx612] Zeros", + "canonical_bson": "1800000013640000000000000000000000000000003EB000", + "degenerate_extjson": "{\"d\" : {\"$numberDecimal\" : \"-.0\"}}", + "canonical_extjson": "{\"d\" : {\"$numberDecimal\" : \"-0.0\"}}" + }, + { + "description": "[basx043] strings without E cannot generate E in result", + "canonical_bson": "18000000136400FC040000000000000000000000003C3000", + "degenerate_extjson": "{\"d\" : {\"$numberDecimal\" : \"+12.76\"}}", + "canonical_extjson": "{\"d\" : {\"$numberDecimal\" : \"12.76\"}}" + }, + { + "description": "[basx055] strings without E cannot generate E in result", + "canonical_bson": "180000001364000500000000000000000000000000303000", + "degenerate_extjson": "{\"d\" : {\"$numberDecimal\" : \"0.00000005\"}}", + "canonical_extjson": "{\"d\" : {\"$numberDecimal\" : \"5E-8\"}}" + }, + { + "description": "[basx054] strings without E cannot generate E in result", + "canonical_bson": "180000001364000500000000000000000000000000323000", + "degenerate_extjson": "{\"d\" : {\"$numberDecimal\" : \"0.0000005\"}}", + "canonical_extjson": "{\"d\" : {\"$numberDecimal\" : \"5E-7\"}}" + }, + { + "description": "[basx052] strings without E cannot generate E in result", + "canonical_bson": "180000001364000500000000000000000000000000343000", + "canonical_extjson": "{\"d\" : {\"$numberDecimal\" : \"0.000005\"}}" + }, + { + "description": "[basx051] strings without E cannot generate E in result", + "canonical_bson": "180000001364000500000000000000000000000000363000", + "degenerate_extjson": "{\"d\" : {\"$numberDecimal\" : \"00.00005\"}}", + "canonical_extjson": "{\"d\" : {\"$numberDecimal\" : \"0.00005\"}}" + }, + { + "description": "[basx050] strings without E cannot generate E in result", + "canonical_bson": "180000001364000500000000000000000000000000383000", + "canonical_extjson": "{\"d\" : {\"$numberDecimal\" : \"0.0005\"}}" + }, + { + "description": "[basx047] strings without E cannot generate E in result", + "canonical_bson": "1800000013640005000000000000000000000000003E3000", + "degenerate_extjson": "{\"d\" : {\"$numberDecimal\" : \".5\"}}", + "canonical_extjson": "{\"d\" : {\"$numberDecimal\" : \"0.5\"}}" + }, + { + "description": "[dqbsr431] check rounding modes heeded (Rounded)", + "canonical_bson": "1800000013640099761CC7B548F377DC80A131C836FE2F00", + "degenerate_extjson": "{\"d\" : {\"$numberDecimal\" : \"1.1111111111111111111111111111123450\"}}", + "canonical_extjson": "{\"d\" : {\"$numberDecimal\" : \"1.111111111111111111111111111112345\"}}" + }, + { + "description": "OK2", + "canonical_bson": "18000000136400000000000A5BC138938D44C64D31FC2F00", + "degenerate_extjson": "{\"d\" : {\"$numberDecimal\" : \".100000000000000000000000000000000000000000000000000000000000\"}}", + "canonical_extjson": "{\"d\" : {\"$numberDecimal\" : \"0.1000000000000000000000000000000000\"}}" + } + ], + "parseErrors": [ + { + "description": "[basx564] Near-specials (Conversion_syntax)", + "string": "Infi" + }, + { + "description": "[basx565] Near-specials (Conversion_syntax)", + "string": "Infin" + }, + { + "description": "[basx566] Near-specials (Conversion_syntax)", + "string": "Infini" + }, + { + "description": "[basx567] Near-specials (Conversion_syntax)", + "string": "Infinit" + }, + { + "description": "[basx568] Near-specials (Conversion_syntax)", + "string": "-Infinit" + }, + { + "description": "[basx590] some baddies with dots and Es and dots and specials (Conversion_syntax)", + "string": ".Infinity" + }, + { + "description": "[basx562] Near-specials (Conversion_syntax)", + "string": "NaNq" + }, + { + "description": "[basx563] Near-specials (Conversion_syntax)", + "string": "NaNs" + }, + { + "description": "[dqbas939] overflow results at different rounding modes (Overflow & Inexact & Rounded)", + "string": "-7e10000" + }, + { + "description": "[dqbsr534] negatives (Rounded & Inexact)", + "string": "-1.11111111111111111111111111111234650" + }, + { + "description": "[dqbsr535] negatives (Rounded & Inexact)", + "string": "-1.11111111111111111111111111111234551" + }, + { + "description": "[dqbsr533] negatives (Rounded & Inexact)", + "string": "-1.11111111111111111111111111111234550" + }, + { + "description": "[dqbsr532] negatives (Rounded & Inexact)", + "string": "-1.11111111111111111111111111111234549" + }, + { + "description": "[dqbsr432] check rounding modes heeded (Rounded & Inexact)", + "string": "1.11111111111111111111111111111234549" + }, + { + "description": "[dqbsr433] check rounding modes heeded (Rounded & Inexact)", + "string": "1.11111111111111111111111111111234550" + }, + { + "description": "[dqbsr435] check rounding modes heeded (Rounded & Inexact)", + "string": "1.11111111111111111111111111111234551" + }, + { + "description": "[dqbsr434] check rounding modes heeded (Rounded & Inexact)", + "string": "1.11111111111111111111111111111234650" + }, + { + "description": "[dqbas938] overflow results at different rounding modes (Overflow & Inexact & Rounded)", + "string": "7e10000" + }, + { + "description": "Inexact rounding#1", + "string": "100000000000000000000000000000000000000000000000000000000001" + }, + { + "description": "Inexact rounding#2", + "string": "1E-6177" + } + ] } diff --git a/test/node/specs/bson-corpus/decimal128-5.json b/test/node/specs/bson-corpus/decimal128-5.json old mode 100755 new mode 100644 diff --git a/test/node/specs/bson-corpus/decimal128-6.json b/test/node/specs/bson-corpus/decimal128-6.json old mode 100755 new mode 100644 diff --git a/test/node/specs/bson-corpus/decimal128-7.json b/test/node/specs/bson-corpus/decimal128-7.json old mode 100755 new mode 100644 diff --git a/test/node/specs/bson-corpus/document.json b/test/node/specs/bson-corpus/document.json old mode 100755 new mode 100644 diff --git a/test/node/specs/bson-corpus/double.json b/test/node/specs/bson-corpus/double.json old mode 100755 new mode 100644 index 00f75196..d5b8fb3d --- a/test/node/specs/bson-corpus/double.json +++ b/test/node/specs/bson-corpus/double.json @@ -28,16 +28,16 @@ "relaxed_extjson": "{\"d\" : -1.0001220703125}" }, { - "description": "1.23456789012345677E+18", - "canonical_bson": "1000000001640081E97DF41022B14300", - "canonical_extjson": "{\"d\" : {\"$numberDouble\": \"1.23456789012345677E+18\"}}", - "relaxed_extjson": "{\"d\" : 1.23456789012345677E+18}" + "description": "1.2345678921232E+18", + "canonical_bson": "100000000164002a1bf5f41022b14300", + "canonical_extjson": "{\"d\" : {\"$numberDouble\": \"1.2345678921232E+18\"}}", + "relaxed_extjson": "{\"d\" : 1.2345678921232E+18}" }, { - "description": "-1.23456789012345677E+18", - "canonical_bson": "1000000001640081E97DF41022B1C300", - "canonical_extjson": "{\"d\" : {\"$numberDouble\": \"-1.23456789012345677E+18\"}}", - "relaxed_extjson": "{\"d\" : -1.23456789012345677E+18}" + "description": "-1.2345678921232E+18", + "canonical_bson": "100000000164002a1bf5f41022b1c300", + "canonical_extjson": "{\"d\" : {\"$numberDouble\": \"-1.2345678921232E+18\"}}", + "relaxed_extjson": "{\"d\" : -1.2345678921232E+18}" }, { "description": "0.0", diff --git a/test/node/specs/bson-corpus/int32.json b/test/node/specs/bson-corpus/int32.json old mode 100755 new mode 100644 diff --git a/test/node/specs/bson-corpus/int64.json b/test/node/specs/bson-corpus/int64.json old mode 100755 new mode 100644 diff --git a/test/node/specs/bson-corpus/maxkey.json b/test/node/specs/bson-corpus/maxkey.json old mode 100755 new mode 100644 diff --git a/test/node/specs/bson-corpus/minkey.json b/test/node/specs/bson-corpus/minkey.json old mode 100755 new mode 100644 diff --git a/test/node/specs/bson-corpus/multi-type-deprecated.json b/test/node/specs/bson-corpus/multi-type-deprecated.json old mode 100755 new mode 100644 index 64c0cb2b..665f388c --- a/test/node/specs/bson-corpus/multi-type-deprecated.json +++ b/test/node/specs/bson-corpus/multi-type-deprecated.json @@ -1,5 +1,5 @@ { - "description": "Multiple types within the same document (deprecated)", + "description": "Multiple types within the same document", "bson_type": "0x00", "deprecated": true, "valid": [ diff --git a/test/node/specs/bson-corpus/multi-type.json b/test/node/specs/bson-corpus/multi-type.json old mode 100755 new mode 100644 diff --git a/test/node/specs/bson-corpus/null.json b/test/node/specs/bson-corpus/null.json old mode 100755 new mode 100644 diff --git a/test/node/specs/bson-corpus/oid.json b/test/node/specs/bson-corpus/oid.json old mode 100755 new mode 100644 diff --git a/test/node/specs/bson-corpus/regex.json b/test/node/specs/bson-corpus/regex.json old mode 100755 new mode 100644 index 02a0b723..c62b019c --- a/test/node/specs/bson-corpus/regex.json +++ b/test/node/specs/bson-corpus/regex.json @@ -6,62 +6,50 @@ { "description": "empty regex with no options", "canonical_bson": "0A0000000B6100000000", - "canonical_extjson": - "{\"a\" : {\"$regularExpression\" : { \"pattern\": \"\", \"options\" : \"\"}}}" + "canonical_extjson": "{\"a\" : {\"$regularExpression\" : { \"pattern\": \"\", \"options\" : \"\"}}}" }, { "description": "regex without options", "canonical_bson": "0D0000000B6100616263000000", - "canonical_extjson": - "{\"a\" : {\"$regularExpression\" : { \"pattern\": \"abc\", \"options\" : \"\"}}}" + "canonical_extjson": "{\"a\" : {\"$regularExpression\" : { \"pattern\": \"abc\", \"options\" : \"\"}}}" }, { "description": "regex with options", "canonical_bson": "0F0000000B610061626300696D0000", - "canonical_extjson": - "{\"a\" : {\"$regularExpression\" : { \"pattern\": \"abc\", \"options\" : \"im\"}}}" + "canonical_extjson": "{\"a\" : {\"$regularExpression\" : { \"pattern\": \"abc\", \"options\" : \"im\"}}}" }, { "description": "regex with options (keys reversed)", "canonical_bson": "0F0000000B610061626300696D0000", - "canonical_extjson": - "{\"a\" : {\"$regularExpression\" : { \"pattern\": \"abc\", \"options\" : \"im\"}}}", - "degenerate_extjson": - "{\"a\" : {\"$regularExpression\" : {\"options\" : \"im\", \"pattern\": \"abc\"}}}" + "canonical_extjson": "{\"a\" : {\"$regularExpression\" : { \"pattern\": \"abc\", \"options\" : \"im\"}}}", + "degenerate_extjson": "{\"a\" : {\"$regularExpression\" : {\"options\" : \"im\", \"pattern\": \"abc\"}}}" }, { "description": "regex with slash", "canonical_bson": "110000000B610061622F636400696D0000", - "canonical_extjson": - "{\"a\" : {\"$regularExpression\" : { \"pattern\": \"ab/cd\", \"options\" : \"im\"}}}" + "canonical_extjson": "{\"a\" : {\"$regularExpression\" : { \"pattern\": \"ab/cd\", \"options\" : \"im\"}}}" }, { "description": "flags not alphabetized", "degenerate_bson": "100000000B6100616263006D69780000", "canonical_bson": "100000000B610061626300696D780000", - "canonical_extjson": - "{\"a\" : {\"$regularExpression\" : { \"pattern\": \"abc\", \"options\" : \"imx\"}}}", - "degenerate_extjson": - "{\"a\" : {\"$regularExpression\" : { \"pattern\": \"abc\", \"options\" : \"mix\"}}}" + "canonical_extjson": "{\"a\" : {\"$regularExpression\" : { \"pattern\": \"abc\", \"options\" : \"imx\"}}}", + "degenerate_extjson": "{\"a\" : {\"$regularExpression\" : { \"pattern\": \"abc\", \"options\" : \"mix\"}}}" }, { - "description": "Required escapes", - "canonical_bson": "100000000B610061625C226162000000", - "canonical_extjson": - "{\"a\" : {\"$regularExpression\" : { \"pattern\": \"ab\\\\\\\"ab\", \"options\" : \"\"}}}" + "description" : "Required escapes", + "canonical_bson" : "100000000B610061625C226162000000", + "canonical_extjson": "{\"a\" : {\"$regularExpression\" : { \"pattern\": \"ab\\\\\\\"ab\", \"options\" : \"\"}}}" }, { - "description": "Regular expression as value of $regex query operator", - "canonical_bson": "180000000B247265676578007061747465726E0069780000", - "canonical_extjson": - "{\"$regex\" : {\"$regularExpression\" : { \"pattern\": \"pattern\", \"options\" : \"ix\"}}}" + "description" : "Regular expression as value of $regex query operator", + "canonical_bson" : "180000000B247265676578007061747465726E0069780000", + "canonical_extjson": "{\"$regex\" : {\"$regularExpression\" : { \"pattern\": \"pattern\", \"options\" : \"ix\"}}}" }, { - "description": "Regular expression as value of $regex query operator with $options", - "canonical_bson": - "270000000B247265676578007061747465726E000002246F7074696F6E73000300000069780000", - "canonical_extjson": - "{\"$regex\" : {\"$regularExpression\" : { \"pattern\": \"pattern\", \"options\" : \"\"}}, \"$options\" : \"ix\"}" + "description" : "Regular expression as value of $regex query operator with $options", + "canonical_bson" : "270000000B247265676578007061747465726E000002246F7074696F6E73000300000069780000", + "canonical_extjson": "{\"$regex\" : {\"$regularExpression\" : { \"pattern\": \"pattern\", \"options\" : \"\"}}, \"$options\" : \"ix\"}" } ], "decodeErrors": [ diff --git a/test/node/specs/bson-corpus/string.json b/test/node/specs/bson-corpus/string.json old mode 100755 new mode 100644 diff --git a/test/node/specs/bson-corpus/symbol.json b/test/node/specs/bson-corpus/symbol.json old mode 100755 new mode 100644 diff --git a/test/node/specs/bson-corpus/timestamp.json b/test/node/specs/bson-corpus/timestamp.json old mode 100755 new mode 100644 diff --git a/test/node/specs/bson-corpus/top.json b/test/node/specs/bson-corpus/top.json old mode 100755 new mode 100644 index 8422bce4..5352a3fa --- a/test/node/specs/bson-corpus/top.json +++ b/test/node/specs/bson-corpus/top.json @@ -10,13 +10,11 @@ ], "decodeErrors": [ { - "description": - "An object size that's too small to even include the object size, but is a well-formed, empty object", + "description": "An object size that's too small to even include the object size, but is a well-formed, empty object", "bson": "0100000000" }, { - "description": - "An object size that's only enough for the object size, but is a well-formed, empty object", + "description": "An object size that's only enough for the object size, but is a well-formed, empty object", "bson": "0400000000" }, { @@ -24,18 +22,15 @@ "bson": "05000000" }, { - "description": - "One object, sized correctly, with a spot for an EOO, but the EOO is 0x01", + "description": "One object, sized correctly, with a spot for an EOO, but the EOO is 0x01", "bson": "0500000001" }, { - "description": - "One object, sized correctly, with a spot for an EOO, but the EOO is 0xff", + "description": "One object, sized correctly, with a spot for an EOO, but the EOO is 0xff", "bson": "05000000FF" }, { - "description": - "One object, sized correctly, with a spot for an EOO, but the EOO is 0x70", + "description": "One object, sized correctly, with a spot for an EOO, but the EOO is 0x70", "bson": "0500000070" }, { @@ -73,13 +68,12 @@ ], "parseErrors": [ { - "description": "Bad $regularExpression (extra field)", - "string": - "{\"a\" : \"$regularExpression\": {\"pattern\": \"abc\", \"options\": \"\", \"unrelated\": true}}}" + "description" : "Bad $regularExpression (extra field)", + "string" : "{\"a\" : {\"$regularExpression\": {\"pattern\": \"abc\", \"options\": \"\", \"unrelated\": true}}}" }, { - "description": "Bad $regularExpression (missing options field)", - "string": "{\"a\" : \"$regularExpression\": {\"pattern\": \"abc\"}}}" + "description" : "Bad $regularExpression (missing options field)", + "string" : "{\"a\" : {\"$regularExpression\": {\"pattern\": \"abc\"}}}" }, { "description": "Bad $regularExpression (pattern is number, not string)", @@ -90,8 +84,8 @@ "string": "{\"x\" : {\"$regularExpression\" : { \"pattern\": \"a\", \"$options\" : 0}}}" }, { - "description": "Bad $regularExpression (missing pattern field)", - "string": "{\"a\" : \"$regularExpression\": {\"options\":\"ix\"}}}" + "description" : "Bad $regularExpression (missing pattern field)", + "string" : "{\"a\" : {\"$regularExpression\": {\"options\":\"ix\"}}}" }, { "description": "Bad $oid (number, not string)", @@ -151,13 +145,16 @@ }, { "description": "Bad $binary (extra field)", - "string": - "{\"x\" : {\"$binary\" : {\"base64\" : \"//8=\", \"subType\" : 0, \"unrelated\": true}}}" + "string": "{\"x\" : {\"$binary\" : {\"base64\" : \"//8=\", \"subType\" : 0, \"unrelated\": true}}}" }, { "description": "Bad $code (type is number, not string)", "string": "{\"a\" : {\"$code\" : 42}}" }, + { + "description": "Bad $code (type is number, not string) when $scope is also present", + "string": "{\"a\" : {\"$code\" : 42, \"$scope\" : {}}}" + }, { "description": "Bad $code (extra field)", "string": "{\"a\" : {\"$code\" : \"\", \"unrelated\": true}}" @@ -180,13 +177,11 @@ }, { "description": "Bad $timestamp (extra field at same level as $timestamp)", - "string": - "{\"a\" : {\"$timestamp\" : {\"t\" : \"123456789\", \"i\" : \"42\"}, \"unrelated\": true } }" + "string": "{\"a\" : {\"$timestamp\" : {\"t\" : \"123456789\", \"i\" : \"42\"}, \"unrelated\": true } }" }, { "description": "Bad $timestamp (extra field at same level as t and i)", - "string": - "{\"a\" : {\"$timestamp\" : {\"t\" : \"123456789\", \"i\" : \"42\", \"unrelated\": true} } }" + "string": "{\"a\" : {\"$timestamp\" : {\"t\" : \"123456789\", \"i\" : \"42\", \"unrelated\": true} } }" }, { "description": "Bad $timestamp (missing t)", @@ -202,8 +197,7 @@ }, { "description": "Bad $date (extra field)", - "string": - "{\"a\" : {\"$date\" : {\"$numberLong\" : \"1356351330501\"}, \"unrelated\": true}}" + "string": "{\"a\" : {\"$date\" : {\"$numberLong\" : \"1356351330501\"}, \"unrelated\": true}}" }, { "description": "Bad DBRef (ref is number, not string)", @@ -239,8 +233,8 @@ }, { "description": "Bad DBpointer (extra field)", - "string": - "{\"a\": {\"$dbPointer\": {\"a\": {\"$numberInt\": \"1\"}, \"$id\": {\"$oid\": \"56e1fc72e0c917e9c4714161\"}, \"c\": {\"$numberInt\": \"2\"}, \"$ref\": \"b\"}}}" + "string": "{\"a\": {\"$dbPointer\": {\"a\": {\"$numberInt\": \"1\"}, \"$id\": {\"$oid\": \"56e1fc72e0c917e9c4714161\"}, \"c\": {\"$numberInt\": \"2\"}, \"$ref\": \"b\"}}}" } + ] } diff --git a/test/node/specs/bson-corpus/undefined.json b/test/node/specs/bson-corpus/undefined.json old mode 100755 new mode 100644 diff --git a/test/scripts/update-spec-tests.sh b/test/scripts/update-spec-tests.sh new file mode 100755 index 00000000..67c85fb1 --- /dev/null +++ b/test/scripts/update-spec-tests.sh @@ -0,0 +1,23 @@ +#!/usr/bin/env bash + +# This script is used to fetch the latest JSON tests for the BSON spec. +# It puts the tests in the direcory $spec_root It should be run from the root of the repository. + +set -o errexit +set -o nounset + +if [ ! -d ".git" ]; then + echo "$0: This script must be run from the root of the repository" >&2 + exit 1 +fi + +spec_root="test/node/specs" + +tmpdir=$(mktemp -d -t spec_testsXXXX) +curl -sL https://github.com/mongodb/specifications/archive/master.zip -o "$tmpdir/specs.zip" +unzip -d "$tmpdir" "$tmpdir/specs.zip" > /dev/null + +mkdir -p "$spec_root/bson-corpus" +rsync -ah "$tmpdir/specifications-master/source/bson-corpus/tests/" "$spec_root/bson-corpus" --delete + +rm -rf "$tmpdir"