-
-
Notifications
You must be signed in to change notification settings - Fork 5k
/
Copy pathpath.spec.js
77 lines (65 loc) · 1.9 KB
/
path.spec.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
import { resolvePath, parsePath, cleanPath } from '../../../src/util/path'
describe('Path utils', () => {
describe('resolvePath', () => {
it('absolute', () => {
const path = resolvePath('/a', '/b')
expect(path).toBe('/a')
})
it('relative', () => {
const path = resolvePath('c/d', '/b')
expect(path).toBe('/c/d')
})
it('relative with append', () => {
const path = resolvePath('c/d', '/b', true)
expect(path).toBe('/b/c/d')
})
it('relative parent', () => {
const path = resolvePath('../d', '/a/b/c')
expect(path).toBe('/a/d')
})
it('relative parent with append', () => {
const path = resolvePath('../d', '/a/b/c', true)
expect(path).toBe('/a/b/d')
})
it('relative query', () => {
const path = resolvePath('?foo=bar', '/a/b')
expect(path).toBe('/a/b?foo=bar')
})
it('relative hash', () => {
const path = resolvePath('#hi', '/a/b')
expect(path).toBe('/a/b#hi')
})
})
describe('parsePath', () => {
it('plain', () => {
const res = parsePath('/a')
expect(res.path).toBe('/a')
expect(res.hash).toBe('')
expect(res.query).toBe('')
})
it('query', () => {
const res = parsePath('/a?foo=bar???')
expect(res.path).toBe('/a')
expect(res.hash).toBe('')
expect(res.query).toBe('foo=bar???')
})
it('hash', () => {
const res = parsePath('/a#haha#hoho')
expect(res.path).toBe('/a')
expect(res.hash).toBe('#haha#hoho')
expect(res.query).toBe('')
})
it('both', () => {
const res = parsePath('/a?foo=bar#ok?baz=qux')
expect(res.path).toBe('/a')
expect(res.hash).toBe('#ok?baz=qux')
expect(res.query).toBe('foo=bar')
})
})
describe('cleanPath', () => {
it('should work', () => {
const path = cleanPath('//a//b//d/')
expect(path).toBe('/a/b/d/')
})
})
})