|
1 | | -'use strict'; |
2 | | - |
3 | | -const constants = require('../../src/constants'); |
4 | | -const BSON = require('../register-bson'); |
| 1 | +import * as constants from '../../src/constants'; |
| 2 | +import * as BSON from '../register-bson'; |
5 | 3 |
|
6 | 4 | describe('BSON Constants', () => { |
7 | 5 | context('Binary Subtype', () => { |
@@ -140,4 +138,42 @@ describe('BSON Constants', () => { |
140 | 138 | expect(constants.BSON_DATA_MAX_KEY).to.equal(0x7f); |
141 | 139 | }); |
142 | 140 | }); |
| 141 | + |
| 142 | + describe('BSONType enum', () => { |
| 143 | + it('double equals 1', () => expect(constants.BSONType.double).to.equal(1)); |
| 144 | + it('string equals 2', () => expect(constants.BSONType.string).to.equal(2)); |
| 145 | + it('object equals 3', () => expect(constants.BSONType.object).to.equal(3)); |
| 146 | + it('array equals 4', () => expect(constants.BSONType.array).to.equal(4)); |
| 147 | + it('binData equals 5', () => expect(constants.BSONType.binData).to.equal(5)); |
| 148 | + it('undefined equals 6', () => expect(constants.BSONType.undefined).to.equal(6)); |
| 149 | + it('objectId equals 7', () => expect(constants.BSONType.objectId).to.equal(7)); |
| 150 | + it('bool equals 8', () => expect(constants.BSONType.bool).to.equal(8)); |
| 151 | + it('date equals 9', () => expect(constants.BSONType.date).to.equal(9)); |
| 152 | + it('null equals 10', () => expect(constants.BSONType.null).to.equal(10)); |
| 153 | + it('regex equals 11', () => expect(constants.BSONType.regex).to.equal(11)); |
| 154 | + it('dbPointer equals 12', () => expect(constants.BSONType.dbPointer).to.equal(12)); |
| 155 | + it('javascript equals 13', () => expect(constants.BSONType.javascript).to.equal(13)); |
| 156 | + it('symbol equals 14', () => expect(constants.BSONType.symbol).to.equal(14)); |
| 157 | + it('javascriptWithScope equals 15', () => |
| 158 | + expect(constants.BSONType.javascriptWithScope).to.equal(15)); |
| 159 | + it('int equals 16', () => expect(constants.BSONType.int).to.equal(16)); |
| 160 | + it('timestamp equals 17', () => expect(constants.BSONType.timestamp).to.equal(17)); |
| 161 | + it('long equals 18', () => expect(constants.BSONType.long).to.equal(18)); |
| 162 | + it('decimal equals 19', () => expect(constants.BSONType.decimal).to.equal(19)); |
| 163 | + it('minKey equals -1', () => expect(constants.BSONType.minKey).to.equal(-1)); |
| 164 | + it('maxKey equals 27', () => expect(constants.BSONType.maxKey).to.equal(127)); |
| 165 | + |
| 166 | + it('minKey equals 255 when used in Uint8Array', () => { |
| 167 | + const byte = new Uint8Array(1); |
| 168 | + byte[0] = constants.BSONType.minKey; |
| 169 | + expect(byte[0]).to.equal(255); |
| 170 | + }); |
| 171 | + |
| 172 | + it('minKey equals 255 when used in DataView in unsigned way', () => { |
| 173 | + const dv = new DataView(new ArrayBuffer(1)); |
| 174 | + dv.setUint8(0, constants.BSONType.minKey); |
| 175 | + expect(dv.getUint8(0)).to.equal(255); |
| 176 | + expect(new Uint8Array(dv.buffer, 0, 1)[0]).to.equal(255); |
| 177 | + }); |
| 178 | + }); |
143 | 179 | }); |
0 commit comments