-
Notifications
You must be signed in to change notification settings - Fork 254
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Browse files
Browse the repository at this point in the history
- Loading branch information
Showing
8 changed files
with
167 additions
and
260 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,82 @@ | ||
import * as BSON from '../register-bson'; | ||
import { sorted, byStrings } from './tools/utils'; | ||
|
||
const EXPECTED_EXPORTS = [ | ||
// This is our added web indicator not a real export but a small exception for this test. | ||
'__isWeb__', | ||
|
||
'BSON_BINARY_SUBTYPE_BYTE_ARRAY', | ||
'BSON_BINARY_SUBTYPE_DEFAULT', | ||
'BSON_BINARY_SUBTYPE_FUNCTION', | ||
'BSON_BINARY_SUBTYPE_MD5', | ||
'BSON_BINARY_SUBTYPE_USER_DEFINED', | ||
'BSON_BINARY_SUBTYPE_UUID', | ||
'BSON_BINARY_SUBTYPE_UUID_NEW', | ||
'BSON_BINARY_SUBTYPE_ENCRYPTED', | ||
'BSON_BINARY_SUBTYPE_COLUMN', | ||
'BSON_DATA_ARRAY', | ||
'BSON_DATA_BINARY', | ||
'BSON_DATA_BOOLEAN', | ||
'BSON_DATA_CODE', | ||
'BSON_DATA_CODE_W_SCOPE', | ||
'BSON_DATA_DATE', | ||
'BSON_DATA_DBPOINTER', | ||
'BSON_DATA_DECIMAL128', | ||
'BSON_DATA_INT', | ||
'BSON_DATA_LONG', | ||
'BSON_DATA_MAX_KEY', | ||
'BSON_DATA_MIN_KEY', | ||
'BSON_DATA_NULL', | ||
'BSON_DATA_NUMBER', | ||
'BSON_DATA_OBJECT', | ||
'BSON_DATA_OID', | ||
'BSON_DATA_REGEXP', | ||
'BSON_DATA_STRING', | ||
'BSON_DATA_SYMBOL', | ||
'BSON_DATA_TIMESTAMP', | ||
'BSON_DATA_UNDEFINED', | ||
'BSON_INT32_MAX', | ||
'BSON_INT32_MIN', | ||
'BSON_INT64_MAX', | ||
'BSON_INT64_MIN', | ||
'EJSON', | ||
'Code', | ||
'BSONSymbol', | ||
'DBRef', | ||
'Binary', | ||
'ObjectId', | ||
'UUID', | ||
'Long', | ||
'LongWithoutOverridesClass', | ||
'Timestamp', | ||
'Double', | ||
'Int32', | ||
'MinKey', | ||
'MaxKey', | ||
'BSONRegExp', | ||
'Decimal128', | ||
'ObjectID', | ||
'BSONError', | ||
'BSONTypeError', | ||
'setInternalBufferSize', | ||
'serialize', | ||
'serializeWithBufferAndIndex', | ||
'deserialize', | ||
'calculateObjectSize', | ||
'deserializeStream', | ||
'default' | ||
]; | ||
|
||
const EXPECTED_EJSON_EXPORTS = ['parse', 'stringify', 'serialize', 'deserialize']; | ||
|
||
describe('bson entrypoint', () => { | ||
it('should export all and only the expected keys in expected_exports', () => { | ||
expect(sorted(Object.keys(BSON), byStrings)).to.deep.equal(sorted(EXPECTED_EXPORTS, byStrings)); | ||
}); | ||
|
||
it('should export all and only the expected keys in expected_ejson_exports', () => { | ||
expect(sorted(Object.keys(BSON.EJSON), byStrings)).to.deep.equal( | ||
sorted(EXPECTED_EJSON_EXPORTS, byStrings) | ||
); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,66 @@ | ||
import { expect } from 'chai'; | ||
import * as BSON from '../register-bson'; | ||
import { bufferFromHexArray } from './tools/utils'; | ||
|
||
describe('ES Map support in serialize()', () => { | ||
it('serialize a empty Map to BSON document - { }', () => { | ||
const map = new Map(); | ||
const emptyBSON = bufferFromHexArray(['']); | ||
const result = BSON.serialize(map); | ||
expect(result).to.have.property('byteLength', 5); | ||
expect(result, 'byteLength must be 5 followed by null terminator').to.deep.equal(emptyBSON); | ||
}); | ||
|
||
it('serialize a Map with one key to BSON document - { a: 2 }', () => { | ||
const map = new Map([['a', new BSON.Int32(2)]]); | ||
const expected = bufferFromHexArray([ | ||
'10', // int32 type | ||
'6100', // 'a' & null | ||
'02000000' // LE 32bit 2 | ||
]); | ||
const result = BSON.serialize(map); | ||
expect(result).to.have.property('byteLength', 12); | ||
expect(result).to.deep.equal(expected); | ||
}); | ||
|
||
it('serialize a nested Map to a BSON document - { a: { b: 2 } }', () => { | ||
// { a: { b: 2 } } | ||
const map = new Map([['a', new Map([['b', new BSON.Int32(2)]])]]); | ||
const expected = bufferFromHexArray([ | ||
'03', // doc type | ||
'6100', // 'a' & null | ||
// nested document | ||
bufferFromHexArray([ | ||
'10', // int32 type | ||
'6200', // 'b' & null | ||
'02000000' // LE 32bit 2 | ||
]).toString('hex') | ||
]); | ||
const result = BSON.serialize(map); | ||
expect(result).to.have.property('byteLength', 20); | ||
expect(result).to.deep.equal(expected); | ||
}); | ||
|
||
it('keep chronological Map key order despite keys being numeric', () => { | ||
const map = new Map([ | ||
['2', new BSON.Int32(2)], | ||
['1', new BSON.Int32(1)] | ||
]); | ||
|
||
// meta assertions: demonstrating that keys are not reordered like objects would | ||
expect(Array.from(map.keys())).to.deep.equal(['2', '1']); | ||
expect(Object.keys({ [2]: 2, [1]: 1 })).to.deep.equal(['1', '2']); | ||
|
||
const expected = bufferFromHexArray([ | ||
'10', // int32 type | ||
'3200', // '2' & null | ||
'02000000', // LE 32bit 2 | ||
'10', // int32 type | ||
'3100', // '1' & null | ||
'01000000' // LE 32bit 1 | ||
]); | ||
const result = BSON.serialize(map); | ||
expect(result).to.have.property('byteLength', 19); | ||
expect(result).to.deep.equal(expected); | ||
}); | ||
}); |
Oops, something went wrong.