CoolFace
Datasetpublic

basant307/AI_Governance_Project

sourceHugging Faceapache-2.0updated 2mo agoView on Hugging Face
0likes48downloads
uri-js.test.js913 linesDownload Raw Back to test
1'use strict'2 3const test = require('tape')4const fastURI = require('..')5 6/**7 * URI.js8 *9 * @fileoverview An RFC 3986 compliant, scheme extendable URI parsing/normalizing/resolving/serializing library for JavaScript.10 * @author <a href="mailto:gary.court@gmail.com">Gary Court</a>11 * @see http://github.com/garycourt/uri-js12 */13 14/**15 * Copyright 2011 Gary Court. All rights reserved.16 *17 * Redistribution and use in source and binary forms, with or without modification, are18 * permitted provided that the following conditions are met:19 *20 *    1. Redistributions of source code must retain the above copyright notice, this list of21 *       conditions and the following disclaimer.22 *23 *    2. Redistributions in binary form must reproduce the above copyright notice, this list24 *       of conditions and the following disclaimer in the documentation and/or other materials25 *       provided with the distribution.26 *27 * THIS SOFTWARE IS PROVIDED BY GARY COURT ``AS IS'' AND ANY EXPRESS OR IMPLIED28 * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND29 * FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL GARY COURT OR30 * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR31 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR32 * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON33 * ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING34 * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF35 * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.36 *37 * The views and conclusions contained in the software and documentation are those of the38 * authors and should not be interpreted as representing official policies, either expressed39 * or implied, of Gary Court.40 */41 42test('Acquire URI', (t) => {43  t.ok(fastURI)44  t.end()45})46 47test('URI Parsing', (t) => {48  let components49 50  // scheme51  components = fastURI.parse('uri:')52  t.equal(components.error, undefined, 'scheme errors')53  t.equal(components.scheme, 'uri', 'scheme')54  t.equal(components.userinfo, undefined, 'userinfo')55  t.equal(components.host, undefined, 'host')56  t.equal(components.port, undefined, 'port')57  t.equal(components.path, '', 'path')58  t.equal(components.query, undefined, 'query')59  t.equal(components.fragment, undefined, 'fragment')60 61  // userinfo62  components = fastURI.parse('//@')63  t.equal(components.error, undefined, 'userinfo errors')64  t.equal(components.scheme, undefined, 'scheme')65  t.equal(components.userinfo, '', 'userinfo')66  t.equal(components.host, '', 'host')67  t.equal(components.port, undefined, 'port')68  t.equal(components.path, '', 'path')69  t.equal(components.query, undefined, 'query')70  t.equal(components.fragment, undefined, 'fragment')71 72  // host73  components = fastURI.parse('//')74  t.equal(components.error, undefined, 'host errors')75  t.equal(components.scheme, undefined, 'scheme')76  t.equal(components.userinfo, undefined, 'userinfo')77  t.equal(components.host, '', 'host')78  t.equal(components.port, undefined, 'port')79  t.equal(components.path, '', 'path')80  t.equal(components.query, undefined, 'query')81  t.equal(components.fragment, undefined, 'fragment')82 83  // port84  components = fastURI.parse('//:')85  t.equal(components.error, undefined, 'port errors')86  t.equal(components.scheme, undefined, 'scheme')87  t.equal(components.userinfo, undefined, 'userinfo')88  t.equal(components.host, '', 'host')89  t.equal(components.port, '', 'port')90  t.equal(components.path, '', 'path')91  t.equal(components.query, undefined, 'query')92  t.equal(components.fragment, undefined, 'fragment')93 94  // path95  components = fastURI.parse('')96  t.equal(components.error, undefined, 'path errors')97  t.equal(components.scheme, undefined, 'scheme')98  t.equal(components.userinfo, undefined, 'userinfo')99  t.equal(components.host, undefined, 'host')100  t.equal(components.port, undefined, 'port')101  t.equal(components.path, '', 'path')102  t.equal(components.query, undefined, 'query')103  t.equal(components.fragment, undefined, 'fragment')104 105  // query106  components = fastURI.parse('?')107  t.equal(components.error, undefined, 'query errors')108  t.equal(components.scheme, undefined, 'scheme')109  t.equal(components.userinfo, undefined, 'userinfo')110  t.equal(components.host, undefined, 'host')111  t.equal(components.port, undefined, 'port')112  t.equal(components.path, '', 'path')113  t.equal(components.query, '', 'query')114  t.equal(components.fragment, undefined, 'fragment')115 116  // fragment117  components = fastURI.parse('#')118  t.equal(components.error, undefined, 'fragment errors')119  t.equal(components.scheme, undefined, 'scheme')120  t.equal(components.userinfo, undefined, 'userinfo')121  t.equal(components.host, undefined, 'host')122  t.equal(components.port, undefined, 'port')123  t.equal(components.path, '', 'path')124  t.equal(components.query, undefined, 'query')125  t.equal(components.fragment, '', 'fragment')126 127  // fragment with character tabulation128  components = fastURI.parse('#\t')129  t.equal(components.error, undefined, 'path errors')130  t.equal(components.scheme, undefined, 'scheme')131  t.equal(components.userinfo, undefined, 'userinfo')132  t.equal(components.host, undefined, 'host')133  t.equal(components.port, undefined, 'port')134  t.equal(components.path, '', 'path')135  t.equal(components.query, undefined, 'query')136  t.equal(components.fragment, '%09', 'fragment')137 138  // fragment with line feed139  components = fastURI.parse('#\n')140  t.equal(components.error, undefined, 'path errors')141  t.equal(components.scheme, undefined, 'scheme')142  t.equal(components.userinfo, undefined, 'userinfo')143  t.equal(components.host, undefined, 'host')144  t.equal(components.port, undefined, 'port')145  t.equal(components.path, '', 'path')146  t.equal(components.query, undefined, 'query')147  t.equal(components.fragment, '%0A', 'fragment')148 149  // fragment with line tabulation150  components = fastURI.parse('#\v')151  t.equal(components.error, undefined, 'path errors')152  t.equal(components.scheme, undefined, 'scheme')153  t.equal(components.userinfo, undefined, 'userinfo')154  t.equal(components.host, undefined, 'host')155  t.equal(components.port, undefined, 'port')156  t.equal(components.path, '', 'path')157  t.equal(components.query, undefined, 'query')158  t.equal(components.fragment, '%0B', 'fragment')159 160  // fragment with form feed161  components = fastURI.parse('#\f')162  t.equal(components.error, undefined, 'path errors')163  t.equal(components.scheme, undefined, 'scheme')164  t.equal(components.userinfo, undefined, 'userinfo')165  t.equal(components.host, undefined, 'host')166  t.equal(components.port, undefined, 'port')167  t.equal(components.path, '', 'path')168  t.equal(components.query, undefined, 'query')169  t.equal(components.fragment, '%0C', 'fragment')170 171  // fragment with carriage return172  components = fastURI.parse('#\r')173  t.equal(components.error, undefined, 'path errors')174  t.equal(components.scheme, undefined, 'scheme')175  t.equal(components.userinfo, undefined, 'userinfo')176  t.equal(components.host, undefined, 'host')177  t.equal(components.port, undefined, 'port')178  t.equal(components.path, '', 'path')179  t.equal(components.query, undefined, 'query')180  t.equal(components.fragment, '%0D', 'fragment')181 182  // all183  components = fastURI.parse('uri://user:pass@example.com:123/one/two.three?q1=a1&q2=a2#body')184  t.equal(components.error, undefined, 'all errors')185  t.equal(components.scheme, 'uri', 'scheme')186  t.equal(components.userinfo, 'user:pass', 'userinfo')187  t.equal(components.host, 'example.com', 'host')188  t.equal(components.port, 123, 'port')189  t.equal(components.path, '/one/two.three', 'path')190  t.equal(components.query, 'q1=a1&q2=a2', 'query')191  t.equal(components.fragment, 'body', 'fragment')192 193  // IPv4address194  components = fastURI.parse('//10.10.10.10')195  t.equal(components.error, undefined, 'IPv4address errors')196  t.equal(components.scheme, undefined, 'scheme')197  t.equal(components.userinfo, undefined, 'userinfo')198  t.equal(components.host, '10.10.10.10', 'host')199  t.equal(components.port, undefined, 'port')200  t.equal(components.path, '', 'path')201  t.equal(components.query, undefined, 'query')202  t.equal(components.fragment, undefined, 'fragment')203 204  // IPv6address205  components = fastURI.parse('//[2001:db8::7]')206  t.equal(components.error, undefined, 'IPv4address errors')207  t.equal(components.scheme, undefined, 'scheme')208  t.equal(components.userinfo, undefined, 'userinfo')209  t.equal(components.host, '2001:db8::7', 'host')210  t.equal(components.port, undefined, 'port')211  t.equal(components.path, '', 'path')212  t.equal(components.query, undefined, 'query')213  t.equal(components.fragment, undefined, 'fragment')214 215  // mixed IPv4address & IPv6address216  components = fastURI.parse('//[::ffff:129.144.52.38]')217  t.equal(components.error, undefined, 'IPv4address errors')218  t.equal(components.scheme, undefined, 'scheme')219  t.equal(components.userinfo, undefined, 'userinfo')220  t.equal(components.host, '::ffff:129.144.52.38', 'host')221  t.equal(components.port, undefined, 'port')222  t.equal(components.path, '', 'path')223  t.equal(components.query, undefined, 'query')224  t.equal(components.fragment, undefined, 'fragment')225 226  // mixed IPv4address & reg-name, example from terion-name (https://github.com/garycourt/uri-js/issues/4)227  components = fastURI.parse('uri://10.10.10.10.example.com/en/process')228  t.equal(components.error, undefined, 'mixed errors')229  t.equal(components.scheme, 'uri', 'scheme')230  t.equal(components.userinfo, undefined, 'userinfo')231  t.equal(components.host, '10.10.10.10.example.com', 'host')232  t.equal(components.port, undefined, 'port')233  t.equal(components.path, '/en/process', 'path')234  t.equal(components.query, undefined, 'query')235  t.equal(components.fragment, undefined, 'fragment')236 237  // IPv6address, example from bkw (https://github.com/garycourt/uri-js/pull/16)238  components = fastURI.parse('//[2606:2800:220:1:248:1893:25c8:1946]/test')239  t.equal(components.error, undefined, 'IPv6address errors')240  t.equal(components.scheme, undefined, 'scheme')241  t.equal(components.userinfo, undefined, 'userinfo')242  t.equal(components.host, '2606:2800:220:1:248:1893:25c8:1946', 'host')243  t.equal(components.port, undefined, 'port')244  t.equal(components.path, '/test', 'path')245  t.equal(components.query, undefined, 'query')246  t.equal(components.fragment, undefined, 'fragment')247 248  // IPv6address, example from RFC 5952249  components = fastURI.parse('//[2001:db8::1]:80')250  t.equal(components.error, undefined, 'IPv6address errors')251  t.equal(components.scheme, undefined, 'scheme')252  t.equal(components.userinfo, undefined, 'userinfo')253  t.equal(components.host, '2001:db8::1', 'host')254  t.equal(components.port, 80, 'port')255  t.equal(components.path, '', 'path')256  t.equal(components.query, undefined, 'query')257  t.equal(components.fragment, undefined, 'fragment')258 259  // IPv6address with zone identifier, RFC 6874260  components = fastURI.parse('//[fe80::a%25en1]')261  t.equal(components.error, undefined, 'IPv4address errors')262  t.equal(components.scheme, undefined, 'scheme')263  t.equal(components.userinfo, undefined, 'userinfo')264  t.equal(components.host, 'fe80::a%en1', 'host')265  t.equal(components.port, undefined, 'port')266  t.equal(components.path, '', 'path')267  t.equal(components.query, undefined, 'query')268  t.equal(components.fragment, undefined, 'fragment')269 270  // IPv6address with an unescaped interface specifier, example from pekkanikander (https://github.com/garycourt/uri-js/pull/22)271  components = fastURI.parse('//[2001:db8::7%en0]')272  t.equal(components.error, undefined, 'IPv6address interface errors')273  t.equal(components.scheme, undefined, 'scheme')274  t.equal(components.userinfo, undefined, 'userinfo')275  t.equal(components.host, '2001:db8::7%en0', 'host')276  t.equal(components.port, undefined, 'port')277  t.equal(components.path, '', 'path')278  t.equal(components.query, undefined, 'query')279  t.equal(components.fragment, undefined, 'fragment')280 281  t.end()282})283 284test('URI Serialization', (t) => {285  let components = {286    scheme: undefined,287    userinfo: undefined,288    host: undefined,289    port: undefined,290    path: undefined,291    query: undefined,292    fragment: undefined293  }294  t.equal(fastURI.serialize(components), '', 'Undefined Components')295 296  components = {297    scheme: '',298    userinfo: '',299    host: '',300    port: 0,301    path: '',302    query: '',303    fragment: ''304  }305  t.equal(fastURI.serialize(components), '//@:0?#', 'Empty Components')306 307  components = {308    scheme: 'uri',309    userinfo: 'foo:bar',310    host: 'example.com',311    port: 1,312    path: 'path',313    query: 'query',314    fragment: 'fragment'315  }316  t.equal(fastURI.serialize(components), 'uri://foo:bar@example.com:1/path?query#fragment', 'All Components')317 318  components = {319    scheme: 'uri',320    host: 'example.com',321    port: '9000'322  }323  t.equal(fastURI.serialize(components), 'uri://example.com:9000', 'String port')324 325  t.equal(fastURI.serialize({ path: '//path' }), '/%2Fpath', 'Double slash path')326  t.equal(fastURI.serialize({ path: 'foo:bar' }), 'foo%3Abar', 'Colon path')327  t.equal(fastURI.serialize({ path: '?query' }), '%3Fquery', 'Query path')328 329  // mixed IPv4address & reg-name, example from terion-name (https://github.com/garycourt/uri-js/issues/4)330  t.equal(fastURI.serialize({ host: '10.10.10.10.example.com' }), '//10.10.10.10.example.com', 'Mixed IPv4address & reg-name')331 332  // IPv6address333  t.equal(fastURI.serialize({ host: '2001:db8::7' }), '//[2001:db8::7]', 'IPv6 Host')334  t.equal(fastURI.serialize({ host: '::ffff:129.144.52.38' }), '//[::ffff:129.144.52.38]', 'IPv6 Mixed Host')335  t.equal(fastURI.serialize({ host: '2606:2800:220:1:248:1893:25c8:1946' }), '//[2606:2800:220:1:248:1893:25c8:1946]', 'IPv6 Full Host')336 337  // IPv6address with zone identifier, RFC 6874338  t.equal(fastURI.serialize({ host: 'fe80::a%en1' }), '//[fe80::a%25en1]', 'IPv6 Zone Unescaped Host')339  t.equal(fastURI.serialize({ host: 'fe80::a%25en1' }), '//[fe80::a%25en1]', 'IPv6 Zone Escaped Host')340 341  t.end()342})343 344test('URI Resolving', { skip: true }, (t) => {345  // normal examples from RFC 3986346  const base = 'uri://a/b/c/d;p?q'347  t.equal(fastURI.resolve(base, 'g:h'), 'g:h', 'g:h')348  t.equal(fastURI.resolve(base, 'g'), 'uri://a/b/c/g', 'g')349  t.equal(fastURI.resolve(base, './g'), 'uri://a/b/c/g', './g')350  t.equal(fastURI.resolve(base, 'g/'), 'uri://a/b/c/g/', 'g/')351  t.equal(fastURI.resolve(base, '/g'), 'uri://a/g', '/g')352  t.equal(fastURI.resolve(base, '//g'), 'uri://g', '//g')353  t.equal(fastURI.resolve(base, '?y'), 'uri://a/b/c/d;p?y', '?y')354  t.equal(fastURI.resolve(base, 'g?y'), 'uri://a/b/c/g?y', 'g?y')355  t.equal(fastURI.resolve(base, '#s'), 'uri://a/b/c/d;p?q#s', '#s')356  t.equal(fastURI.resolve(base, 'g#s'), 'uri://a/b/c/g#s', 'g#s')357  t.equal(fastURI.resolve(base, 'g?y#s'), 'uri://a/b/c/g?y#s', 'g?y#s')358  t.equal(fastURI.resolve(base, ';x'), 'uri://a/b/c/;x', ';x')359  t.equal(fastURI.resolve(base, 'g;x'), 'uri://a/b/c/g;x', 'g;x')360  t.equal(fastURI.resolve(base, 'g;x?y#s'), 'uri://a/b/c/g;x?y#s', 'g;x?y#s')361  t.equal(fastURI.resolve(base, ''), 'uri://a/b/c/d;p?q', '')362  t.equal(fastURI.resolve(base, '.'), 'uri://a/b/c/', '.')363  t.equal(fastURI.resolve(base, './'), 'uri://a/b/c/', './')364  t.equal(fastURI.resolve(base, '..'), 'uri://a/b/', '..')365  t.equal(fastURI.resolve(base, '../'), 'uri://a/b/', '../')366  t.equal(fastURI.resolve(base, '../g'), 'uri://a/b/g', '../g')367  t.equal(fastURI.resolve(base, '../..'), 'uri://a/', '../..')368  t.equal(fastURI.resolve(base, '../../'), 'uri://a/', '../../')369  t.equal(fastURI.resolve(base, '../../g'), 'uri://a/g', '../../g')370 371  // abnormal examples from RFC 3986372  t.equal(fastURI.resolve(base, '../../../g'), 'uri://a/g', '../../../g')373  t.equal(fastURI.resolve(base, '../../../../g'), 'uri://a/g', '../../../../g')374 375  t.equal(fastURI.resolve(base, '/./g'), 'uri://a/g', '/./g')376  t.equal(fastURI.resolve(base, '/../g'), 'uri://a/g', '/../g')377  t.equal(fastURI.resolve(base, 'g.'), 'uri://a/b/c/g.', 'g.')378  t.equal(fastURI.resolve(base, '.g'), 'uri://a/b/c/.g', '.g')379  t.equal(fastURI.resolve(base, 'g..'), 'uri://a/b/c/g..', 'g..')380  t.equal(fastURI.resolve(base, '..g'), 'uri://a/b/c/..g', '..g')381 382  t.equal(fastURI.resolve(base, './../g'), 'uri://a/b/g', './../g')383  t.equal(fastURI.resolve(base, './g/.'), 'uri://a/b/c/g/', './g/.')384  t.equal(fastURI.resolve(base, 'g/./h'), 'uri://a/b/c/g/h', 'g/./h')385  t.equal(fastURI.resolve(base, 'g/../h'), 'uri://a/b/c/h', 'g/../h')386  t.equal(fastURI.resolve(base, 'g;x=1/./y'), 'uri://a/b/c/g;x=1/y', 'g;x=1/./y')387  t.equal(fastURI.resolve(base, 'g;x=1/../y'), 'uri://a/b/c/y', 'g;x=1/../y')388 389  t.equal(fastURI.resolve(base, 'g?y/./x'), 'uri://a/b/c/g?y/./x', 'g?y/./x')390  t.equal(fastURI.resolve(base, 'g?y/../x'), 'uri://a/b/c/g?y/../x', 'g?y/../x')391  t.equal(fastURI.resolve(base, 'g#s/./x'), 'uri://a/b/c/g#s/./x', 'g#s/./x')392  t.equal(fastURI.resolve(base, 'g#s/../x'), 'uri://a/b/c/g#s/../x', 'g#s/../x')393 394  t.equal(fastURI.resolve(base, 'uri:g'), 'uri:g', 'uri:g')395  t.equal(fastURI.resolve(base, 'uri:g', { tolerant: true }), 'uri://a/b/c/g', 'uri:g')396 397  // examples by PAEz398  t.equal(fastURI.resolve('//www.g.com/', '/adf\ngf'), '//www.g.com/adf%0Agf', '/adf\\ngf')399  t.equal(fastURI.resolve('//www.g.com/error\n/bleh/bleh', '..'), '//www.g.com/error%0A/', '//www.g.com/error\\n/bleh/bleh')400 401  t.end()402})403 404test('URI Normalizing', { skip: true }, (t) => {405  // test from RFC 3987406  t.equal(fastURI.normalize('uri://www.example.org/red%09ros\xE9#red'), 'uri://www.example.org/red%09ros%C3%A9#red')407 408  // IPv4address409  t.equal(fastURI.normalize('//192.068.001.000'), '//192.68.1.0')410 411  // IPv6address, example from RFC 3513412  t.equal(fastURI.normalize('http://[1080::8:800:200C:417A]/'), 'http://[1080::8:800:200c:417a]/')413 414  // IPv6address, examples from RFC 5952415  t.equal(fastURI.normalize('//[2001:0db8::0001]/'), '//[2001:db8::1]/')416  t.equal(fastURI.normalize('//[2001:db8::1:0000:1]/'), '//[2001:db8::1:0:1]/')417  t.equal(fastURI.normalize('//[2001:db8:0:0:0:0:2:1]/'), '//[2001:db8::2:1]/')418  t.equal(fastURI.normalize('//[2001:db8:0:1:1:1:1:1]/'), '//[2001:db8:0:1:1:1:1:1]/')419  t.equal(fastURI.normalize('//[2001:0:0:1:0:0:0:1]/'), '//[2001:0:0:1::1]/')420  t.equal(fastURI.normalize('//[2001:db8:0:0:1:0:0:1]/'), '//[2001:db8::1:0:0:1]/')421  t.equal(fastURI.normalize('//[2001:DB8::1]/'), '//[2001:db8::1]/')422  t.equal(fastURI.normalize('//[0:0:0:0:0:ffff:192.0.2.1]/'), '//[::ffff:192.0.2.1]/')423 424  // Mixed IPv4 and IPv6 address425  t.equal(fastURI.normalize('//[1:2:3:4:5:6:192.0.2.1]/'), '//[1:2:3:4:5:6:192.0.2.1]/')426  t.equal(fastURI.normalize('//[1:2:3:4:5:6:192.068.001.000]/'), '//[1:2:3:4:5:6:192.68.1.0]/')427 428  t.end()429})430 431test('URI Equals', (t) => {432  // test from RFC 3986433  t.equal(fastURI.equal('example://a/b/c/%7Bfoo%7D', 'eXAMPLE://a/./b/../b/%63/%7bfoo%7d'), true)434 435  // test from RFC 3987436  t.equal(fastURI.equal('http://example.org/~user', 'http://example.org/%7euser'), true)437 438  t.end()439})440 441test('Escape Component', { skip: true }, (t) => {442  let chr443  for (let d = 0; d <= 129; ++d) {444    chr = String.fromCharCode(d)445    if (!chr.match(/[$&+,;=]/)) {446      t.equal(fastURI.escapeComponent(chr), encodeURIComponent(chr))447    } else {448      t.equal(fastURI.escapeComponent(chr), chr)449    }450  }451  t.equal(fastURI.escapeComponent('\u00c0'), encodeURIComponent('\u00c0'))452  t.equal(fastURI.escapeComponent('\u07ff'), encodeURIComponent('\u07ff'))453  t.equal(fastURI.escapeComponent('\u0800'), encodeURIComponent('\u0800'))454  t.equal(fastURI.escapeComponent('\u30a2'), encodeURIComponent('\u30a2'))455  t.end()456})457 458test('Unescape Component', { skip: true }, (t) => {459  let chr460  for (let d = 0; d <= 129; ++d) {461    chr = String.fromCharCode(d)462    t.equal(fastURI.unescapeComponent(encodeURIComponent(chr)), chr)463  }464  t.equal(fastURI.unescapeComponent(encodeURIComponent('\u00c0')), '\u00c0')465  t.equal(fastURI.unescapeComponent(encodeURIComponent('\u07ff')), '\u07ff')466  t.equal(fastURI.unescapeComponent(encodeURIComponent('\u0800')), '\u0800')467  t.equal(fastURI.unescapeComponent(encodeURIComponent('\u30a2')), '\u30a2')468  t.end()469})470 471const IRI_OPTION = { iri: true, unicodeSupport: true }472 473test('IRI Parsing', { skip: true }, (t) => {474  const components = fastURI.parse('uri://us\xA0er:pa\uD7FFss@example.com:123/o\uF900ne/t\uFDCFwo.t\uFDF0hree?q1=a1\uF8FF\uE000&q2=a2#bo\uFFEFdy', IRI_OPTION)475  t.equal(components.error, undefined, 'all errors')476  t.equal(components.scheme, 'uri', 'scheme')477  t.equal(components.userinfo, 'us\xA0er:pa\uD7FFss', 'userinfo')478  t.equal(components.host, 'example.com', 'host')479  t.equal(components.port, 123, 'port')480  t.equal(components.path, '/o\uF900ne/t\uFDCFwo.t\uFDF0hree', 'path')481  t.equal(components.query, 'q1=a1\uF8FF\uE000&q2=a2', 'query')482  t.equal(components.fragment, 'bo\uFFEFdy', 'fragment')483  t.end()484})485 486test('IRI Serialization', { skip: true }, (t) => {487  const components = {488    scheme: 'uri',489    userinfo: 'us\xA0er:pa\uD7FFss',490    host: 'example.com',491    port: 123,492    path: '/o\uF900ne/t\uFDCFwo.t\uFDF0hree',493    query: 'q1=a1\uF8FF\uE000&q2=a2',494    fragment: 'bo\uFFEFdy\uE001'495  }496  t.equal(fastURI.serialize(components, IRI_OPTION), 'uri://us\xA0er:pa\uD7FFss@example.com:123/o\uF900ne/t\uFDCFwo.t\uFDF0hree?q1=a1\uF8FF\uE000&q2=a2#bo\uFFEFdy%EE%80%81')497  t.end()498})499 500test('IRI Normalizing', { skip: true }, (t) => {501  t.equal(fastURI.normalize('uri://www.example.org/red%09ros\xE9#red', IRI_OPTION), 'uri://www.example.org/red%09ros\xE9#red')502  t.end()503})504 505test('IRI Equals', { skip: true }, (t) => {506  // example from RFC 3987507  t.equal(fastURI.equal('example://a/b/c/%7Bfoo%7D/ros\xE9', 'eXAMPLE://a/./b/../b/%63/%7bfoo%7d/ros%C3%A9', IRI_OPTION), true)508  t.end()509})510 511test('Convert IRI to URI', { skip: true }, (t) => {512  // example from RFC 3987513  t.equal(fastURI.serialize(fastURI.parse('uri://www.example.org/red%09ros\xE9#red', IRI_OPTION)), 'uri://www.example.org/red%09ros%C3%A9#red')514 515  // Internationalized Domain Name conversion via punycode example from RFC 3987516  t.equal(fastURI.serialize(fastURI.parse('uri://r\xE9sum\xE9.example.org', { iri: true, domainHost: true }), { domainHost: true }), 'uri://xn--rsum-bpad.example.org')517  t.end()518})519 520test('Convert URI to IRI', { skip: true }, (t) => {521  // examples from RFC 3987522  t.equal(fastURI.serialize(fastURI.parse('uri://www.example.org/D%C3%BCrst'), IRI_OPTION), 'uri://www.example.org/D\xFCrst')523  t.equal(fastURI.serialize(fastURI.parse('uri://www.example.org/D%FCrst'), IRI_OPTION), 'uri://www.example.org/D%FCrst')524  t.equal(fastURI.serialize(fastURI.parse('uri://xn--99zt52a.example.org/%e2%80%ae'), IRI_OPTION), 'uri://xn--99zt52a.example.org/%E2%80%AE') // or uri://\u7D0D\u8C46.example.org/%E2%80%AE525 526  // Internationalized Domain Name conversion via punycode example from RFC 3987527  t.equal(fastURI.serialize(fastURI.parse('uri://xn--rsum-bpad.example.org', { domainHost: true }), { iri: true, domainHost: true }), 'uri://r\xE9sum\xE9.example.org')528  t.end()529})530 531if (fastURI.SCHEMES.http) {532  test('HTTP Equals', (t) => {533    // test from RFC 2616534    t.equal(fastURI.equal('http://abc.com:80/~smith/home.html', 'http://abc.com/~smith/home.html'), true)535    t.equal(fastURI.equal('http://ABC.com/%7Esmith/home.html', 'http://abc.com/~smith/home.html'), true)536    t.equal(fastURI.equal('http://ABC.com:/%7esmith/home.html', 'http://abc.com/~smith/home.html'), true)537    t.equal(fastURI.equal('HTTP://ABC.COM', 'http://abc.com/'), true)538    // test from RFC 3986539    t.equal(fastURI.equal('http://example.com:/', 'http://example.com:80/'), true)540    t.end()541  })542}543 544if (fastURI.SCHEMES.https) {545  test('HTTPS Equals', (t) => {546    t.equal(fastURI.equal('https://example.com', 'https://example.com:443/'), true)547    t.equal(fastURI.equal('https://example.com:/', 'https://example.com:443/'), true)548    t.end()549  })550}551 552if (fastURI.SCHEMES.urn) {553  test('URN Parsing', (t) => {554    // example from RFC 2141555    const components = fastURI.parse('urn:foo:a123,456')556    t.equal(components.error, undefined, 'errors')557    t.equal(components.scheme, 'urn', 'scheme')558    t.equal(components.userinfo, undefined, 'userinfo')559    t.equal(components.host, undefined, 'host')560    t.equal(components.port, undefined, 'port')561    t.equal(components.path, undefined, 'path')562    t.equal(components.query, undefined, 'query')563    t.equal(components.fragment, undefined, 'fragment')564    t.equal(components.nid, 'foo', 'nid')565    t.equal(components.nss, 'a123,456', 'nss')566    t.end()567  })568 569  test('URN Serialization', (t) => {570    // example from RFC 2141571    const components = {572      scheme: 'urn',573      nid: 'foo',574      nss: 'a123,456'575    }576    t.equal(fastURI.serialize(components), 'urn:foo:a123,456')577    t.end()578  })579 580  test('URN Equals', { skip: true }, (t) => {581    // test from RFC 2141582    t.equal(fastURI.equal('urn:foo:a123,456', 'urn:foo:a123,456'), true)583    t.equal(fastURI.equal('urn:foo:a123,456', 'URN:foo:a123,456'), true)584    t.equal(fastURI.equal('urn:foo:a123,456', 'urn:FOO:a123,456'), true)585    t.equal(fastURI.equal('urn:foo:a123,456', 'urn:foo:A123,456'), false)586    t.equal(fastURI.equal('urn:foo:a123%2C456', 'URN:FOO:a123%2c456'), true)587    t.end()588  })589 590  test('URN Resolving', (t) => {591    // example from epoberezkin592    t.equal(fastURI.resolve('', 'urn:some:ip:prop'), 'urn:some:ip:prop')593    t.equal(fastURI.resolve('#', 'urn:some:ip:prop'), 'urn:some:ip:prop')594    t.equal(fastURI.resolve('urn:some:ip:prop', 'urn:some:ip:prop'), 'urn:some:ip:prop')595    t.equal(fastURI.resolve('urn:some:other:prop', 'urn:some:ip:prop'), 'urn:some:ip:prop')596    t.end()597  })598 599  test('UUID Parsing', (t) => {600    // example from RFC 4122601    let components = fastURI.parse('urn:uuid:f81d4fae-7dec-11d0-a765-00a0c91e6bf6')602    t.equal(components.error, undefined, 'errors')603    t.equal(components.scheme, 'urn', 'scheme')604    t.equal(components.userinfo, undefined, 'userinfo')605    t.equal(components.host, undefined, 'host')606    t.equal(components.port, undefined, 'port')607    t.equal(components.path, undefined, 'path')608    t.equal(components.query, undefined, 'query')609    t.equal(components.fragment, undefined, 'fragment')610    t.equal(components.nid, 'uuid', 'nid')611    t.equal(components.nss, undefined, 'nss')612    t.equal(components.uuid, 'f81d4fae-7dec-11d0-a765-00a0c91e6bf6', 'uuid')613 614    components = fastURI.parse('urn:uuid:notauuid-7dec-11d0-a765-00a0c91e6bf6')615    t.notEqual(components.error, undefined, 'errors')616    t.end()617  })618 619  test('UUID Serialization', (t) => {620    // example from RFC 4122621    let components = {622      scheme: 'urn',623      nid: 'uuid',624      uuid: 'f81d4fae-7dec-11d0-a765-00a0c91e6bf6'625    }626    t.equal(fastURI.serialize(components), 'urn:uuid:f81d4fae-7dec-11d0-a765-00a0c91e6bf6')627 628    components = {629      scheme: 'urn',630      nid: 'uuid',631      uuid: 'notauuid-7dec-11d0-a765-00a0c91e6bf6'632    }633    t.equal(fastURI.serialize(components), 'urn:uuid:notauuid-7dec-11d0-a765-00a0c91e6bf6')634    t.end()635  })636 637  test('UUID Equals', (t) => {638    t.equal(fastURI.equal('URN:UUID:F81D4FAE-7DEC-11D0-A765-00A0C91E6BF6', 'urn:uuid:f81d4fae-7dec-11d0-a765-00a0c91e6bf6'), true)639    t.end()640  })641 642  test('URN NID Override', (t) => {643    let components = fastURI.parse('urn:foo:f81d4fae-7dec-11d0-a765-00a0c91e6bf6', { nid: 'uuid' })644    t.equal(components.error, undefined, 'errors')645    t.equal(components.scheme, 'urn', 'scheme')646    t.equal(components.path, undefined, 'path')647    t.equal(components.nid, 'foo', 'nid')648    t.equal(components.nss, undefined, 'nss')649    t.equal(components.uuid, 'f81d4fae-7dec-11d0-a765-00a0c91e6bf6', 'uuid')650 651    components = {652      scheme: 'urn',653      nid: 'foo',654      uuid: 'f81d4fae-7dec-11d0-a765-00a0c91e6bf6'655    }656    t.equal(fastURI.serialize(components, { nid: 'uuid' }), 'urn:foo:f81d4fae-7dec-11d0-a765-00a0c91e6bf6')657    t.end()658  })659}660 661if (fastURI.SCHEMES.mailto) {662  test('Mailto Parse', (t) => {663    let components664 665    // tests from RFC 6068666 667    components = fastURI.parse('mailto:chris@example.com')668    t.equal(components.error, undefined, 'error')669    t.equal(components.scheme, 'mailto', 'scheme')670    t.equal(components.userinfo, undefined, 'userinfo')671    t.equal(components.host, undefined, 'host')672    t.equal(components.port, undefined, 'port')673    t.equal(components.path, undefined, 'path')674    t.equal(components.query, undefined, 'query')675    t.equal(components.fragment, undefined, 'fragment')676    t.deepEqual(components.to, ['chris@example.com'], 'to')677    t.equal(components.subject, undefined, 'subject')678    t.equal(components.body, undefined, 'body')679    t.equal(components.headers, undefined, 'headers')680 681    components = fastURI.parse('mailto:infobot@example.com?subject=current-issue')682    t.deepEqual(components.to, ['infobot@example.com'], 'to')683    t.equal(components.subject, 'current-issue', 'subject')684 685    components = fastURI.parse('mailto:infobot@example.com?body=send%20current-issue')686    t.deepEqual(components.to, ['infobot@example.com'], 'to')687    t.equal(components.body, 'send current-issue', 'body')688 689    components = fastURI.parse('mailto:infobot@example.com?body=send%20current-issue%0D%0Asend%20index')690    t.deepEqual(components.to, ['infobot@example.com'], 'to')691    t.equal(components.body, 'send current-issue\x0D\x0Asend index', 'body')692 693    components = fastURI.parse('mailto:list@example.org?In-Reply-To=%3C3469A91.D10AF4C@example.com%3E')694    t.deepEqual(components.to, ['list@example.org'], 'to')695    t.deepEqual(components.headers, { 'In-Reply-To': '<3469A91.D10AF4C@example.com>' }, 'headers')696 697    components = fastURI.parse('mailto:majordomo@example.com?body=subscribe%20bamboo-l')698    t.deepEqual(components.to, ['majordomo@example.com'], 'to')699    t.equal(components.body, 'subscribe bamboo-l', 'body')700 701    components = fastURI.parse('mailto:joe@example.com?cc=bob@example.com&body=hello')702    t.deepEqual(components.to, ['joe@example.com'], 'to')703    t.equal(components.body, 'hello', 'body')704    t.deepEqual(components.headers, { cc: 'bob@example.com' }, 'headers')705 706    components = fastURI.parse('mailto:joe@example.com?cc=bob@example.com?body=hello')707    if (fastURI.VALIDATE_SUPPORT) t.ok(components.error, 'invalid header fields')708 709    components = fastURI.parse('mailto:gorby%25kremvax@example.com')710    t.deepEqual(components.to, ['gorby%kremvax@example.com'], 'to gorby%kremvax@example.com')711 712    components = fastURI.parse('mailto:unlikely%3Faddress@example.com?blat=foop')713    t.deepEqual(components.to, ['unlikely?address@example.com'], 'to unlikely?address@example.com')714    t.deepEqual(components.headers, { blat: 'foop' }, 'headers')715 716    components = fastURI.parse('mailto:Mike%26family@example.org')717    t.deepEqual(components.to, ['Mike&family@example.org'], 'to Mike&family@example.org')718 719    components = fastURI.parse('mailto:%22not%40me%22@example.org')720    t.deepEqual(components.to, ['"not@me"@example.org'], 'to ' + '"not@me"@example.org')721 722    components = fastURI.parse('mailto:%22oh%5C%5Cno%22@example.org')723    t.deepEqual(components.to, ['"oh\\\\no"@example.org'], 'to ' + '"oh\\\\no"@example.org')724 725    components = fastURI.parse("mailto:%22%5C%5C%5C%22it's%5C%20ugly%5C%5C%5C%22%22@example.org")726    t.deepEqual(components.to, ['"\\\\\\"it\'s\\ ugly\\\\\\""@example.org'], 'to ' + '"\\\\\\"it\'s\\ ugly\\\\\\""@example.org')727 728    components = fastURI.parse('mailto:user@example.org?subject=caf%C3%A9')729    t.deepEqual(components.to, ['user@example.org'], 'to')730    t.equal(components.subject, 'caf\xE9', 'subject')731 732    components = fastURI.parse('mailto:user@example.org?subject=%3D%3Futf-8%3FQ%3Fcaf%3DC3%3DA9%3F%3D')733    t.deepEqual(components.to, ['user@example.org'], 'to')734    t.equal(components.subject, '=?utf-8?Q?caf=C3=A9?=', 'subject') // TODO: Verify this735 736    components = fastURI.parse('mailto:user@example.org?subject=%3D%3Fiso-8859-1%3FQ%3Fcaf%3DE9%3F%3D')737    t.deepEqual(components.to, ['user@example.org'], 'to')738    t.equal(components.subject, '=?iso-8859-1?Q?caf=E9?=', 'subject') // TODO: Verify this739 740    components = fastURI.parse('mailto:user@example.org?subject=caf%C3%A9&body=caf%C3%A9')741    t.deepEqual(components.to, ['user@example.org'], 'to')742    t.equal(components.subject, 'caf\xE9', 'subject')743    t.equal(components.body, 'caf\xE9', 'body')744 745    if (fastURI.IRI_SUPPORT) {746      components = fastURI.parse('mailto:user@%E7%B4%8D%E8%B1%86.example.org?subject=Test&body=NATTO')747      t.deepEqual(components.to, ['user@xn--99zt52a.example.org'], 'to')748      t.equal(components.subject, 'Test', 'subject')749      t.equal(components.body, 'NATTO', 'body')750    }751 752    t.end()753  })754 755  test('Mailto Serialize', (t) => {756    // tests from RFC 6068757    t.equal(fastURI.serialize({ scheme: 'mailto', to: ['chris@example.com'] }), 'mailto:chris@example.com')758    t.equal(fastURI.serialize({ scheme: 'mailto', to: ['infobot@example.com'], body: 'current-issue' }), 'mailto:infobot@example.com?body=current-issue')759    t.equal(fastURI.serialize({ scheme: 'mailto', to: ['infobot@example.com'], body: 'send current-issue' }), 'mailto:infobot@example.com?body=send%20current-issue')760    t.equal(fastURI.serialize({ scheme: 'mailto', to: ['infobot@example.com'], body: 'send current-issue\x0D\x0Asend index' }), 'mailto:infobot@example.com?body=send%20current-issue%0D%0Asend%20index')761    t.equal(fastURI.serialize({ scheme: 'mailto', to: ['list@example.org'], headers: { 'In-Reply-To': '<3469A91.D10AF4C@example.com>' } }), 'mailto:list@example.org?In-Reply-To=%3C3469A91.D10AF4C@example.com%3E')762    t.equal(fastURI.serialize({ scheme: 'mailto', to: ['majordomo@example.com'], body: 'subscribe bamboo-l' }), 'mailto:majordomo@example.com?body=subscribe%20bamboo-l')763    t.equal(fastURI.serialize({ scheme: 'mailto', to: ['joe@example.com'], headers: { cc: 'bob@example.com', body: 'hello' } }), 'mailto:joe@example.com?cc=bob@example.com&body=hello')764    t.equal(fastURI.serialize({ scheme: 'mailto', to: ['gorby%25kremvax@example.com'] }), 'mailto:gorby%25kremvax@example.com')765    t.equal(fastURI.serialize({ scheme: 'mailto', to: ['unlikely%3Faddress@example.com'], headers: { blat: 'foop' } }), 'mailto:unlikely%3Faddress@example.com?blat=foop')766    t.equal(fastURI.serialize({ scheme: 'mailto', to: ['Mike&family@example.org'] }), 'mailto:Mike%26family@example.org')767    t.equal(fastURI.serialize({ scheme: 'mailto', to: ['"not@me"@example.org'] }), 'mailto:%22not%40me%22@example.org')768    t.equal(fastURI.serialize({ scheme: 'mailto', to: ['"oh\\\\no"@example.org'] }), 'mailto:%22oh%5C%5Cno%22@example.org')769    t.equal(fastURI.serialize({ scheme: 'mailto', to: ['"\\\\\\"it\'s\\ ugly\\\\\\""@example.org'] }), "mailto:%22%5C%5C%5C%22it's%5C%20ugly%5C%5C%5C%22%22@example.org")770    t.equal(fastURI.serialize({ scheme: 'mailto', to: ['user@example.org'], subject: 'caf\xE9' }), 'mailto:user@example.org?subject=caf%C3%A9')771    t.equal(fastURI.serialize({ scheme: 'mailto', to: ['user@example.org'], subject: '=?utf-8?Q?caf=C3=A9?=' }), 'mailto:user@example.org?subject=%3D%3Futf-8%3FQ%3Fcaf%3DC3%3DA9%3F%3D')772    t.equal(fastURI.serialize({ scheme: 'mailto', to: ['user@example.org'], subject: '=?iso-8859-1?Q?caf=E9?=' }), 'mailto:user@example.org?subject=%3D%3Fiso-8859-1%3FQ%3Fcaf%3DE9%3F%3D')773    t.equal(fastURI.serialize({ scheme: 'mailto', to: ['user@example.org'], subject: 'caf\xE9', body: 'caf\xE9' }), 'mailto:user@example.org?subject=caf%C3%A9&body=caf%C3%A9')774    if (fastURI.IRI_SUPPORT) {775      t.equal(fastURI.serialize({ scheme: 'mailto', to: ['us\xE9r@\u7d0d\u8c46.example.org'], subject: 'Test', body: 'NATTO' }), 'mailto:us%C3%A9r@xn--99zt52a.example.org?subject=Test&body=NATTO')776    }777    t.end()778  })779 780  test('Mailto Equals', (t) => {781    // tests from RFC 6068782    t.equal(fastURI.equal('mailto:addr1@an.example,addr2@an.example', 'mailto:?to=addr1@an.example,addr2@an.example'), true)783    t.equal(fastURI.equal('mailto:?to=addr1@an.example,addr2@an.example', 'mailto:addr1@an.example?to=addr2@an.example'), true)784    t.end()785  })786}787 788if (fastURI.SCHEMES.ws) {789  test('WS Parse', (t) => {790    let components791 792    // example from RFC 6455, Sec 4.1793    components = fastURI.parse('ws://example.com/chat')794    t.equal(components.error, undefined, 'error')795    t.equal(components.scheme, 'ws', 'scheme')796    t.equal(components.userinfo, undefined, 'userinfo')797    t.equal(components.host, 'example.com', 'host')798    t.equal(components.port, undefined, 'port')799    t.equal(components.path, undefined, 'path')800    t.equal(components.query, undefined, 'query')801    t.equal(components.fragment, undefined, 'fragment')802    t.equal(components.resourceName, '/chat', 'resourceName')803    t.equal(components.secure, false, 'secure')804 805    components = fastURI.parse('ws://example.com/foo?bar=baz')806    t.equal(components.error, undefined, 'error')807    t.equal(components.scheme, 'ws', 'scheme')808    t.equal(components.userinfo, undefined, 'userinfo')809    t.equal(components.host, 'example.com', 'host')810    t.equal(components.port, undefined, 'port')811    t.equal(components.path, undefined, 'path')812    t.equal(components.query, undefined, 'query')813    t.equal(components.fragment, undefined, 'fragment')814    t.equal(components.resourceName, '/foo?bar=baz', 'resourceName')815    t.equal(components.secure, false, 'secure')816 817    components = fastURI.parse('ws://example.com/?bar=baz')818    t.equal(components.resourceName, '/?bar=baz', 'resourceName')819 820    t.end()821  })822 823  test('WS Serialize', (t) => {824    t.equal(fastURI.serialize({ scheme: 'ws' }), 'ws:')825    t.equal(fastURI.serialize({ scheme: 'ws', host: 'example.com' }), 'ws://example.com')826    t.equal(fastURI.serialize({ scheme: 'ws', resourceName: '/' }), 'ws:')827    t.equal(fastURI.serialize({ scheme: 'ws', resourceName: '/foo' }), 'ws:/foo')828    t.equal(fastURI.serialize({ scheme: 'ws', resourceName: '/foo?bar' }), 'ws:/foo?bar')829    t.equal(fastURI.serialize({ scheme: 'ws', secure: false }), 'ws:')830    t.equal(fastURI.serialize({ scheme: 'ws', secure: true }), 'wss:')831    t.equal(fastURI.serialize({ scheme: 'ws', host: 'example.com', resourceName: '/foo' }), 'ws://example.com/foo')832    t.equal(fastURI.serialize({ scheme: 'ws', host: 'example.com', resourceName: '/foo?bar' }), 'ws://example.com/foo?bar')833    t.equal(fastURI.serialize({ scheme: 'ws', host: 'example.com', secure: false }), 'ws://example.com')834    t.equal(fastURI.serialize({ scheme: 'ws', host: 'example.com', secure: true }), 'wss://example.com')835    t.equal(fastURI.serialize({ scheme: 'ws', host: 'example.com', resourceName: '/foo?bar', secure: false }), 'ws://example.com/foo?bar')836    t.equal(fastURI.serialize({ scheme: 'ws', host: 'example.com', resourceName: '/foo?bar', secure: true }), 'wss://example.com/foo?bar')837    t.end()838  })839 840  test('WS Equal', (t) => {841    t.equal(fastURI.equal('WS://ABC.COM:80/chat#one', 'ws://abc.com/chat'), true)842    t.end()843  })844 845  test('WS Normalize', (t) => {846    t.equal(fastURI.normalize('ws://example.com:80/foo#hash'), 'ws://example.com/foo')847    t.end()848  })849}850 851if (fastURI.SCHEMES.wss) {852  test('WSS Parse', (t) => {853    let components854 855    // example from RFC 6455, Sec 4.1856    components = fastURI.parse('wss://example.com/chat')857    t.equal(components.error, undefined, 'error')858    t.equal(components.scheme, 'wss', 'scheme')859    t.equal(components.userinfo, undefined, 'userinfo')860    t.equal(components.host, 'example.com', 'host')861    t.equal(components.port, undefined, 'port')862    t.equal(components.path, undefined, 'path')863    t.equal(components.query, undefined, 'query')864    t.equal(components.fragment, undefined, 'fragment')865    t.equal(components.resourceName, '/chat', 'resourceName')866    t.equal(components.secure, true, 'secure')867 868    components = fastURI.parse('wss://example.com/foo?bar=baz')869    t.equal(components.error, undefined, 'error')870    t.equal(components.scheme, 'wss', 'scheme')871    t.equal(components.userinfo, undefined, 'userinfo')872    t.equal(components.host, 'example.com', 'host')873    t.equal(components.port, undefined, 'port')874    t.equal(components.path, undefined, 'path')875    t.equal(components.query, undefined, 'query')876    t.equal(components.fragment, undefined, 'fragment')877    t.equal(components.resourceName, '/foo?bar=baz', 'resourceName')878    t.equal(components.secure, true, 'secure')879 880    components = fastURI.parse('wss://example.com/?bar=baz')881    t.equal(components.resourceName, '/?bar=baz', 'resourceName')882 883    t.end()884  })885 886  test('WSS Serialize', (t) => {887    t.equal(fastURI.serialize({ scheme: 'wss' }), 'wss:')888    t.equal(fastURI.serialize({ scheme: 'wss', host: 'example.com' }), 'wss://example.com')889    t.equal(fastURI.serialize({ scheme: 'wss', resourceName: '/' }), 'wss:')890    t.equal(fastURI.serialize({ scheme: 'wss', resourceName: '/foo' }), 'wss:/foo')891    t.equal(fastURI.serialize({ scheme: 'wss', resourceName: '/foo?bar' }), 'wss:/foo?bar')892    t.equal(fastURI.serialize({ scheme: 'wss', secure: false }), 'ws:')893    t.equal(fastURI.serialize({ scheme: 'wss', secure: true }), 'wss:')894    t.equal(fastURI.serialize({ scheme: 'wss', host: 'example.com', resourceName: '/foo' }), 'wss://example.com/foo')895    t.equal(fastURI.serialize({ scheme: 'wss', host: 'example.com', resourceName: '/foo?bar' }), 'wss://example.com/foo?bar')896    t.equal(fastURI.serialize({ scheme: 'wss', host: 'example.com', secure: false }), 'ws://example.com')897    t.equal(fastURI.serialize({ scheme: 'wss', host: 'example.com', secure: true }), 'wss://example.com')898    t.equal(fastURI.serialize({ scheme: 'wss', host: 'example.com', resourceName: '/foo?bar', secure: false }), 'ws://example.com/foo?bar')899    t.equal(fastURI.serialize({ scheme: 'wss', host: 'example.com', resourceName: '/foo?bar', secure: true }), 'wss://example.com/foo?bar')900    t.end()901  })902 903  test('WSS Equal', (t) => {904    t.equal(fastURI.equal('WSS://ABC.COM:443/chat#one', 'wss://abc.com/chat'), true)905    t.end()906  })907 908  test('WSS Normalize', (t) => {909    t.equal(fastURI.normalize('wss://example.com:443/foo#hash'), 'wss://example.com/foo')910    t.end()911  })912}913 
basant307/AI_Governance_Project · CoolFace