Skip to content

Commit ac4db06

Browse files
committed
use tape in test/helpers.coffee
1 parent a8b3477 commit ac4db06

File tree

1 file changed

+116
-117
lines changed

1 file changed

+116
-117
lines changed

test/helpers.coffee

+116-117
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
test = require 'tape'
12
{
23
escapeForRegex
34
concatMap
@@ -6,134 +7,132 @@
67
keysAndValuesToObject
78
} = require '../lib/url-pattern'
89

9-
module.exports =
10+
test 'escapeForRegex', (t) ->
11+
expected = '\\[\\-\\/\\\\\\^\\$\\*\\+\\?\\.\\(\\)\\|\\[\\]\\{\\}\\]'
12+
actual = escapeForRegex('[-\/\\^$*+?.()|[\]{}]')
13+
t.equal expected, actual
1014

11-
'escapeForRegex': (test) ->
12-
expected = '\\[\\-\\/\\\\\\^\\$\\*\\+\\?\\.\\(\\)\\|\\[\\]\\{\\}\\]'
13-
actual = escapeForRegex('[-\/\\^$*+?.()|[\]{}]')
14-
test.equal expected, actual
15+
t.equal escapeForRegex('a$98kdjf(kdj)'), 'a\\$98kdjf\\(kdj\\)'
16+
t.equal 'a', escapeForRegex 'a'
17+
t.equal '!', escapeForRegex '!'
18+
t.equal '\\.', escapeForRegex '.'
19+
t.equal '\\/', escapeForRegex '/'
20+
t.equal '\\-', escapeForRegex '-'
21+
t.equal '\\-', escapeForRegex '-'
22+
t.equal '\\[', escapeForRegex '['
23+
t.equal '\\]', escapeForRegex ']'
24+
t.equal '\\(', escapeForRegex '('
25+
t.equal '\\)', escapeForRegex ')'
26+
t.end()
1527

16-
test.equal escapeForRegex('a$98kdjf(kdj)'), 'a\\$98kdjf\\(kdj\\)'
17-
test.equal 'a', escapeForRegex 'a'
18-
test.equal '!', escapeForRegex '!'
19-
test.equal '\\.', escapeForRegex '.'
20-
test.equal '\\/', escapeForRegex '/'
21-
test.equal '\\-', escapeForRegex '-'
22-
test.equal '\\-', escapeForRegex '-'
23-
test.equal '\\[', escapeForRegex '['
24-
test.equal '\\]', escapeForRegex ']'
25-
test.equal '\\(', escapeForRegex '('
26-
test.equal '\\)', escapeForRegex ')'
27-
test.done()
28+
test 'concatMap', (t) ->
29+
t.deepEqual [], concatMap [], ->
30+
t.deepEqual [1], concatMap [1], (x) -> [x]
31+
t.deepEqual [1, 1, 1, 2, 2, 2, 3, 3, 3], concatMap [1, 2, 3], (x) -> [x, x, x]
32+
t.end()
2833

29-
'concatMap': (test) ->
30-
test.deepEqual [], concatMap [], ->
31-
test.deepEqual [1], concatMap [1], (x) -> [x]
32-
test.deepEqual [1, 1, 1, 2, 2, 2, 3, 3, 3], concatMap [1, 2, 3], (x) -> [x, x, x]
33-
test.done()
34+
test 'stringConcatMap', (t) ->
35+
t.equal '', stringConcatMap [], ->
36+
t.equal '1', stringConcatMap [1], (x) -> x
37+
t.equal '123', stringConcatMap [1, 2, 3], (x) -> x
38+
t.equal '1a2a3a', stringConcatMap [1, 2, 3], (x) -> x + 'a'
39+
t.end()
3440

35-
'stringConcatMap': (test) ->
36-
test.equal '', stringConcatMap [], ->
37-
test.equal '1', stringConcatMap [1], (x) -> x
38-
test.equal '123', stringConcatMap [1, 2, 3], (x) -> x
39-
test.equal '1a2a3a', stringConcatMap [1, 2, 3], (x) -> x + 'a'
40-
test.done()
41+
test 'regexGroupCount', (t) ->
42+
t.equal 0, regexGroupCount /foo/
43+
t.equal 1, regexGroupCount /(foo)/
44+
t.equal 2, regexGroupCount /((foo))/
45+
t.equal 2, regexGroupCount /(fo(o))/
46+
t.equal 2, regexGroupCount /f(o)(o)/
47+
t.equal 2, regexGroupCount /f(o)o()/
48+
t.equal 5, regexGroupCount /f(o)o()()(())/
49+
t.end()
4150

