fetch-dht/lib/binaryQuerystring/index.test.js

47 lines
1.2 KiB
JavaScript
Raw Normal View History

2020-04-12 21:33:32 +00:00
const assert = require('assert');
require('./index.js').__test(
({ spliceString, DBUC_REGEX, decodeComponent, parse, fromUrl }) => {
assert.strictEqual(
spliceString('abcdefg', 2, 3, 'HELLO'),
'abHELLOfg',
'splice string not working as intended (0)',
);
assert.strictEqual(
spliceString('abcd', 2, 0, 'HELLO'),
'abHELLOcd',
'splice string not working as intended (1)',
);
assert.strictEqual(
spliceString('abcd', 2, -2, 'HELLO'),
'abHELLO',
'splice string not working as intended (2)',
);
for (const [input, expected] of [
[
'%28m.%5BO%83i%85S%283j%C1%26%3A%E0%2Az%60%D5',
'(m.[O\u0083i\u0085S(3j\u00C1&\u003A\u00E0\u002Az`\u00D5',
],
[
'(m.%5bO%83i%85S(3j%c1%26%3a%e0*z%60%d5',
'(m.[O\u0083i\u0085S(3j\u00C1&\u003A\u00E0\u002Az`\u00D5',
],
]) {
const actual = decodeComponent(input);
assert.strictEqual(
actual,
expected,
`decodeComponent failed on input '${input}'`,
);
}
// expect other tests to validate deeper functionality
assert.deepEqual(
fromUrl('http://example.com/foo?bar=hi'),
{ bar: 'hi' },
`parseBinaryQuerystring failed`,
);
},
);