@@ -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
assert . deepEqual = function deepEqual ( actual , expected , message ) {
@@ -139,18 +140,22 @@ assert.deepStrictEqual = function deepStrictEqual(actual, expected, message) {
139
140
} ;
140
141
141
142
function _deepEqual ( actual , expected , strict , memos ) {
142
- // 7.1. All identical values are equivalent, as determined by ===.
143
+ // All identical values are equivalent, as determined by ===.
143
144
if ( actual === expected ) {
144
145
return true ;
146
+
147
+ // If both values are instances of buffers, equivalence is
148
+ // determined by comparing the values and ensuring the result
149
+ // === 0.
145
150
} else if ( actual instanceof Buffer && expected instanceof Buffer ) {
146
151
return compare ( actual , expected ) === 0 ;
147
152
148
- // 7.2. If the expected value is a Date object, the actual value is
153
+ // If the expected value is a Date object, the actual value is
149
154
// equivalent if it is also a Date object that refers to the same time.
150
155
} else if ( util . isDate ( actual ) && util . isDate ( expected ) ) {
151
156
return actual . getTime ( ) === expected . getTime ( ) ;
152
157
153
- // 7.3 If the expected value is a RegExp object, the actual value is
158
+ // If the expected value is a RegExp object, the actual value is
154
159
// equivalent if it is also a RegExp object with the same source and
155
160
// properties (`global`, `multiline`, `lastIndex`, `ignoreCase`).
156
161
} else if ( util . isRegExp ( actual ) && util . isRegExp ( expected ) ) {
@@ -160,18 +165,18 @@ function _deepEqual(actual, expected, strict, memos) {
160
165
actual . lastIndex === expected . lastIndex &&
161
166
actual . ignoreCase === expected . ignoreCase ;
162
167
163
- // 7.4. Other pairs that do not both pass typeof value == 'object',
164
- // equivalence is determined by ==.
168
+ // If both values are primitives, equivalence is determined by
169
+ // == or, if checking for strict equivalence, = ==.
165
170
} else if ( ( actual === null || typeof actual !== 'object' ) &&
166
171
( expected === null || typeof expected !== 'object' ) ) {
167
172
return strict ? actual === expected : actual == expected ;
168
173
169
174
// If both values are instances of typed arrays, wrap their underlying
170
- // ArrayBuffers in a Buffer each to increase performance
175
+ // ArrayBuffers in a Buffer to increase performance.
171
176
// This optimization requires the arrays to have the same type as checked by
172
- // Object.prototype.toString (aka pToString). Never perform binary
173
- // comparisons for Float*Arrays, though, since e.g. +0 === -0 but their
174
- // bit patterns are not identical.
177
+ // Object.prototype.toString (pToString). Never perform binary
178
+ // comparisons for Float*Arrays, though, since +0 === -0 is true despite the
179
+ // two values' bit patterns not being identical.
175
180
} else if ( ArrayBuffer . isView ( actual ) && ArrayBuffer . isView ( expected ) &&
176
181
pToString ( actual ) === pToString ( expected ) &&
177
182
! ( actual instanceof Float32Array ||
@@ -184,7 +189,7 @@ function _deepEqual(actual, expected, strict, memos) {
184
189
expected . byteOffset +
185
190
expected . byteLength ) ) === 0 ;
186
191
187
- // 7.5 For all other Object pairs, including Array objects, equivalence is
192
+ // For all other Object pairs, including Array objects, equivalence is
188
193
// determined by having the same number of owned properties (as verified
189
194
// with Object.prototype.hasOwnProperty.call), the same set of keys
190
195
// (although not necessarily the same order), equivalent values for every
@@ -214,7 +219,8 @@ function isArguments(object) {
214
219
function objEquiv ( a , b , strict , actualVisitedObjects ) {
215
220
if ( a === null || a === undefined || b === null || b === undefined )
216
221
return false ;
217
- // if one is a primitive, the other must be same
222
+
223
+ // If one is a primitive, the other must be the same.
218
224
if ( util . isPrimitive ( a ) || util . isPrimitive ( b ) )
219
225
return a === b ;
220
226
if ( strict && Object . getPrototypeOf ( a ) !== Object . getPrototypeOf ( b ) )
@@ -226,20 +232,23 @@ function objEquiv(a, b, strict, actualVisitedObjects) {
226
232
const ka = Object . keys ( a ) ;
227
233
const kb = Object . keys ( b ) ;
228
234
var key , i ;
229
- // having the same number of owned properties (keys incorporates
230
- // hasOwnProperty)
235
+
236
+ // The pair must have the same number of owned properties (keys
237
+ // incorporates hasOwnProperty).
231
238
if ( ka . length !== kb . length )
232
239
return false ;
233
- //the same set of keys (although not necessarily the same order),
240
+
241
+ // The pair must have the same set of keys (although not
242
+ // necessarily in the same order).
234
243
ka . sort ( ) ;
235
244
kb . sort ( ) ;
236
- //~~~cheap key test
245
+ // Cheap key test:
237
246
for ( i = ka . length - 1 ; i >= 0 ; i -- ) {
238
247
if ( ka [ i ] !== kb [ i ] )
239
248
return false ;
240
249
}
241
- //equivalent values for every corresponding key, and
242
- //~~~possibly expensive deep test
250
+ // The pair must have equivalent values for every corresponding key.
251
+ // Possibly expensive deep test:
243
252
for ( i = ka . length - 1 ; i >= 0 ; i -- ) {
244
253
key = ka [ i ] ;
245
254
if ( ! _deepEqual ( a [ key ] , b [ key ] , strict , actualVisitedObjects ) )
@@ -248,7 +257,7 @@ function objEquiv(a, b, strict, actualVisitedObjects) {
248
257
return true ;
249
258
}
250
259
251
- // 8. The non-equivalence assertion tests for any deep inequality.
260
+ // The non-equivalence assertion tests for any deep inequality.
252
261
// assert.notDeepEqual(actual, expected, message_opt);
253
262
254
263
assert . notDeepEqual = function notDeepEqual ( actual , expected , message ) {
@@ -265,7 +274,7 @@ function notDeepStrictEqual(actual, expected, message) {
265
274
}
266
275
267
276
268
- // 9. The strict equality assertion tests strict equality, as determined by ===.
277
+ // The strict equality assertion tests strict equality, as determined by ===.
269
278
// assert.strictEqual(actual, expected, message_opt);
270
279
271
280
assert . strictEqual = function strictEqual ( actual , expected , message ) {
@@ -274,8 +283,9 @@ assert.strictEqual = function strictEqual(actual, expected, message) {
274
283
}
275
284
} ;
276
285
277
- // 10. The strict non-equality assertion tests for strict inequality, as
278
- // determined by !==. assert.notStrictEqual(actual, expected, message_opt);
286
+ // The strict non-equality assertion tests for strict inequality, as
287
+ // determined by !==.
288
+ // assert.notStrictEqual(actual, expected, message_opt);
279
289
280
290
assert . notStrictEqual = function notStrictEqual ( actual , expected , message ) {
281
291
if ( actual === expected ) {
@@ -297,7 +307,7 @@ function expectedException(actual, expected) {
297
307
return true ;
298
308
}
299
309
} catch ( e ) {
300
- // Ignore. The instanceof check doesn't work for arrow functions.
310
+ // Ignore. The instanceof check doesn't work for arrow functions.
301
311
}
302
312
303
313
if ( Error . isPrototypeOf ( expected ) ) {
@@ -355,7 +365,7 @@ function _throws(shouldThrow, block, expected, message) {
355
365
}
356
366
}
357
367
358
- // 11. Expected to throw an error:
368
+ // Expected to throw an error.
359
369
// assert.throws(block, Error_opt, message_opt);
360
370
361
371
assert . throws = function ( block , /*optional*/ error , /*optional*/ message ) {
0 commit comments