42-
'regexGroupCount': (test) ->
43-
test.equal 0, regexGroupCount /foo/
44-
test.equal 1, regexGroupCount /(foo)/
45-
test.equal 2, regexGroupCount /((foo))/
46-
test.equal 2, regexGroupCount /(fo(o))/
47-
test.equal 2, regexGroupCount /f(o)(o)/
48-
test.equal 2, regexGroupCount /f(o)o()/
49-
test.equal 5, regexGroupCount /f(o)o()()(())/
50-
test.done()
51-
52-
'keysAndValuesToObject': (test) ->
53-
test.deepEqual(
54-
keysAndValuesToObject(
55-
[]
56-
[]
57-
)
58-
{}
51+
test 'keysAndValuesToObject', (t) ->
52+
t.deepEqual(
53+
keysAndValuesToObject(
54+
[]
55+
[]
5956
)
60-
test.deepEqual(
61-
keysAndValuesToObject(
62-
['one']
63-
[1]
64-
)
65-
{
66-
one: 1
67-
}
57+
{}
58+
)
59+
t.deepEqual(
60+
keysAndValuesToObject(
61+
['one']
62+
[1]
6863
)
69-
test.deepEqual(
70-
keysAndValuesToObject(
71-
['one', 'two']
72-
[1]
73-
)
74-
{
75-
one: 1
76-
}
64+
{
65+
one: 1
66+
}
67+
)
68+
t.deepEqual(
69+
keysAndValuesToObject(
70+
['one', 'two']
71+
[1]
7772
)
78-
test.deepEqual(
79-
keysAndValuesToObject(
80-
['one', 'two', 'two']
81-
[1, 2, 3]
82-
)
83-
{
84-
one: 1
85-
two: [2, 3]
86-
}
73+
{
74+
one: 1
75+
}
76+
)
77+
t.deepEqual(
78+
keysAndValuesToObject(
79+
['one', 'two', 'two']
80+
[1, 2, 3]
8781
)
88-
test.deepEqual(
89-
keysAndValuesToObject(
90-
['one', 'two', 'two', 'two']
91-
[1, 2, 3, null]
92-
)
93-
{
94-
one: 1
95-
two: [2, 3]
96-
}
82+
{
83+
one: 1
84+
two: [2, 3]
85+
}
86+
)
87+
t.deepEqual(
88+
keysAndValuesToObject(
89+
['one', 'two', 'two', 'two']
90+
[1, 2, 3, null]
9791
)
98-
test.deepEqual(
99-
keysAndValuesToObject(
100-
['one', 'two', 'two', 'two']
101-
[1, 2, 3, 4]
102-
)
103-
{
104-
one: 1
105-
two: [2, 3, 4]
106-
}
92+
{
93+
one: 1
94+
two: [2, 3]
95+
}
96+
)
97+
t.deepEqual(
98+
keysAndValuesToObject(
99+
['one', 'two', 'two', 'two']
100+
[1, 2, 3, 4]
107101
)
108-
test.deepEqual(
109-
keysAndValuesToObject(
110-
['one', 'two', 'two', 'two', 'three']
111-
[1, 2, 3, 4, undefined]
112-
)
113-
{
114-
one: 1
115-
two: [2, 3, 4]
116-
}
102+
{
103+
one: 1
104+
two: [2, 3, 4]
105+
}
106+
)
107+
t.deepEqual(
108+
keysAndValuesToObject(
109+
['one', 'two', 'two', 'two', 'three']
110+
[1, 2, 3, 4, undefined]
117111
)
118-
test.deepEqual(
119-
keysAndValuesToObject(
120-
['one', 'two', 'two', 'two', 'three']
121-
[1, 2, 3, 4, 5]
122-
)
123-
{
124-
one: 1
125-
two: [2, 3, 4]
126-
three: 5
127-
}
112+
{
113+
one: 1
114+
two: [2, 3, 4]
115+
}
116+
)
117+
t.deepEqual(
118+
keysAndValuesToObject(
119+
['one', 'two', 'two', 'two', 'three']
120+
[1, 2, 3, 4, 5]
128121
)
129-
test.deepEqual(
130-
keysAndValuesToObject(
131-
['one', 'two', 'two', 'two', 'three']
132-
[null, 2, 3, 4, 5]
133-
)
134-
{
135-
two: [2, 3, 4]
136-
three: 5
137-
}
122+
{
123+
one: 1
124+
two: [2, 3, 4]
125+
three: 5
126+
}
127+
)
128+
t.deepEqual(
129+
keysAndValuesToObject(
130+
['one', 'two', 'two', 'two', 'three']
131+
[null, 2, 3, 4, 5]
138132
)
139-
test.done()
133+
{
134+
two: [2, 3, 4]
135+
three: 5
136+
}
137+
)
138+
t.end()

0 commit comments

Comments
 (0)