From f5b4849208a7b0ced9333a77837658f684b07d0a Mon Sep 17 00:00:00 2001 From: Daijiro Wachi Date: Thu, 16 Feb 2017 14:03:23 +0100 Subject: [PATCH] test: test bottom-up merge sort in URLSearchParams MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit The bottom-up iterative stable merge sort is called only when the length of provided value is larger than 100. Added a test for it. PR-URL: https://github.com/nodejs/node/pull/11399 Reviewed-By: James M Snell Reviewed-By: Joyee Cheung Reviewed-By: Timothy Gu Reviewed-By: Michaƫl Zasso --- .../test-whatwg-url-searchparams-sort.js | 17 +++++++++++++++-- 1 file changed, 15 insertions(+), 2 deletions(-) diff --git a/test/parallel/test-whatwg-url-searchparams-sort.js b/test/parallel/test-whatwg-url-searchparams-sort.js index 0fcc01335aed57..5bddc14d947d8f 100644 --- a/test/parallel/test-whatwg-url-searchparams-sort.js +++ b/test/parallel/test-whatwg-url-searchparams-sort.js @@ -55,12 +55,25 @@ const { test, assert_array_equals } = common.WPT; /* eslint-enable */ // Tests below are not from WPT. -;[ + +// Test bottom-up iterative stable merge sort +const tests = [{input: '', output: []}]; +const pairs = []; +for (let i = 10; i < 100; i++) { + pairs.push([`a${i}`, 'b']); + tests[0].output.push([`a${i}`, 'b']); +} +tests[0].input = pairs.sort(() => Math.random() > 0.5) + .map((pair) => pair.join('=')).join('&'); + +tests.push( { 'input': 'z=a&=b&c=d', 'output': [['', 'b'], ['c', 'd'], ['z', 'a']] } -].forEach((val) => { +); + +tests.forEach((val) => { test(() => { const params = new URLSearchParams(val.input); let i = 0;