|
1 | 1 | import { expect } from 'chai';
|
2 | 2 | import { isDeepStrictEqual } from 'util';
|
3 |
| -import { Binary, Document, Double, Int32, Long, ObjectId, Timestamp } from '../../../src'; |
| 3 | +import { Binary, Document, Long, ObjectId } from '../../../src'; |
4 | 4 | import {
|
5 | 5 | CommandFailedEvent,
|
6 | 6 | CommandStartedEvent,
|
@@ -78,91 +78,34 @@ export function isSpecialOperator(value: unknown): value is SpecialOperator {
|
78 | 78 | }
|
79 | 79 |
|
80 | 80 | const TYPE_MAP = new Map();
|
81 |
| -function typeof_double(actual): actual is number | Double { |
82 |
| - return typeof actual === 'number' || actual._bsontype === 'Double'; |
83 |
| -} |
84 |
| -function typeof_string(actual: unknown): actual is string { |
85 |
| - return typeof actual === 'string'; |
86 |
| -} |
87 |
| -function typeof_object(actual: unknown): actual is Document { |
88 |
| - return typeof actual === 'object' && actual !== null; |
89 |
| -} |
90 |
| -function typeof_array(actual: unknown): actual is unknown[] { |
91 |
| - return Array.isArray(actual); |
92 |
| -} |
93 |
| -function typeof_binData(actual) { |
94 |
| - return actual instanceof Binary; |
95 |
| -} |
96 |
| -function typeof_undefined(actual) { |
97 |
| - return actual === undefined; |
98 |
| -} |
99 |
| -function typeof_objectId(actual) { |
100 |
| - return actual instanceof ObjectId; |
101 |
| -} |
102 |
| -function typeof_bool(actual) { |
103 |
| - return typeof actual === 'boolean'; |
104 |
| -} |
105 |
| -function typeof_date(actual) { |
106 |
| - return actual instanceof Date; |
107 |
| -} |
108 |
| -function typeof_null(actual) { |
109 |
| - return actual === null; |
110 |
| -} |
111 |
| -function typeof_regex(actual) { |
112 |
| - return actual instanceof RegExp || actual._bsontype === 'BSONRegExp'; |
113 |
| -} |
114 |
| -function typeof_dbPointer(actual) { |
115 |
| - return actual._bsontype === 'DBRef'; |
116 |
| -} |
117 |
| -function typeof_javascript(actual) { |
118 |
| - return actual._bsontype === 'Code'; |
119 |
| -} |
120 |
| -function typeof_symbol(actual) { |
121 |
| - return actual._bsontype === 'Symbol'; |
122 |
| -} |
123 |
| -function typeof_javascriptWithScope(actual) { |
124 |
| - return actual._bsontype === 'Code' && actual.scope; |
125 |
| -} |
126 |
| -function typeof_int(actual): actual is number | Int32 { |
127 |
| - return (typeof actual === 'number' && Number.isInteger(actual)) || actual._bsontype === 'Int32'; |
128 |
| -} |
129 |
| -function typeof_timestamp(actual: Timestamp, expected: Timestamp) { |
130 |
| - expect(actual.equals(expected)).to.be.true; |
131 |
| -} |
132 |
| -function typeof_long(actual: unknown): actual is number | Long { |
133 |
| - return (typeof actual === 'number' && Number.isInteger(actual)) || Long.isLong(actual); |
134 |
| -} |
135 |
| -function typeof_decimal(actual) { |
136 |
| - return actual._bsontype === 'Decimal128'; |
137 |
| -} |
138 |
| -function typeof_minKey(actual) { |
139 |
| - return actual._bsontype === 'MinKey'; |
140 |
| -} |
141 |
| -function typeof_maxKey(actual) { |
142 |
| - return actual._bsontype === 'MaxKey'; |
143 |
| -} |
144 | 81 |
|
145 |
| -TYPE_MAP.set('double', typeof_double); |
146 |
| -TYPE_MAP.set('string', typeof_string); |
147 |
| -TYPE_MAP.set('object', typeof_object); |
148 |
| -TYPE_MAP.set('array', typeof_array); |
149 |
| -TYPE_MAP.set('binData', typeof_binData); |
150 |
| -TYPE_MAP.set('undefined', typeof_undefined); |
151 |
| -TYPE_MAP.set('objectId', typeof_objectId); |
152 |
| -TYPE_MAP.set('bool', typeof_bool); |
153 |
| -TYPE_MAP.set('date', typeof_date); |
154 |
| -TYPE_MAP.set('null', typeof_null); |
155 |
| -TYPE_MAP.set('regex', typeof_regex); |
156 |
| -TYPE_MAP.set('dbPointer', typeof_dbPointer); |
157 |
| -TYPE_MAP.set('javascript', typeof_javascript); |
158 |
| -TYPE_MAP.set('symbol', typeof_symbol); |
159 |
| -TYPE_MAP.set('javascriptWithScope', typeof_javascriptWithScope); |
160 |
| -TYPE_MAP.set('int', typeof_int); |
161 |
| -TYPE_MAP.set('timestamp', typeof_timestamp); |
162 |
| -TYPE_MAP.set('long', typeof_long); |
163 |
| -TYPE_MAP.set('decimal', typeof_decimal); |
164 |
| -TYPE_MAP.set('minKey', typeof_minKey); |
165 |
| -TYPE_MAP.set('maxKey', typeof_maxKey); |
| 82 | +TYPE_MAP.set('double', actual => typeof actual === 'number' || actual._bsontype === 'Double'); |
| 83 | +TYPE_MAP.set('string', actual => typeof actual === 'string'); |
| 84 | +TYPE_MAP.set('object', actual => typeof actual === 'object' && actual !== null); |
| 85 | +TYPE_MAP.set('array', actual => Array.isArray(actual)); |
| 86 | +TYPE_MAP.set('binData', actual => actual instanceof Binary); |
| 87 | +TYPE_MAP.set('undefined', actual => actual === undefined); |
| 88 | +TYPE_MAP.set('objectId', actual => actual instanceof ObjectId); |
| 89 | +TYPE_MAP.set('bool', actual => typeof actual === 'boolean'); |
| 90 | +TYPE_MAP.set('date', actual => actual instanceof Date); |
| 91 | +TYPE_MAP.set('null', actual => actual === null); |
| 92 | +TYPE_MAP.set('regex', actual => actual instanceof RegExp || actual._bsontype === 'BSONRegExp'); |
| 93 | +TYPE_MAP.set('dbPointer', actual => actual._bsontype === 'DBRef'); |
| 94 | +TYPE_MAP.set('javascript', actual => actual._bsontype === 'Code'); |
| 95 | +TYPE_MAP.set('symbol', actual => actual._bsontype === 'Symbol'); |
| 96 | +TYPE_MAP.set('javascriptWithScope', actual => actual._bsontype === 'Code' && actual.scope); |
| 97 | +TYPE_MAP.set('timestamp', actual => actual._bsontype === 'Timestamp'); |
| 98 | +TYPE_MAP.set('decimal', actual => actual._bsontype === 'Decimal128'); |
| 99 | +TYPE_MAP.set('minKey', actual => actual._bsontype === 'MinKey'); |
| 100 | +TYPE_MAP.set('maxKey', actual => actual._bsontype === 'MaxKey'); |
| 101 | +TYPE_MAP.set( |
| 102 | + 'int', |
| 103 | + actual => (typeof actual === 'number' && Number.isInteger(actual)) || actual._bsontype === 'Int32' |
| 104 | +); |
| 105 | +TYPE_MAP.set( |
| 106 | + 'long', |
| 107 | + actual => (typeof actual === 'number' && Number.isInteger(actual)) || Long.isLong(actual) |
| 108 | +); |
166 | 109 |
|
167 | 110 | export function expectResultCheck(
|
168 | 111 | actual: Document,
|
|
0 commit comments