source: imaps-frontend/node_modules/fast-uri/test/resolve.test.js@ 79a0317

main
Last change on this file since 79a0317 was 79a0317, checked in by stefan toskovski <stefantoska84@…>, 3 days ago

F4 Finalna Verzija

  • Property mode set to 100644
File size: 3.7 KB
RevLine 
[79a0317]1'use strict'
2
3const test = require('tape')
4const URI = require('../')
5
6test('URI Resolving', (t) => {
7 // normal examples from RFC 3986
8 const base = 'uri://a/b/c/d;p?q'
9 t.equal(URI.resolve(base, 'g:h'), 'g:h', 'g:h')
10 t.equal(URI.resolve(base, 'g:h'), 'g:h', 'g:h')
11 t.equal(URI.resolve(base, 'g'), 'uri://a/b/c/g', 'g')
12 t.equal(URI.resolve(base, './g'), 'uri://a/b/c/g', './g')
13 t.equal(URI.resolve(base, 'g/'), 'uri://a/b/c/g/', 'g/')
14 t.equal(URI.resolve(base, '/g'), 'uri://a/g', '/g')
15 t.equal(URI.resolve(base, '//g'), 'uri://g', '//g')
16 t.equal(URI.resolve(base, '?y'), 'uri://a/b/c/d;p?y', '?y')
17 t.equal(URI.resolve(base, 'g?y'), 'uri://a/b/c/g?y', 'g?y')
18 t.equal(URI.resolve(base, '#s'), 'uri://a/b/c/d;p?q#s', '#s')
19 t.equal(URI.resolve(base, 'g#s'), 'uri://a/b/c/g#s', 'g#s')
20 t.equal(URI.resolve(base, 'g?y#s'), 'uri://a/b/c/g?y#s', 'g?y#s')
21 t.equal(URI.resolve(base, ';x'), 'uri://a/b/c/;x', ';x')
22 t.equal(URI.resolve(base, 'g;x'), 'uri://a/b/c/g;x', 'g;x')
23 t.equal(URI.resolve(base, 'g;x?y#s'), 'uri://a/b/c/g;x?y#s', 'g;x?y#s')
24 t.equal(URI.resolve(base, ''), 'uri://a/b/c/d;p?q', '')
25 t.equal(URI.resolve(base, '.'), 'uri://a/b/c/', '.')
26 t.equal(URI.resolve(base, './'), 'uri://a/b/c/', './')
27 t.equal(URI.resolve(base, '..'), 'uri://a/b/', '..')
28 t.equal(URI.resolve(base, '../'), 'uri://a/b/', '../')
29 t.equal(URI.resolve(base, '../g'), 'uri://a/b/g', '../g')
30 t.equal(URI.resolve(base, '../..'), 'uri://a/', '../..')
31 t.equal(URI.resolve(base, '../../'), 'uri://a/', '../../')
32 t.equal(URI.resolve(base, '../../g'), 'uri://a/g', '../../g')
33
34 // abnormal examples from RFC 3986
35 t.equal(URI.resolve(base, '../../../g'), 'uri://a/g', '../../../g')
36 t.equal(URI.resolve(base, '../../../../g'), 'uri://a/g', '../../../../g')
37
38 t.equal(URI.resolve(base, '/./g'), 'uri://a/g', '/./g')
39 t.equal(URI.resolve(base, '/../g'), 'uri://a/g', '/../g')
40 t.equal(URI.resolve(base, 'g.'), 'uri://a/b/c/g.', 'g.')
41 t.equal(URI.resolve(base, '.g'), 'uri://a/b/c/.g', '.g')
42 t.equal(URI.resolve(base, 'g..'), 'uri://a/b/c/g..', 'g..')
43 t.equal(URI.resolve(base, '..g'), 'uri://a/b/c/..g', '..g')
44
45 t.equal(URI.resolve(base, './../g'), 'uri://a/b/g', './../g')
46 t.equal(URI.resolve(base, './g/.'), 'uri://a/b/c/g/', './g/.')
47 t.equal(URI.resolve(base, 'g/./h'), 'uri://a/b/c/g/h', 'g/./h')
48 t.equal(URI.resolve(base, 'g/../h'), 'uri://a/b/c/h', 'g/../h')
49 t.equal(URI.resolve(base, 'g;x=1/./y'), 'uri://a/b/c/g;x=1/y', 'g;x=1/./y')
50 t.equal(URI.resolve(base, 'g;x=1/../y'), 'uri://a/b/c/y', 'g;x=1/../y')
51
52 t.equal(URI.resolve(base, 'g?y/./x'), 'uri://a/b/c/g?y/./x', 'g?y/./x')
53 t.equal(URI.resolve(base, 'g?y/../x'), 'uri://a/b/c/g?y/../x', 'g?y/../x')
54 t.equal(URI.resolve(base, 'g#s/./x'), 'uri://a/b/c/g#s/./x', 'g#s/./x')
55 t.equal(URI.resolve(base, 'g#s/../x'), 'uri://a/b/c/g#s/../x', 'g#s/../x')
56
57 t.equal(URI.resolve(base, 'uri:g'), 'uri:g', 'uri:g')
58 t.equal(URI.resolve(base, 'uri:g', { tolerant: true }), 'uri://a/b/c/g', 'uri:g')
59
60 // examples by PAEz
61 // example was provided to avoid infinite loop within regex
62 // this is not the case anymore
63 // t.equal(URI.resolve('//www.g.com/', '/adf\ngf'), '//www.g.com/adf%0Agf', '/adf\\ngf')
64 // t.equal(URI.resolve('//www.g.com/error\n/bleh/bleh', '..'), '//www.g.com/error%0A/', '//www.g.com/error\\n/bleh/bleh')
65 t.end()
66})
67
68test('URN Resolving', (t) => {
69 // example from epoberezkin
70 t.equal(URI.resolve('', 'urn:some:ip:prop'), 'urn:some:ip:prop', 'urn:some:ip:prop')
71 t.equal(URI.resolve('#', 'urn:some:ip:prop'), 'urn:some:ip:prop', 'urn:some:ip:prop')
72 t.equal(URI.resolve('urn:some:ip:prop', 'urn:some:ip:prop'), 'urn:some:ip:prop', 'urn:some:ip:prop')
73 t.equal(URI.resolve('urn:some:other:prop', 'urn:some:ip:prop'), 'urn:some:ip:prop', 'urn:some:ip:prop')
74 t.end()
75})
Note: See TracBrowser for help on using the repository browser.