Browse Source

test: fix broken tests in test-buffer-includes

Some of the tests for `buffer.includes()` functionality introduced in
https://github.com/nodejs/node/pull/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: https://github.com/nodejs/node/pull/12040
Ref: https://github.com/nodejs/node/pull/3567
Reviewed-By: Rich Trott <rtrott@gmail.com>
Reviewed-By: Anna Henningsen <anna@addaleax.net>
Reviewed-By: Luigi Pinca <luigipinca@gmail.com>
Reviewed-By: Colin Ihrig <cjihrig@gmail.com>
Reviewed-By: Yuta Hiroto <hello@about-hiroppy.com>
Reviewed-By: Santiago Gimeno <santiago.gimeno@gmail.com>
Reviewed-By: James M Snell <jasnell@gmail.com>
v6.x
Alexey Orlenko 8 years ago
committed by Myles Borins
parent
commit
e2279e297a
No known key found for this signature in database GPG Key ID: 933B01F40B5CA946
  1. 22
      test/parallel/test-buffer-includes.js

22
test/parallel/test-buffer-includes.js

@ -155,14 +155,12 @@ assert(mixedByteStringUcs2.includes('bc', 0, 'ucs2'));
assert(mixedByteStringUcs2.includes('\u03a3', 0, 'ucs2')); assert(mixedByteStringUcs2.includes('\u03a3', 0, 'ucs2'));
assert(!mixedByteStringUcs2.includes('\u0396', 0, 'ucs2')); assert(!mixedByteStringUcs2.includes('\u0396', 0, 'ucs2'));
assert( assert.ok(
6, mixedByteStringUcs2.includes(Buffer.from('bc', 'ucs2'), 0, 'ucs2')); mixedByteStringUcs2.includes(Buffer.from('bc', 'ucs2'), 0, 'ucs2'));
assert( assert.ok(
10, mixedByteStringUcs2.includes(Buffer.from('\u03a3', 'ucs2'), mixedByteStringUcs2.includes(Buffer.from('\u03a3', 'ucs2'), 0, 'ucs2'));
0, 'ucs2')); assert.ok(
assert( !mixedByteStringUcs2.includes(Buffer.from('\u0396', 'ucs2'), 0, 'ucs2'));
-1, mixedByteStringUcs2.includes(Buffer.from('\u0396', 'ucs2'),
0, 'ucs2'));
twoByteString = Buffer.from('\u039a\u0391\u03a3\u03a3\u0395', 'ucs2'); twoByteString = Buffer.from('\u039a\u0391\u03a3\u03a3\u0395', 'ucs2');
@ -266,12 +264,12 @@ for (let lengthIndex = 0; lengthIndex < lengths.length; lengthIndex++) {
const patternBufferUcs2 = const patternBufferUcs2 =
allCharsBufferUcs2.slice(index, index + length); allCharsBufferUcs2.slice(index, index + length);
assert( assert.ok(
index, allCharsBufferUcs2.includes(patternBufferUcs2, 0, 'ucs2')); allCharsBufferUcs2.includes(patternBufferUcs2, 0, 'ucs2'));
const patternStringUcs2 = patternBufferUcs2.toString('ucs2'); const patternStringUcs2 = patternBufferUcs2.toString('ucs2');
assert( assert.ok(
index, allCharsBufferUcs2.includes(patternStringUcs2, 0, 'ucs2')); allCharsBufferUcs2.includes(patternStringUcs2, 0, 'ucs2'));
} }
} }

Loading…
Cancel
Save