|
1 | 1 | 'use strict';
|
2 | 2 | require('../common');
|
3 | 3 | const assert = require('assert');
|
| 4 | +const inspect = require('util').inspect; |
4 | 5 |
|
5 | 6 | // test using assert
|
6 | 7 | const qs = require('querystring');
|
@@ -126,28 +127,43 @@ assert.strictEqual('918854443121279438895193',
|
126 | 127 | qs.parse('id=918854443121279438895193').id);
|
127 | 128 |
|
128 | 129 |
|
129 |
| -function check(actual, expected) { |
| 130 | +function check(actual, expected, input) { |
130 | 131 | assert(!(actual instanceof Object));
|
131 |
| - assert.deepStrictEqual(Object.keys(actual).sort(), |
132 |
| - Object.keys(expected).sort()); |
133 |
| - Object.keys(expected).forEach(function(key) { |
134 |
| - assert.deepStrictEqual(actual[key], expected[key]); |
| 132 | + const actualKeys = Object.keys(actual).sort(); |
| 133 | + const expectedKeys = Object.keys(expected).sort(); |
| 134 | + let msg; |
| 135 | + if (typeof input === 'string') { |
| 136 | + msg = `Input: ${inspect(input)}\n` + |
| 137 | + `Actual keys: ${inspect(actualKeys)}\n` + |
| 138 | + `Expected keys: ${inspect(expectedKeys)}`; |
| 139 | + } |
| 140 | + assert.deepStrictEqual(actualKeys, expectedKeys, msg); |
| 141 | + expectedKeys.forEach(function(key) { |
| 142 | + if (typeof input === 'string') { |
| 143 | + msg = `Input: ${inspect(input)}\n` + |
| 144 | + `Key: ${inspect(key)}\n` + |
| 145 | + `Actual value: ${inspect(actual[key])}\n` + |
| 146 | + `Expected value: ${inspect(expected[key])}`; |
| 147 | + } else { |
| 148 | + msg = undefined; |
| 149 | + } |
| 150 | + assert.deepStrictEqual(actual[key], expected[key], msg); |
135 | 151 | });
|
136 | 152 | }
|
137 | 153 |
|
138 | 154 | // test that the canonical qs is parsed properly.
|
139 | 155 | qsTestCases.forEach(function(testCase) {
|
140 |
| - check(qs.parse(testCase[0]), testCase[2]); |
| 156 | + check(qs.parse(testCase[0]), testCase[2], testCase[0]); |
141 | 157 | });
|
142 | 158 |
|
143 | 159 | // test that the colon test cases can do the same
|
144 | 160 | qsColonTestCases.forEach(function(testCase) {
|
145 |
| - check(qs.parse(testCase[0], ';', ':'), testCase[2]); |
| 161 | + check(qs.parse(testCase[0], ';', ':'), testCase[2], testCase[0]); |
146 | 162 | });
|
147 | 163 |
|
148 | 164 | // test the weird objects, that they get parsed properly
|
149 | 165 | qsWeirdObjects.forEach(function(testCase) {
|
150 |
| - check(qs.parse(testCase[1]), testCase[2]); |
| 166 | + check(qs.parse(testCase[1]), testCase[2], testCase[1]); |
151 | 167 | });
|
152 | 168 |
|
153 | 169 | qsNoMungeTestCases.forEach(function(testCase) {
|
|
0 commit comments