-
Notifications
You must be signed in to change notification settings - Fork 42
/
Copy patherrors.coffee
107 lines (100 loc) · 2.64 KB
/
errors.coffee
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
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
test = require 'tape'
UrlPattern = require '../lib/url-pattern'
test 'invalid argument', (t) ->
UrlPattern
t.plan 5
try
new UrlPattern()
catch e
t.equal e.message, "argument must be a regex or a string"
try
new UrlPattern(5)
catch e
t.equal e.message, "argument must be a regex or a string"
try
new UrlPattern ''
catch e
t.equal e.message, "argument must not be the empty string"
try
new UrlPattern ' '
catch e
t.equal e.message, "argument must not contain whitespace"
try
new UrlPattern ' fo o'
catch e
t.equal e.message, "argument must not contain whitespace"
t.end()
test 'invalid variable name in pattern', (t) ->
UrlPattern
t.plan 3
try
new UrlPattern ':'
catch e
t.equal e.message, "couldn't parse pattern"
try
new UrlPattern ':.'
catch e
t.equal e.message, "couldn't parse pattern"
try
new UrlPattern 'foo:.'
catch e
# TODO `:` must be followed by the name of the named segment consisting of at least one character in character set `a-zA-Z0-9` at 4
t.equal e.message, "could only partially parse pattern"
t.end()
test 'too many closing parentheses', (t) ->
t.plan 2
try
new UrlPattern ')'
catch e
# TODO did not plan ) at 0
t.equal e.message, "couldn't parse pattern"
try
new UrlPattern '((foo)))bar'
catch e
# TODO did not plan ) at 7
t.equal e.message, "could only partially parse pattern"
t.end()
test 'unclosed parentheses', (t) ->
t.plan 2
try
new UrlPattern '('
catch e
# TODO unclosed parentheses at 1
t.equal e.message, "couldn't parse pattern"
try
new UrlPattern '(((foo)bar(boo)far)'
catch e
# TODO unclosed parentheses at 19
t.equal e.message, "couldn't parse pattern"
t.end()
test 'regex names', (t) ->
t.plan 3
try
new UrlPattern /x/, 5
catch e
t.equal e.message, 'if first argument is a regex the second argument may be an array of group names but you provided something else'
try
new UrlPattern /(((foo)bar(boo))far)/, []
catch e
t.equal e.message, "regex contains 4 groups but array of group names contains 0"
try
new UrlPattern /(((foo)bar(boo))far)/, ['a', 'b']
catch e
t.equal e.message, "regex contains 4 groups but array of group names contains 2"
t.end()
test 'stringify regex', (t) ->
t.plan 1
pattern = new UrlPattern /x/
try
pattern.stringify()
catch e
t.equal e.message, "can't stringify patterns generated from a regex"
t.end()
test 'stringify argument', (t) ->
t.plan 1
pattern = new UrlPattern 'foo'
try
pattern.stringify(5)
catch e
t.equal e.message, "argument must be an object or undefined"
t.end()