@@ -30,16 +30,16 @@ const util = require('util');
30
30
const Buffer = require ( 'buffer' ) . Buffer ;
31
31
const pToString = ( obj ) => Object . prototype . toString . call ( obj ) ;
32
32
33
- // 1. The assert module provides functions that throw
33
+ // The assert module provides functions that throw
34
34
// AssertionError's when particular conditions are not met. The
35
35
// assert module must conform to the following interface.
36
36
37
37
const assert = module . exports = ok ;
38
38
39
- // 2. The AssertionError is defined in assert.
39
+ // The AssertionError is defined in assert.
40
40
// new assert.AssertionError({ message: message,
41
41
// actual: actual,
42
- // expected: expected })
42
+ // expected: expected });
43
43
44
44
assert . AssertionError = function AssertionError ( options ) {
45
45
this . name = 'AssertionError' ;
@@ -75,7 +75,7 @@ function getMessage(self) {
75
75
// other keys to the AssertionError's constructor - they will be
76
76
// ignored.
77
77
78
- // 3. All of the following functions must throw an AssertionError
78
+ // All of the following functions must throw an AssertionError
79
79
// when a corresponding condition is not met, with a message that
80
80
// may be undefined if not provided. All assertion methods provide
81
81
// both the actual and expected values to the assertion error for
@@ -94,7 +94,7 @@ function fail(actual, expected, message, operator, stackStartFunction) {
94
94
// EXTENSION! allows for well behaved errors defined elsewhere.
95
95
assert . fail = fail ;
96
96
97
- // 4. Pure assertion tests whether a value is truthy, as determined
97
+ // Pure assertion tests whether a value is truthy, as determined
98
98
// by !!guard.
99
99
// assert.ok(guard, message_opt);
100
100
// This statement is equivalent to assert.equal(true, !!guard,
@@ -106,24 +106,25 @@ function ok(value, message) {
106
106
}
107
107
assert . ok = ok ;
108
108
109
- // 5. The equality assertion tests shallow, coercive equality with
109
+ // The equality assertion tests shallow, coercive equality with
110
110
// ==.
111
111
// assert.equal(actual, expected, message_opt);
112
112
113
113
assert . equal = function equal ( actual , expected , message ) {
114
114
if ( actual != expected ) fail ( actual , expected , message , '==' , assert . equal ) ;
115
115
} ;
116
116
117
- // 6. The non-equality assertion tests for whether two objects are not equal
118
- // with != assert.notEqual(actual, expected, message_opt);
117
+ // The non-equality assertion tests for whether two objects are not
118
+ // equal with !=.
119
+ // assert.notEqual(actual, expected, message_opt);
119
120
120
121
assert . notEqual = function notEqual ( actual , expected , message ) {
121
122
if ( actual == expected ) {
122
123
fail ( actual , expected , message , '!=' , assert . notEqual ) ;
123
124
}
124
125
} ;
125
126
126
- // 7. The equivalence assertion tests a deep equality relation.
127
+ // The equivalence assertion tests a deep equality relation.
127
128
// assert.deepEqual(actual, expected, message_opt);
128
129
129
130
/* eslint-disable no-restricted-properties */
@@ -141,18 +142,22 @@ assert.deepStrictEqual = function deepStrictEqual(actual, expected, message) {
141
142
} ;
142
143
143
144
function _deepEqual ( actual , expected , strict , memos ) {
144
- // 7.1. All identical values are equivalent, as determined by ===.
145
+ // All identical values are equivalent, as determined by ===.
145
146
if ( actual === expected ) {
146
147
return true ;
148
+
149
+ // If both values are instances of buffers, equivalence is
150
+ // determined by comparing the values and ensuring the result
151
+ // === 0.
147
152
} else if ( actual instanceof Buffer && expected instanceof Buffer ) {
148
153
return compare ( actual , expected ) === 0 ;
149
154
150
- // 7.2. If the expected value is a Date object, the actual value is
155
+ // If the expected value is a Date object, the actual value is
151
156
// equivalent if it is also a Date object that refers to the same time.
152
157
} else if ( util . isDate ( actual ) && util . isDate ( expected ) ) {
153
158
return actual . getTime ( ) === expected . getTime ( ) ;
154
159
155
- // 7.3 If the expected value is a RegExp object, the actual value is
160
+ // If the expected value is a RegExp object, the actual value is
156
161
// equivalent if it is also a RegExp object with the same source and
157
162
// properties (`global`, `multiline`, `lastIndex`, `ignoreCase`).
158
163
} else if ( util . isRegExp ( actual ) && util . isRegExp ( expected ) ) {
@@ -162,18 +167,18 @@ function _deepEqual(actual, expected, strict, memos) {
162
167
actual . lastIndex === expected . lastIndex &&
163
168
actual . ignoreCase === expected . ignoreCase ;
164
169
165
- // 7.4. Other pairs that do not both pass typeof value == 'object',
166
- // equivalence is determined by ==.
170
+ // If both values are primitives, equivalence is determined by
171
+ // == or, if checking for strict equivalence, = ==.
167
172
} else if ( ( actual === null || typeof actual !== 'object' ) &&
168
173
( expected === null || typeof expected !== 'object' ) ) {
169
174
return strict ? actual === expected : actual == expected ;
170
175
171
176
// If both values are instances of typed arrays, wrap their underlying
172
- // ArrayBuffers in a Buffer each to increase performance
177
+ // ArrayBuffers in a Buffer to increase performance.
173
178
// This optimization requires the arrays to have the same type as checked by
174
- // Object.prototype.toString (aka pToString). Never perform binary
175
- // comparisons for Float*Arrays, though, since e.g. +0 === -0 but their
176
- // bit patterns are not identical.
179
+ // Object.prototype.toString (pToString). Never perform binary
180
+ // comparisons for Float*Arrays, though, since +0 === -0 is true despite the
181
+ // two values' bit patterns not being identical.
177
182
} else if ( ArrayBuffer . isView ( actual ) && ArrayBuffer . isView ( expected ) &&
178
183
pToString ( actual ) === pToString ( expected ) &&
179
184
! ( actual instanceof Float32Array ||
@@ -185,7 +190,7 @@ function _deepEqual(actual, expected, strict, memos) {
185
190
expected . byteOffset ,
186
191
expected . byteLength ) ) === 0 ;
187
192
188
- // 7.5 For all other Object pairs, including Array objects, equivalence is
193
+ // For all other Object pairs, including Array objects, equivalence is
189
194
// determined by having the same number of owned properties (as verified
190
195
// with Object.prototype.hasOwnProperty.call), the same set of keys
191
196
// (although not necessarily the same order), equivalent values for every
@@ -215,7 +220,8 @@ function isArguments(object) {
215
220
function objEquiv ( a , b , strict , actualVisitedObjects ) {
216
221
if ( a === null || a === undefined || b === null || b === undefined )
217
222
return false ;
218
- // if one is a primitive, the other must be same
223
+
224
+ // If one is a primitive, the other must be the same.
219
225
if ( util . isPrimitive ( a ) || util . isPrimitive ( b ) )
220
226
return a === b ;
221
227
if ( strict && Object . getPrototypeOf ( a ) !== Object . getPrototypeOf ( b ) )
@@ -227,20 +233,23 @@ function objEquiv(a, b, strict, actualVisitedObjects) {
227
233
const ka = Object . keys ( a ) ;
228
234
const kb = Object . keys ( b ) ;
229
235
var key , i ;
230
- // having the same number of owned properties (keys incorporates
231
- // hasOwnProperty)
236
+
237
+ // The pair must have the same number of owned properties (keys
238
+ // incorporates hasOwnProperty).
232
239
if ( ka . length !== kb . length )
233
240
return false ;
234
- //the same set of keys (although not necessarily the same order),
241
+
242
+ // The pair must have the same set of keys (although not
243
+ // necessarily in the same order).
235
244
ka . sort ( ) ;
236
245
kb . sort ( ) ;
237
- //~~~cheap key test
246
+ // Cheap key test:
238
247
for ( i = ka . length - 1 ; i >= 0 ; i -- ) {
239
248
if ( ka [ i ] !== kb [ i ] )
240
249
return false ;
241
250
}
242
- //equivalent values for every corresponding key, and
243
- //~~~possibly expensive deep test
251
+ // The pair must have equivalent values for every corresponding key.
252
+ // Possibly expensive deep test:
244
253
for ( i = ka . length - 1 ; i >= 0 ; i -- ) {
245
254
key = ka [ i ] ;
246
255
if ( ! _deepEqual ( a [ key ] , b [ key ] , strict , actualVisitedObjects ) )
@@ -249,7 +258,7 @@ function objEquiv(a, b, strict, actualVisitedObjects) {
249
258
return true ;
250
259
}
251
260
252
- // 8. The non-equivalence assertion tests for any deep inequality.
261
+ // The non-equivalence assertion tests for any deep inequality.
253
262
// assert.notDeepEqual(actual, expected, message_opt);
254
263
255
264
assert . notDeepEqual = function notDeepEqual ( actual , expected , message ) {
@@ -266,7 +275,7 @@ function notDeepStrictEqual(actual, expected, message) {
266
275
}
267
276
268
277
269
- // 9. The strict equality assertion tests strict equality, as determined by ===.
278
+ // The strict equality assertion tests strict equality, as determined by ===.
270
279
// assert.strictEqual(actual, expected, message_opt);
271
280
272
281
assert . strictEqual = function strictEqual ( actual , expected , message ) {
@@ -275,8 +284,9 @@ assert.strictEqual = function strictEqual(actual, expected, message) {
275
284
}
276
285
} ;
277
286
278
- // 10. The strict non-equality assertion tests for strict inequality, as
279
- // determined by !==. assert.notStrictEqual(actual, expected, message_opt);
287
+ // The strict non-equality assertion tests for strict inequality, as
288
+ // determined by !==.
289
+ // assert.notStrictEqual(actual, expected, message_opt);
280
290
281
291
assert . notStrictEqual = function notStrictEqual ( actual , expected , message ) {
282
292
if ( actual === expected ) {
@@ -298,7 +308,7 @@ function expectedException(actual, expected) {
298
308
return true ;
299
309
}
300
310
} catch ( e ) {
301
- // Ignore. The instanceof check doesn't work for arrow functions.
311
+ // Ignore. The instanceof check doesn't work for arrow functions.
302
312
}
303
313
304
314
if ( Error . isPrototypeOf ( expected ) ) {
@@ -356,7 +366,7 @@ function _throws(shouldThrow, block, expected, message) {
356
366
}
357
367
}
358
368
359
- // 11. Expected to throw an error:
369
+ // Expected to throw an error.
360
370
// assert.throws(block, Error_opt, message_opt);
361
371
362
372
assert . throws = function throws ( block , /*optional*/ error , /*optional*/ message ) {
0 commit comments