Skip to content
This repository was archived by the owner on Feb 3, 2022. It is now read-only.

Commit 0cbe79a

Browse files
committed
test(*): extJSON => EJSON
1 parent be588aa commit 0cbe79a

File tree

2 files changed

+34
-35
lines changed

2 files changed

+34
-35
lines changed

test/bson_corpus_tests.js

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,15 @@
11
'use strict';
22

3-
const extJSON = require('..');
3+
const EJSON = require('..');
44
const BSON = require('bson');
55
const expect = require('chai').expect;
66

77
function nativeToBson(native) {
8-
var b = new BSON();
9-
var serializeOptions = {
8+
const serializeOptions = {
109
ignoreUndefined: false
1110
};
12-
return b.serialize(native, serializeOptions);
11+
12+
return BSON.serialize(native, serializeOptions);
1313
}
1414

1515
function bsonToNative(bson) {
@@ -18,32 +18,32 @@ function bsonToNative(bson) {
1818
promoteLongs: true,
1919
promoteValues: false
2020
};
21-
var b = new BSON();
22-
return b.deserialize(bson, deserializeOptions);
21+
22+
return BSON.deserialize(bson, deserializeOptions);
2323
}
2424

2525
function jsonToNative(json) {
26-
return extJSON.parse(json);
26+
return EJSON.parse(json);
2727
}
2828

2929
function nativeToCEJSON(native) {
30-
return extJSON.stringify(native);
30+
return EJSON.stringify(native);
3131
}
3232

3333
function nativeToREJSON(native) {
34-
return extJSON.stringify(native, { relaxed: true });
34+
return EJSON.stringify(native, { relaxed: true });
3535
}
3636

3737
function normalize(cEJ) {
3838
return JSON.stringify(JSON.parse(cEJ));
3939
}
4040

41-
var skip = {
41+
const skip = {
4242
'Timestamp with high-order bit set on both seconds and increment':
4343
'Current BSON implementation of timestamp/long cannot hold these values - 1 too large.'
4444
};
4545

46-
var modifiedDoubles = {
46+
const modifiedDoubles = {
4747
'+1.0': { canonical_extjson: '{"d":{"$numberDouble":"1"}}' },
4848
'-1.0': { canonical_extjson: '{"d":{"$numberDouble":"-1"}}' },
4949
'1.23456789012345677E+18': { canonical_extjson: '{"d":{"$numberDouble":"1234567890123456800"}}' },
@@ -57,7 +57,7 @@ var modifiedDoubles = {
5757
}
5858
};
5959

60-
var modifiedMultitype = {
60+
const modifiedMultitype = {
6161
'All BSON types': {
6262
canonical_extjson:
6363
'{"_id":{"$oid":"57e193d7a9cc81b4027498b5"},"Symbol":"symbol","String":"string","Int32":{"$numberInt":"42"},"Int64":{"$numberLong":"42"},"Double":{"$numberDouble":"-1"},"Binary":{"$binary":{"base64":"o0w498Or7cijeBSpkquNtg==","subType":"03"}},"BinaryUserDefined":{"$binary":{"base64":"AQIDBAU=","subType":"80"}},"Code":{"$code":"function() {}"},"CodeWithScope":{"$code":"function() {}","$scope":{}},"Subdocument":{"foo":"bar"},"Array":[{"$numberInt":"1"},{"$numberInt":"2"},{"$numberInt":"3"},{"$numberInt":"4"},{"$numberInt":"5"}],"Timestamp":{"$timestamp":{"t":42,"i":1}},"Regex":{"$regularExpression":{"pattern":"pattern","options":""}},"DatetimeEpoch":{"$date":{"$numberLong":"0"}},"DatetimePositive":{"$date":{"$numberLong":"2147483647"}},"DatetimeNegative":{"$date":{"$numberLong":"-2147483648"}},"True":true,"False":false,"DBPointer":{"$ref":"collection","$id":{"$oid":"57e193d7a9cc81b4027498b1"}},"DBRef":{"$ref":"collection","$id":{"$oid":"57fd71e96e32ab4225b723fb"},"$db":"database"},"Minkey":{"$minKey":1},"Maxkey":{"$maxKey":1},"Null":null,"Undefined":null}',

test/extend_mongodb_tests.js

Lines changed: 22 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
const assert = require('assert');
44
const expect = require('chai').expect;
5-
const extJSON = require('..');
5+
const EJSON = require('..');
66
const BSON = require('bson');
77

88
// BSON types
@@ -57,12 +57,12 @@ describe('Extended JSON', function() {
5757
var json =
5858
'{"_id":{"$numberInt":"100"},"gh":{"$numberInt":"1"},"binary":{"$binary":{"base64":"AAECAwQFBgcICQoLDA0ODxAREhMUFRYXGBkaGxwdHh8gISIjJCUmJygpKissLS4vMDEyMzQ1Njc4OTo7PD0+Pw==","subType":"00"}},"date":{"$date":{"$numberLong":"1488372056737"}},"code":{"$code":"function() {}","$scope":{"a":{"$numberInt":"1"}}},"dbRef":{"$ref":"tests","$id":{"$numberInt":"1"},"$db":"test"},"decimal":{"$numberDecimal":"100"},"double":{"$numberDouble":"10.1"},"int32":{"$numberInt":"10"},"long":{"$numberLong":"200"},"maxKey":{"$maxKey":1},"minKey":{"$minKey":1},"objectId":{"$oid":"111111111111111111111111"},"regexp":{"$regularExpression":{"pattern":"hello world","options":"i"}},"symbol":{"$symbol":"symbol"},"timestamp":{"$timestamp":{"t":0,"i":1000}},"int32Number":{"$numberInt":"300"},"doubleNumber":{"$numberDouble":"200.2"},"longNumberIntFit":{"$numberLong":"7036874417766400"},"doubleNumberIntFit":{"$numberLong":"19007199250000000"}}';
5959

60-
assert.equal(json, extJSON.stringify(doc, null, 0));
60+
assert.equal(json, EJSON.stringify(doc, null, 0));
6161
});
6262

6363
it('should correctly deserialize using strict, and non-strict mode', function() {
6464
// Deserialize the document using non strict mode
65-
var doc1 = extJSON.parse(extJSON.stringify(doc, null, 0), { strict: false });
65+
var doc1 = EJSON.parse(EJSON.stringify(doc, null, 0), { strict: false });
6666

6767
// Validate the values
6868
assert.equal(300, doc1.int32Number);
@@ -71,7 +71,7 @@ describe('Extended JSON', function() {
7171
assert.equal(19007199250000000.12, doc1.doubleNumberIntFit);
7272

7373
// Deserialize the document using strict mode
74-
doc1 = extJSON.parse(extJSON.stringify(doc, null, 0), { strict: true });
74+
doc1 = EJSON.parse(EJSON.stringify(doc, null, 0), { strict: true });
7575

7676
// Validate the values
7777
expect(doc1.int32Number._bsontype).to.equal('Int32');
@@ -82,44 +82,44 @@ describe('Extended JSON', function() {
8282

8383
it('should correctly serialize, and deserialize using built-in BSON', function() {
8484
// Create ExtJSON instance
85-
var Int32 = extJSON.BSON.Int32;
85+
var Int32 = EJSON.BSON.Int32;
8686
// Create a doc
8787
var doc1 = {
8888
int32: new Int32(10)
8989
};
9090

9191
// Serialize the document
92-
var text = extJSON.stringify(doc1, null, 0);
92+
var text = EJSON.stringify(doc1, null, 0);
9393
expect(text).to.equal('{"int32":{"$numberInt":"10"}}');
9494

9595
// Deserialize the json in strict and non strict mode
96-
var doc2 = extJSON.parse(text, { strict: true });
96+
var doc2 = EJSON.parse(text, { strict: true });
9797
expect(doc2.int32._bsontype).to.equal('Int32');
98-
doc2 = extJSON.parse(text, { strict: false });
98+
doc2 = EJSON.parse(text, { strict: false });
9999
expect(doc2.int32).to.equal(10);
100100
});
101101

102102
it('should correctly serialize bson types when they are values', function() {
103-
var Int32 = extJSON.BSON.Int32;
104-
var serialized = extJSON.stringify(new ObjectID('591801a468f9e7024b6235ea'));
103+
var Int32 = EJSON.BSON.Int32;
104+
var serialized = EJSON.stringify(new ObjectID('591801a468f9e7024b6235ea'));
105105
expect(serialized).to.equal('{"$oid":"591801a468f9e7024b6235ea"}');
106-
serialized = extJSON.stringify(new Int32(42));
106+
serialized = EJSON.stringify(new Int32(42));
107107
expect(serialized).to.equal('{"$numberInt":"42"}');
108-
serialized = extJSON.stringify({
108+
serialized = EJSON.stringify({
109109
_id: { $nin: [new ObjectID('591801a468f9e7024b6235ea')] }
110110
});
111111
expect(serialized).to.equal('{"_id":{"$nin":[{"$oid":"591801a468f9e7024b6235ea"}]}}');
112112

113-
serialized = extJSON.stringify(new Binary(new Uint8Array([1, 2, 3, 4, 5])));
113+
serialized = EJSON.stringify(new Binary(new Uint8Array([1, 2, 3, 4, 5])));
114114
expect(serialized).to.equal('{"$binary":{"base64":"AQIDBAU=","subType":"00"}}');
115115
});
116116

117117
it('should correctly parse null values', function() {
118-
expect(extJSON.parse('null')).to.be.null;
119-
expect(extJSON.parse('[null]')[0]).to.be.null;
118+
expect(EJSON.parse('null')).to.be.null;
119+
expect(EJSON.parse('[null]')[0]).to.be.null;
120120

121121
var input = '{"result":[{"_id":{"$oid":"591801a468f9e7024b623939"},"emptyField":null}]}';
122-
var parsed = extJSON.parse(input, { strict: false });
122+
var parsed = EJSON.parse(input, { strict: false });
123123

124124
expect(parsed).to.deep.equal({
125125
result: [{ _id: new ObjectID('591801a468f9e7024b623939'), emptyField: null }]
@@ -128,7 +128,7 @@ describe('Extended JSON', function() {
128128

129129
it('should correctly throw when passed a non-string to parse', function() {
130130
expect(() => {
131-
extJSON.parse({}, { strict: true });
131+
EJSON.parse({}, { strict: true });
132132
}).to.throw;
133133
});
134134

@@ -141,7 +141,7 @@ describe('Extended JSON', function() {
141141
date: { $date: { $numberLong: '1452124800000' } }
142142
};
143143

144-
const parsed = extJSON.parse(JSON.stringify(inputObject), { relaxed: true });
144+
const parsed = EJSON.parse(JSON.stringify(inputObject), { relaxed: true });
145145
expect(parsed).to.eql({
146146
int: 500,
147147
long: 42,
@@ -151,8 +151,8 @@ describe('Extended JSON', function() {
151151
});
152152

153153
it('should allow regexp', function() {
154-
const parsedRegExp = extJSON.stringify({ test: /some-regex/i }, { relaxed: true });
155-
const parsedBSONRegExp = extJSON.stringify(
154+
const parsedRegExp = EJSON.stringify({ test: /some-regex/i }, { relaxed: true });
155+
const parsedBSONRegExp = EJSON.stringify(
156156
{ test: new BSONRegExp('some-regex', 'i') },
157157
{ relaxed: true }
158158
);
@@ -176,8 +176,7 @@ describe('Extended JSON', function() {
176176
timestamp: new Timestamp()
177177
};
178178

179-
const result = extJSON.serialize(doc);
180-
179+
const result = EJSON.serialize(doc);
181180
expect(result).to.deep.equal({
182181
binary: { $binary: { base64: '', subType: '00' } },
183182
code: { $code: 'function() {}' },
@@ -212,7 +211,7 @@ describe('Extended JSON', function() {
212211
timestamp: { $timestamp: { t: 0, i: 0 } }
213212
};
214213

215-
const result = extJSON.deserialize(doc);
214+
const result = EJSON.deserialize(doc);
216215

217216
// binary
218217
expect(result.binary).to.be.an.instanceOf(BSON.Binary);

0 commit comments

Comments
 (0)