|
1 | 1 | load(__dirname + '/index.js'); |
2 | 2 |
|
| 3 | +const bson = require('bson'); |
| 4 | + |
3 | 5 | assert.strictEqual(ObjectId('0123456789abcdef01234567').tojson(), 'ObjectId("0123456789abcdef01234567")'); |
4 | 6 |
|
5 | 7 | assert.strictEqual(BinData(4, 'abcdefgh').toString(), 'BinData(4,"abcdefgh")'); |
@@ -87,7 +89,7 @@ const tsFromStr = Timestamp.fromString('ff', 16); |
87 | 89 | assert.strictEqual(tsFromStr.i, 255); |
88 | 90 | assert.strictEqual(tsFromStr.t, 0); |
89 | 91 | assert.strictEqual(Timestamp.MAX_VALUE._bsontype, 'Long'); |
90 | | -assert.strictEqual(Timestamp.MAX_VALUE, Long.MAX_UNSIGNED_VALUE); |
| 92 | +assert.strictEqual(Timestamp.MAX_VALUE, Long.MAX_UNSIGNED_VALUE); |
91 | 93 |
|
92 | 94 | const id = ObjectId('68ffa28b77bba38c9ddcf376'); |
93 | 95 | const dbRef = DBRef('testColl', id, 'testDb'); |
@@ -161,3 +163,19 @@ assert(sortedArrayJson.indexOf('"a"') < sortedArrayJson.indexOf('"z"'), 'Array.t |
161 | 163 | assert(sortedArrayJson.indexOf('"b"') < sortedArrayJson.indexOf('"y"'), 'Array.tojson with sortedKeys=true should sort object keys in array elements'); |
162 | 164 | assert(unsortedArrayJson.indexOf('"z"') < unsortedArrayJson.indexOf('"a"'), 'Array.tojson with sortedKeys=false should not sort keys'); |
163 | 165 | assert(defaultArrayJson.indexOf('"z"') < defaultArrayJson.indexOf('"a"'), 'Array.tojson without sortedKeys should not sort keys'); |
| 166 | + |
| 167 | +// Test MinKey |
| 168 | +const minKey = new MinKey(); |
| 169 | +assert(minKey instanceof MinKey, "minKey should be an instance of MinKey"); |
| 170 | +assert.strictEqual(minKey.tojson(), '{ "$minKey" : 1 }'); |
| 171 | +assert.strictEqual(minKey.toString(), "[object Function]"); |
| 172 | +assert.strictEqual(minKey.toJSON(), '{ "$minKey" : 1 }'); |
| 173 | + |
| 174 | +// Test that multiple references return the same instance |
| 175 | +const anotherMinKeyRef = new MinKey(); |
| 176 | +assert.strictEqual(minKey, anotherMinKeyRef); |
| 177 | +assert.strictEqual(MinKey(), MinKey()); |
| 178 | + |
| 179 | +const serializedBsonMinKey = bson.serialize({ key1: MinKey, key2: MinKey() }); |
| 180 | +const deserializedBsonMinKey = bson.deserialize(serializedBsonMinKey); |
| 181 | +assert.deepStrictEqual(deserializedBsonMinKey.key1, deserializedBsonMinKey.key2); |
0 commit comments