-
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
Co-authored-by: Bailey Pearson <bailey.pearson@mongodb.com>
- Loading branch information
1 parent
be74b30
commit 5103e4d
Showing
9 changed files
with
103 additions
and
37 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 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 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 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,10 @@ | ||
import * as BSON from '../../register-bson'; | ||
import { expect } from 'chai'; | ||
|
||
describe('calculateSize()', () => { | ||
it('should only enumerate own property keys from input objects', () => { | ||
const input = { a: 1 }; | ||
Object.setPrototypeOf(input, { b: 2 }); | ||
expect(BSON.calculateObjectSize(input)).to.equal(12); | ||
}); | ||
}); |
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,18 @@ | ||
import * as BSON from '../../register-bson'; | ||
import { expect } from 'chai'; | ||
|
||
describe('deserializer()', () => { | ||
describe('when the fieldsAsRaw options is present and has a value that corresponds to a key in the object', () => { | ||
it('ignores non-own properties set on the options object', () => { | ||
const bytes = BSON.serialize({ someKey: [1] }); | ||
const options = { fieldsAsRaw: { someKey: true } }; | ||
Object.setPrototypeOf(options, { promoteValues: false }); | ||
const result = BSON.deserialize(bytes, options); | ||
expect(result).to.have.property('someKey').that.is.an('array'); | ||
expect( | ||
result.someKey[0], | ||
'expected promoteValues option set on options object prototype to be ignored, but it was not' | ||
).to.not.have.property('_bsontype', 'Int32'); | ||
}); | ||
}); | ||
}); |
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,17 @@ | ||
import * as BSON from '../../register-bson'; | ||
import { bufferFromHexArray } from '../tools/utils'; | ||
import { expect } from 'chai'; | ||
|
||
describe('serialize()', () => { | ||
it('should only enumerate own property keys from input objects', () => { | ||
const input = { a: 1 }; | ||
Object.setPrototypeOf(input, { b: 2 }); | ||
const bytes = BSON.serialize(input); | ||
expect(bytes).to.deep.equal( | ||
bufferFromHexArray([ | ||
'106100', // type int32, a\x00 | ||
'01000000' // int32LE = 1 | ||
]) | ||
); | ||
}); | ||
}); |