-
Notifications
You must be signed in to change notification settings - Fork 256
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix(Timestamp): make sure timestamp is always unsigned
Fixes NODE-1939
- Loading branch information
1 parent
51862d8
commit 36b2d43
Showing
2 changed files
with
42 additions
and
6 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
'use strict'; | ||
|
||
const BSON = require('../../lib/bson'); | ||
const expect = require('chai').expect; | ||
|
||
describe('Timestamp', function() { | ||
it('should have a MAX_VALUE equal to Long.MAX_UNSIGNED_VALUE', function() { | ||
expect(BSON.Timestamp.MAX_VALUE).to.equal(BSON.Long.MAX_UNSIGNED_VALUE); | ||
}); | ||
|
||
it('should always be an unsigned value', function() { | ||
[ | ||
new BSON.Timestamp(), | ||
new BSON.Timestamp(0xff, 0xffffffff), | ||
new BSON.Timestamp(0xffffffff, 0xffffffff), | ||
new BSON.Timestamp(-1, -1), | ||
new BSON.Timestamp(new BSON.Timestamp(0xffffffff, 0xffffffff)), | ||
new BSON.Timestamp(new BSON.Long(0xffffffff, 0xfffffffff, false)), | ||
new BSON.Timestamp(new BSON.Long(0xffffffff, 0xfffffffff, true)) | ||
].forEach(timestamp => { | ||
expect(timestamp).to.have.property('unsigned', true); | ||
}); | ||
}); | ||
|
||
it('should print out an unsigned number', function() { | ||
const timestamp = new BSON.Timestamp(0xffffffff, 0xffffffff); | ||
expect(timestamp.toString()).to.equal('18446744073709551615'); | ||
expect(timestamp.toJSON()).to.deep.equal({ $timestamp: '18446744073709551615' }); | ||
expect(timestamp.toExtendedJSON()).to.deep.equal({ | ||
$timestamp: { t: 4294967295, i: 4294967295 } | ||
}); | ||
}); | ||
}); |