|
@ -1,6 +1,7 @@ |
|
|
'use strict'; |
|
|
'use strict'; |
|
|
require('../common'); |
|
|
require('../common'); |
|
|
const assert = require('assert'); |
|
|
const assert = require('assert'); |
|
|
|
|
|
const inspect = require('util').inspect; |
|
|
|
|
|
|
|
|
// test using assert
|
|
|
// test using assert
|
|
|
const qs = require('querystring'); |
|
|
const qs = require('querystring'); |
|
@ -126,28 +127,43 @@ assert.strictEqual('918854443121279438895193', |
|
|
qs.parse('id=918854443121279438895193').id); |
|
|
qs.parse('id=918854443121279438895193').id); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
function check(actual, expected) { |
|
|
function check(actual, expected, input) { |
|
|
assert(!(actual instanceof Object)); |
|
|
assert(!(actual instanceof Object)); |
|
|
assert.deepStrictEqual(Object.keys(actual).sort(), |
|
|
const actualKeys = Object.keys(actual).sort(); |
|
|
Object.keys(expected).sort()); |
|
|
const expectedKeys = Object.keys(expected).sort(); |
|
|
Object.keys(expected).forEach(function(key) { |
|
|
let msg; |
|
|
assert.deepStrictEqual(actual[key], expected[key]); |
|
|
if (typeof input === 'string') { |
|
|
|
|
|
msg = `Input: ${inspect(input)}\n` + |
|
|
|
|
|
`Actual keys: ${inspect(actualKeys)}\n` + |
|
|
|
|
|
`Expected keys: ${inspect(expectedKeys)}`; |
|
|
|
|
|
} |
|
|
|
|
|
assert.deepStrictEqual(actualKeys, expectedKeys, msg); |
|
|
|
|
|
expectedKeys.forEach(function(key) { |
|
|
|
|
|
if (typeof input === 'string') { |
|
|
|
|
|
msg = `Input: ${inspect(input)}\n` + |
|
|
|
|
|
`Key: ${inspect(key)}\n` + |
|
|
|
|
|
`Actual value: ${inspect(actual[key])}\n` + |
|
|
|
|
|
`Expected value: ${inspect(expected[key])}`; |
|
|
|
|
|
} else { |
|
|
|
|
|
msg = undefined; |
|
|
|
|
|
} |
|
|
|
|
|
assert.deepStrictEqual(actual[key], expected[key], msg); |
|
|
}); |
|
|
}); |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
// test that the canonical qs is parsed properly.
|
|
|
// test that the canonical qs is parsed properly.
|
|
|
qsTestCases.forEach(function(testCase) { |
|
|
qsTestCases.forEach(function(testCase) { |
|
|
check(qs.parse(testCase[0]), testCase[2]); |
|
|
check(qs.parse(testCase[0]), testCase[2], testCase[0]); |
|
|
}); |
|
|
}); |
|
|
|
|
|
|
|
|
// test that the colon test cases can do the same
|
|
|
// test that the colon test cases can do the same
|
|
|
qsColonTestCases.forEach(function(testCase) { |
|
|
qsColonTestCases.forEach(function(testCase) { |
|
|
check(qs.parse(testCase[0], ';', ':'), testCase[2]); |
|
|
check(qs.parse(testCase[0], ';', ':'), testCase[2], testCase[0]); |
|
|
}); |
|
|
}); |
|
|
|
|
|
|
|
|
// test the weird objects, that they get parsed properly
|
|
|
// test the weird objects, that they get parsed properly
|
|
|
qsWeirdObjects.forEach(function(testCase) { |
|
|
qsWeirdObjects.forEach(function(testCase) { |
|
|
check(qs.parse(testCase[1]), testCase[2]); |
|
|
check(qs.parse(testCase[1]), testCase[2], testCase[1]); |
|
|
}); |
|
|
}); |
|
|
|
|
|
|
|
|
qsNoMungeTestCases.forEach(function(testCase) { |
|
|
qsNoMungeTestCases.forEach(function(testCase) { |
|
|