From 948b99deabb017653616f284d042d4c0a241eaa9 Mon Sep 17 00:00:00 2001 From: Alexey Orlenko Date: Sat, 25 Mar 2017 19:39:12 +0200 Subject: [PATCH] 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 Reviewed-By: Anna Henningsen Reviewed-By: Luigi Pinca Reviewed-By: Colin Ihrig Reviewed-By: Yuta Hiroto Reviewed-By: Santiago Gimeno Reviewed-By: James M Snell --- test/parallel/test-buffer-includes.js | 22 ++++++++++------------ 1 file changed, 10 insertions(+), 12 deletions(-) diff --git a/test/parallel/test-buffer-includes.js b/test/parallel/test-buffer-includes.js index 9b0aef0ad7652d..2b65ce41889cdc 100644 --- a/test/parallel/test-buffer-includes.js +++ b/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('\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'); @@ -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')); } }