1 | 'use strict'
|
---|
2 |
|
---|
3 | const test = require('tape')
|
---|
4 | const URI = require('../')
|
---|
5 |
|
---|
6 | const fn = URI.equal
|
---|
7 | const runTest = (t, suite) => {
|
---|
8 | suite.forEach(s => {
|
---|
9 | const operator = s.result ? '==' : '!='
|
---|
10 | t.equal(fn(s.pair[0], s.pair[1]), s.result, `${s.pair[0]} ${operator} ${s.pair[1]}`)
|
---|
11 | t.equal(fn(s.pair[1], s.pair[0]), s.result, `${s.pair[1]} ${operator} ${s.pair[0]}`)
|
---|
12 | })
|
---|
13 | }
|
---|
14 |
|
---|
15 | test('URI Equals', (t) => {
|
---|
16 | const suite = [
|
---|
17 | { pair: ['example://a/b/c/%7Bfoo%7D', 'eXAMPLE://a/./b/../b/%63/%7bfoo%7d'], result: true }, // test from RFC 3986
|
---|
18 | { pair: ['http://example.org/~user', 'http://example.org/%7euser'], result: true } // test from RFC 3987
|
---|
19 | ]
|
---|
20 | runTest(t, suite)
|
---|
21 | t.end()
|
---|
22 | })
|
---|
23 |
|
---|
24 | // test('IRI Equals', (t) => {
|
---|
25 | // // example from RFC 3987
|
---|
26 | // t.equal(URI.equal('example://a/b/c/%7Bfoo%7D/ros\xE9', 'eXAMPLE://a/./b/../b/%63/%7bfoo%7d/ros%C3%A9', IRI_OPTION), true)
|
---|
27 | // t.end()
|
---|
28 | // })
|
---|
29 |
|
---|
30 | test('HTTP Equals', (t) => {
|
---|
31 | const suite = [
|
---|
32 | // test from RFC 2616
|
---|
33 | { pair: ['http://abc.com:80/~smith/home.html', 'http://abc.com/~smith/home.html'], result: true },
|
---|
34 | { pair: [{ scheme: 'http', host: 'abc.com', port: 80, path: '/~smith/home.html' }, 'http://abc.com/~smith/home.html'], result: true },
|
---|
35 | { pair: ['http://ABC.com/%7Esmith/home.html', 'http://abc.com/~smith/home.html'], result: true },
|
---|
36 | { pair: ['http://ABC.com:/%7esmith/home.html', 'http://abc.com/~smith/home.html'], result: true },
|
---|
37 | { pair: ['HTTP://ABC.COM', 'http://abc.com/'], result: true },
|
---|
38 | // test from RFC 3986
|
---|
39 | { pair: ['http://example.com:/', 'http://example.com:80/'], result: true }
|
---|
40 | ]
|
---|
41 | runTest(t, suite)
|
---|
42 | t.end()
|
---|
43 | })
|
---|
44 |
|
---|
45 | test('HTTPS Equals', (t) => {
|
---|
46 | const suite = [
|
---|
47 | { pair: ['https://example.com', 'https://example.com:443/'], result: true },
|
---|
48 | { pair: ['https://example.com:/', 'https://example.com:443/'], result: true }
|
---|
49 | ]
|
---|
50 | runTest(t, suite)
|
---|
51 | t.end()
|
---|
52 | })
|
---|
53 |
|
---|
54 | test('URN Equals', (t) => {
|
---|
55 | const suite = [
|
---|
56 | // test from RFC 2141
|
---|
57 | { pair: ['urn:foo:a123,456', 'urn:foo:a123,456'], result: true },
|
---|
58 | { pair: ['urn:foo:a123,456', 'URN:foo:a123,456'], result: true },
|
---|
59 | { pair: ['urn:foo:a123,456', 'urn:FOO:a123,456'], result: true }
|
---|
60 | ]
|
---|
61 |
|
---|
62 | // Disabling for now as the whole equal logic might need
|
---|
63 | // to be refactored
|
---|
64 | // t.equal(URI.equal('urn:foo:a123,456', 'urn:foo:A123,456'), false)
|
---|
65 | // t.equal(URI.equal('urn:foo:a123%2C456', 'URN:FOO:a123%2c456'), true)
|
---|
66 |
|
---|
67 | runTest(t, suite)
|
---|
68 | t.end()
|
---|
69 | })
|
---|
70 |
|
---|
71 | test('UUID Equals', (t) => {
|
---|
72 | const suite = [
|
---|
73 | { pair: ['URN:UUID:F81D4FAE-7DEC-11D0-A765-00A0C91E6BF6', 'urn:uuid:f81d4fae-7dec-11d0-a765-00a0c91e6bf6'], result: true }
|
---|
74 | ]
|
---|
75 |
|
---|
76 | runTest(t, suite)
|
---|
77 | t.end()
|
---|
78 | })
|
---|
79 |
|
---|
80 | // test('Mailto Equals', (t) => {
|
---|
81 | // // tests from RFC 6068
|
---|
82 | // t.equal(URI.equal('mailto:addr1@an.example,addr2@an.example', 'mailto:?to=addr1@an.example,addr2@an.example'), true)
|
---|
83 | // t.equal(URI.equal('mailto:?to=addr1@an.example,addr2@an.example', 'mailto:addr1@an.example?to=addr2@an.example'), true)
|
---|
84 | // t.end()
|
---|
85 | // })
|
---|
86 |
|
---|
87 | test('WS Equal', (t) => {
|
---|
88 | const suite = [
|
---|
89 | { pair: ['WS://ABC.COM:80/chat#one', 'ws://abc.com/chat'], result: true }
|
---|
90 | ]
|
---|
91 |
|
---|
92 | runTest(t, suite)
|
---|
93 | t.end()
|
---|
94 | })
|
---|
95 |
|
---|
96 | test('WSS Equal', (t) => {
|
---|
97 | const suite = [
|
---|
98 | { pair: ['WSS://ABC.COM:443/chat#one', 'wss://abc.com/chat'], result: true }
|
---|
99 | ]
|
---|
100 |
|
---|
101 | runTest(t, suite)
|
---|
102 | t.end()
|
---|
103 | })
|
---|