diff options
author | Joyee Cheung <joyeec9h3@gmail.com> | 2017-01-28 17:23:47 +0800 |
---|---|---|
committer | James M Snell <jasnell@gmail.com> | 2017-01-30 10:19:37 -0800 |
commit | 147d2a6419cb1e1dae5f9c2abf04cc21c52e0e0e (patch) | |
tree | 8b7c671aca9f23639a911f2f39976a8464136c4c /test/parallel/test-url-parse-query.js | |
parent | 49e5f61ef6b0d2800db19b0ca758ec04e457bf45 (diff) | |
download | android-node-v8-147d2a6419cb1e1dae5f9c2abf04cc21c52e0e0e.tar.gz android-node-v8-147d2a6419cb1e1dae5f9c2abf04cc21c52e0e0e.tar.bz2 android-node-v8-147d2a6419cb1e1dae5f9c2abf04cc21c52e0e0e.zip |
url, test: break up test-url.js
PR-URL: https://github.com/nodejs/node/pull/11049
Reviewed-By: Anna Henningsen <anna@addaleax.net>
Reviewed-By: James M Snell <jasnell@gmail.com>
Reviewed-By: Colin Ihrig <cjihrig@gmail.com>
Diffstat (limited to 'test/parallel/test-url-parse-query.js')
-rw-r--r-- | test/parallel/test-url-parse-query.js | 90 |
1 files changed, 90 insertions, 0 deletions
diff --git a/test/parallel/test-url-parse-query.js b/test/parallel/test-url-parse-query.js new file mode 100644 index 0000000000..34c31d8a3c --- /dev/null +++ b/test/parallel/test-url-parse-query.js @@ -0,0 +1,90 @@ +'use strict'; +require('../common'); +const assert = require('assert'); +const url = require('url'); + +function createWithNoPrototype(properties = []) { + const noProto = Object.create(null); + properties.forEach((property) => { + noProto[property.key] = property.value; + }); + return noProto; +} + +function check(actual, expected) { + assert.notStrictEqual(Object.getPrototypeOf(actual), Object.prototype); + assert.deepStrictEqual(Object.keys(actual).sort(), + Object.keys(expected).sort()); + Object.keys(expected).forEach(function(key) { + assert.deepStrictEqual(actual[key], expected[key]); + }); +} + +const parseTestsWithQueryString = { + '/foo/bar?baz=quux#frag': { + href: '/foo/bar?baz=quux#frag', + hash: '#frag', + search: '?baz=quux', + query: createWithNoPrototype([{key: 'baz', value: 'quux'}]), + pathname: '/foo/bar', + path: '/foo/bar?baz=quux' + }, + 'http://example.com': { + href: 'http://example.com/', + protocol: 'http:', + slashes: true, + host: 'example.com', + hostname: 'example.com', + query: createWithNoPrototype(), + search: '', + pathname: '/', + path: '/' + }, + '/example': { + protocol: null, + slashes: null, + auth: undefined, + host: null, + port: null, + hostname: null, + hash: null, + search: '', + query: createWithNoPrototype(), + pathname: '/example', + path: '/example', + href: '/example' + }, + '/example?query=value': { + protocol: null, + slashes: null, + auth: undefined, + host: null, + port: null, + hostname: null, + hash: null, + search: '?query=value', + query: createWithNoPrototype([{ key: 'query', value: 'value' }]), + pathname: '/example', + path: '/example?query=value', + href: '/example?query=value' + } +}; +for (const u in parseTestsWithQueryString) { + const actual = url.parse(u, true); + const expected = Object.assign(new url.Url(), parseTestsWithQueryString[u]); + for (const i in actual) { + if (actual[i] === null && expected[i] === undefined) { + expected[i] = null; + } + } + + const properties = Object.keys(actual).sort(); + assert.deepStrictEqual(properties, Object.keys(expected).sort()); + properties.forEach((property) => { + if (property === 'query') { + check(actual[property], expected[property]); + } else { + assert.deepStrictEqual(actual[property], expected[property]); + } + }); +} |