Skip to content

Commit 948b99d

Browse files
aqrlnMylesBorins
authored andcommitted
test: fix broken tests in test-buffer-includes
Some of the tests for `buffer.includes()` functionality introduced in #3567 have been broken in a way that caused them to always pass regardless of the result of the tested method. This behavior was caused by two reasons: * These tests were written as though `buffer.includes()` was supposed to return the same value that `buffer.indexOf()` does, i.e., used indices or -1 as expected return values instead of true and false. * `assert()` was used as the assertion function to do that instead of `assert.strictEqual()`. Thus `assert()` was called with a non-zero number as the first argument effectively causing these tests to pass. This commit changes the tests to use `assert.ok()` and removes redundant indices. PR-URL: #12040 Ref: #3567 Reviewed-By: Rich Trott <[email protected]> Reviewed-By: Anna Henningsen <[email protected]> Reviewed-By: Luigi Pinca <[email protected]> Reviewed-By: Colin Ihrig <[email protected]> Reviewed-By: Yuta Hiroto <[email protected]> Reviewed-By: Santiago Gimeno <[email protected]> Reviewed-By: James M Snell <[email protected]>
1 parent 18a586a commit 948b99d

File tree

1 file changed

+10
-12
lines changed

1 file changed

+10
-12
lines changed

test/parallel/test-buffer-includes.js

+10-12
Original file line numberDiff line numberDiff line change
@@ -155,14 +155,12 @@ assert(mixedByteStringUcs2.includes('bc', 0, 'ucs2'));
155155
assert(mixedByteStringUcs2.includes('\u03a3', 0, 'ucs2'));
156156
assert(!mixedByteStringUcs2.includes('\u0396', 0, 'ucs2'));
157157

158-
assert(
159-
6, mixedByteStringUcs2.includes(Buffer.from('bc', 'ucs2'), 0, 'ucs2'));
160-
assert(
161-
10, mixedByteStringUcs2.includes(Buffer.from('\u03a3', 'ucs2'),
162-
0, 'ucs2'));
163-
assert(
164-
-1, mixedByteStringUcs2.includes(Buffer.from('\u0396', 'ucs2'),
165-
0, 'ucs2'));
158+
assert.ok(
159+
mixedByteStringUcs2.includes(Buffer.from('bc', 'ucs2'), 0, 'ucs2'));
160+
assert.ok(
161+
mixedByteStringUcs2.includes(Buffer.from('\u03a3', 'ucs2'), 0, 'ucs2'));
162+
assert.ok(
163+
!mixedByteStringUcs2.includes(Buffer.from('\u0396', 'ucs2'), 0, 'ucs2'));
166164

167165
twoByteString = Buffer.from('\u039a\u0391\u03a3\u03a3\u0395', 'ucs2');
168166

@@ -266,12 +264,12 @@ for (let lengthIndex = 0; lengthIndex < lengths.length; lengthIndex++) {
266264

267265
const patternBufferUcs2 =
268266
allCharsBufferUcs2.slice(index, index + length);
269-
assert(
270-
index, allCharsBufferUcs2.includes(patternBufferUcs2, 0, 'ucs2'));
267+
assert.ok(
268+
allCharsBufferUcs2.includes(patternBufferUcs2, 0, 'ucs2'));
271269

272270
const patternStringUcs2 = patternBufferUcs2.toString('ucs2');
273-
assert(
274-
index, allCharsBufferUcs2.includes(patternStringUcs2, 0, 'ucs2'));
271+
assert.ok(
272+
allCharsBufferUcs2.includes(patternStringUcs2, 0, 'ucs2'));
275273
}
276274
}
277275

0 commit comments

Comments
 (0)