Skip to content

Commit

Permalink
test: fix broken tests in test-buffer-includes
Browse files Browse the repository at this point in the history
Some of the tests for `buffer.includes()` functionality introduced in
nodejs/node#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: nodejs/node#12040
Ref: nodejs/node#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>
  • Loading branch information
aqrln authored and andrew749 committed Jul 19, 2017
1 parent 9c0d06d commit a004b3d
Showing 1 changed file with 10 additions and 12 deletions.
22 changes: 10 additions & 12 deletions test/parallel/test-buffer-includes.js
Original file line number Diff line number Diff line change
Expand Up @@ -155,14 +155,12 @@ assert(mixedByteStringUcs2.includes('bc', 0, 'ucs2'));
assert(mixedByteStringUcs2.includes('\u03a3', 0, 'ucs2'));
assert(!mixedByteStringUcs2.includes('\u0396', 0, 'ucs2'));

assert(
6, mixedByteStringUcs2.includes(Buffer.from('bc', 'ucs2'), 0, 'ucs2'));
assert(
10, mixedByteStringUcs2.includes(Buffer.from('\u03a3', 'ucs2'),
0, 'ucs2'));
assert(
-1, mixedByteStringUcs2.includes(Buffer.from('\u0396', 'ucs2'),
0, 'ucs2'));
assert.ok(
mixedByteStringUcs2.includes(Buffer.from('bc', 'ucs2'), 0, 'ucs2'));
assert.ok(
mixedByteStringUcs2.includes(Buffer.from('\u03a3', 'ucs2'), 0, 'ucs2'));
assert.ok(
!mixedByteStringUcs2.includes(Buffer.from('\u0396', 'ucs2'), 0, 'ucs2'));

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

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

const patternBufferUcs2 =
allCharsBufferUcs2.slice(index, index + length);
assert(
index, allCharsBufferUcs2.includes(patternBufferUcs2, 0, 'ucs2'));
assert.ok(
allCharsBufferUcs2.includes(patternBufferUcs2, 0, 'ucs2'));

const patternStringUcs2 = patternBufferUcs2.toString('ucs2');
assert(
index, allCharsBufferUcs2.includes(patternStringUcs2, 0, 'ucs2'));
assert.ok(
allCharsBufferUcs2.includes(patternStringUcs2, 0, 'ucs2'));
}
}

Expand Down

0 comments on commit a004b3d

Please sign in to comment.