1 |
|
2 |
|
3 | var parseUri = require('../parseUri')
|
4 | var chai = require('chai')
|
5 | var expect = chai.expect
|
6 |
|
7 | describe('parseUri', function () {
|
8 | function assertURL (url, object) {
|
9 | expect(parseUri(url)).to.eql(object)
|
10 | }
|
11 |
|
12 | it('can parse a URL', function () {
|
13 | assertURL('http://localhost:1234/', {
|
14 | auth: '',
|
15 | authority: '//localhost:1234',
|
16 | hash: '',
|
17 | host: 'localhost:1234',
|
18 | hostname: 'localhost',
|
19 | href: 'http://localhost:1234/',
|
20 | pathname: '/',
|
21 | port: '1234',
|
22 | protocol: 'http:',
|
23 | search: ''
|
24 | })
|
25 | })
|
26 |
|
27 | it('can parse a URL with path and query', function () {
|
28 | assertURL('http://localhost:1234/a/path?a=A&b=B', {
|
29 | auth: '',
|
30 | authority: '//localhost:1234',
|
31 | hash: '',
|
32 | host: 'localhost:1234',
|
33 | hostname: 'localhost',
|
34 | href: 'http://localhost:1234/a/path?a=A&b=B',
|
35 | pathname: '/a/path',
|
36 | port: '1234',
|
37 | protocol: 'http:',
|
38 | search: '?a=A&b=B'
|
39 | })
|
40 | })
|
41 |
|
42 | it('can parse a URL with username and password', function () {
|
43 | assertURL('http://user%20name:pass%20word@localhost:1234/a/path?a=A&b=B', {
|
44 | auth: 'user name:pass word',
|
45 | authority: '//user%20name:pass%20word@localhost:1234',
|
46 | hash: '',
|
47 | host: 'localhost:1234',
|
48 | hostname: 'localhost',
|
49 | href: 'http://user%20name:pass%20word@localhost:1234/a/path?a=A&b=B',
|
50 | pathname: '/a/path',
|
51 | port: '1234',
|
52 | protocol: 'http:',
|
53 | search: '?a=A&b=B'
|
54 | })
|
55 | })
|
56 |
|
57 | it('can parse a URL with @ and : in the path', function () {
|
58 | assertURL('http://localhost:1234/a/path@with:isnotauth?a=A&b=B', {
|
59 | auth: '',
|
60 | authority: '//localhost:1234',
|
61 | hash: '',
|
62 | host: 'localhost:1234',
|
63 | hostname: 'localhost',
|
64 | href: 'http://localhost:1234/a/path@with:isnotauth?a=A&b=B',
|
65 | pathname: '/a/path@with:isnotauth',
|
66 | port: '1234',
|
67 | protocol: 'http:',
|
68 | search: '?a=A&b=B'
|
69 | })
|
70 | })
|
71 | })
|