|
1 | 1 | var expect = require('chai').expect; |
2 | 2 |
|
3 | | -describe('Regexp', function() { |
| 3 | +describe.only('Regexp', function () { |
4 | 4 |
|
5 | | - describe('matching beginning of a string', function() { |
| 5 | + describe('matching beginning of a string', function () { |
6 | 6 |
|
7 | 7 | var pattern = /^players/; |
8 | 8 |
|
9 | | - it('passes with a matching string', function() { |
| 9 | + it('passes with a matching string', function () { |
10 | 10 | expect(pattern.test('players')).to.equal(true); |
11 | 11 | }); |
12 | 12 |
|
13 | | - it('fails with a non-matching string', function() { |
| 13 | + it('fails with a non-matching string', function () { |
14 | 14 | expect(pattern.test('the players')).to.equal(false); |
15 | 15 | }); |
16 | 16 | }); |
17 | 17 |
|
18 | | - describe('matching extension', function() { |
| 18 | + describe('matching extension', function () { |
19 | 19 |
|
20 | 20 | var pattern = /\.js$/; |
21 | 21 |
|
22 | | - it('passes with a matching filename', function() { |
| 22 | + it('passes with a matching filename', function () { |
23 | 23 | expect(pattern.test('any-file.js')).to.equal(true); |
24 | 24 | }); |
25 | 25 |
|
26 | | - it('fails with a non-matching extension', function() { |
| 26 | + it('fails with a non-matching extension', function () { |
27 | 27 | expect(pattern.test('another.extension')).to.equal(false); |
28 | 28 | }); |
29 | 29 |
|
30 | | - it('fails with a mal-formed extension', function() { |
| 30 | + it('fails with a mal-formed extension', function () { |
31 | 31 | expect(pattern.test('hiddenjs')).to.equal(false); |
32 | 32 | }); |
33 | 33 | }); |
34 | 34 |
|
35 | | - describe('matching /players', function() { |
| 35 | + describe('matching /players', function () { |
36 | 36 |
|
37 | 37 | var pattern = /^\/players/; |
38 | 38 |
|
39 | | - it('passes with a matching string', function() { |
| 39 | + it('passes with a matching string', function () { |
40 | 40 | expect(pattern.test('/players')).to.equal(true); |
41 | 41 | }); |
42 | 42 |
|
43 | | - it('fails with a non-matching string', function() { |
| 43 | + it('fails with a non-matching string', function () { |
44 | 44 | expect(pattern.test('/the players')).to.equal(false); |
45 | 45 | }); |
46 | 46 |
|
47 | 47 | }); |
48 | 48 |
|
49 | | - describe('matching /players/{login}', function() { |
| 49 | + describe('matching /players/{login}', function () { |
50 | 50 |
|
51 | 51 | var pattern = /^\/players\/[A-z]+$/; |
52 | 52 |
|
53 | | - it('passes with a matching string', function() { |
| 53 | + it('passes with a matching string', function () { |
54 | 54 | expect(pattern.test('/players/any')).to.equal(true); |
55 | 55 | }); |
56 | 56 |
|
57 | | - it('fails with a non-matching string', function() { |
| 57 | + it('fails with a non-matching string', function () { |
58 | 58 | expect(pattern.test('/players/any/thing')).to.equal(false); |
59 | 59 | }); |
60 | 60 |
|
61 | 61 | }); |
62 | 62 |
|
63 | | - describe('matching /players/{login} with a dot in the login', function() { |
| 63 | + describe('matching /players/{login} with a dot in the login', function () { |
64 | 64 |
|
65 | 65 | var pattern = /^\/players\/[A-z|\.]+$/; |
66 | 66 |
|
67 | | - it('passes with a matching string', function() { |
| 67 | + it('passes with a matching string', function () { |
68 | 68 | expect(pattern.test('/players/any.name')).to.equal(true); |
69 | 69 | }); |
70 | 70 |
|
71 | | - it('fails with a non-matching string', function() { |
| 71 | + it('fails with a non-matching string', function () { |
72 | 72 | expect(pattern.test('/players/any:name')).to.equal(false); |
73 | 73 | }); |
74 | 74 |
|
75 | 75 | }); |
76 | 76 |
|
77 | | - describe('matching /players/{login} with a dash in the login', function() { |
| 77 | + describe('matching /players/{login} with a dash in the login', function () { |
78 | 78 |
|
79 | 79 | var pattern = /^\/players\/[A-z|\.|\-]+$/; |
80 | 80 |
|
81 | | - it('passes with a matching string', function() { |
| 81 | + it('passes with a matching string', function () { |
82 | 82 | expect(pattern.test('/players/any-name')).to.equal(true); |
83 | 83 | }); |
84 | 84 |
|
85 | | - it('fails with a non-matching string', function() { |
| 85 | + it('fails with a non-matching string', function () { |
86 | 86 | expect(pattern.test('/players/any:name')).to.equal(false); |
87 | 87 | }); |
88 | 88 |
|
89 | 89 | }); |
90 | 90 |
|
91 | | - describe('matching /players/{login} with a number in the login', function() { |
| 91 | + describe('matching /players/{login} with a number in the login', function () { |
92 | 92 |
|
93 | 93 | var pattern = /^\/players\/[A-z|\.|\-|0-9]+$/; |
94 | 94 |
|
95 | | - it('passes with a matching string', function() { |
| 95 | + it('passes with a matching string', function () { |
96 | 96 | expect(pattern.test('/players/any-name-42')).to.equal(true); |
97 | 97 | }); |
98 | 98 |
|
99 | | - it('fails with a non-matching string', function() { |
| 99 | + it('fails with a non-matching string', function () { |
100 | 100 | expect(pattern.test('/players/any:name')).to.equal(false); |
101 | 101 | }); |
102 | 102 |
|
103 | 103 | }); |
104 | 104 |
|
105 | | - describe('matching /players/{login} with a @ in the login', function() { |
| 105 | + describe('matching /players/{login} with a @ in the login', function () { |
106 | 106 |
|
107 | 107 | var pattern = /^\/players\/[A-z|\.|\-|@]+$/; |
108 | 108 |
|
109 | | - it('passes with a matching string', function() { |
| 109 | + it('passes with a matching string', function () { |
110 | 110 | expect(pattern.test('/players/any@name')).to.equal(true); |
111 | 111 | }); |
112 | 112 |
|
113 | | - it('fails with a non-matching string', function() { |
| 113 | + it('fails with a non-matching string', function () { |
114 | 114 | expect(pattern.test('/players/any:name')).to.equal(false); |
115 | 115 | }); |
116 | 116 |
|
117 | 117 | }); |
118 | 118 |
|
119 | | - describe('matching /players/{login}/play/world/{id}', function() { |
| 119 | + describe('matching /players/{login}/play/world/{id}', function () { |
120 | 120 |
|
121 | 121 | var pattern = /^\/players\/[A-z]+\/play\/world\/[0-9]+$/; |
122 | 122 |
|
123 | | - it('passes with a matching string', function() { |
| 123 | + it('passes with a matching string', function () { |
124 | 124 | expect(pattern.test('/players/any/play/world/42')).to.equal(true); |
125 | 125 | }); |
126 | 126 |
|
127 | | - it('fails with a non-matching string', function() { |
| 127 | + it('fails with a non-matching string', function () { |
128 | 128 | expect(pattern.test('/players/any/play/world/3/any')).to.equal(false); |
129 | 129 | }); |
130 | 130 |
|
131 | 131 | }); |
132 | 132 |
|
133 | | - describe('matching /any-route', function() { |
| 133 | + describe('matching /any-route', function () { |
134 | 134 |
|
135 | 135 | var pattern = /^\/any-route$/; |
136 | 136 |
|
137 | | - it('passes with a matching string', function() { |
| 137 | + it('passes with a matching string', function () { |
138 | 138 | expect(pattern.test('/any-route')).to.equal(true); |
139 | 139 | }); |
140 | 140 |
|
141 | | - it('fails with a non-matching string', function() { |
| 141 | + it('fails with a non-matching string', function () { |
142 | 142 | expect(pattern.test('/any-route/more')).to.equal(false); |
143 | 143 | }); |
144 | 144 |
|
145 | 145 | }); |
146 | 146 |
|
147 | | - describe('matching all', function() { |
| 147 | + describe('matching all', function () { |
148 | 148 |
|
149 | 149 | var pattern = /.*/; |
150 | 150 |
|
151 | | - it('passes with a matching string', function() { |
| 151 | + it('passes with a matching string', function () { |
152 | 152 | expect(pattern.test('/-42any/thing')).to.equal(true); |
153 | 153 | }); |
154 | 154 |
|
155 | 155 | }); |
156 | 156 |
|
157 | | - describe('Data extraction', function() { |
| 157 | + describe('Data extraction', function () { |
158 | 158 |
|
159 | 159 | var pattern = /^\/players\/(.*)\/play\/world\/(.*)/; |
160 | 160 |
|
161 | | - it('is built-in', function() { |
| 161 | + it('is built-in', function () { |
162 | 162 | expect(pattern.exec('/players/ericminio/play/world/1')[1]).to.equal('ericminio'); |
163 | 163 | }); |
164 | 164 |
|
165 | | - it('can extract second parameter', function() { |
| 165 | + it('can extract second parameter', function () { |
166 | 166 | expect(pattern.exec('/players/ericminio/play/world/42')[2]).to.equal('42'); |
167 | 167 | }); |
168 | 168 |
|
169 | | - it('returns null when not found', function() { |
| 169 | + it('returns null when not found', function () { |
170 | 170 | expect(pattern.exec('/non/matching')).to.equal(null); |
171 | 171 | }); |
172 | 172 |
|
173 | | - it('can extract a parameter with a dot', function() { |
| 173 | + it('can extract a parameter with a dot', function () { |
174 | 174 | expect(pattern.exec('/players/eric.mignot/play/world/1')[1]).to.equal('eric.mignot'); |
175 | 175 | }); |
176 | 176 | }); |
177 | 177 |
|
178 | | - describe('Regex concatanation', function() { |
| 178 | + describe('Regex concatanation', function () { |
179 | 179 |
|
180 | | - it('works', function() { |
181 | | - var start = /\/any/; |
182 | | - var end = /\/route/; |
183 | | - var pattern = /^/ && start && end && /$/; |
| 180 | + it('works', function () { |
| 181 | + var start = /\/any/; |
| 182 | + var end = /\/route/; |
| 183 | + var pattern = /^/ && start && end && /$/; |
184 | 184 |
|
185 | | - expect(pattern.test('/any/route')).to.equal(true); |
186 | | - }); |
| 185 | + expect(pattern.test('/any/route')).to.equal(true); |
| 186 | + }); |
187 | 187 |
|
188 | | - it('works inline', function() { |
189 | | - var pattern = /^/ && /\/any/ && /\/route/ && /$/; |
| 188 | + it('works inline', function () { |
| 189 | + var pattern = /^/ && /\/any/ && /\/route/ && /$/; |
190 | 190 |
|
191 | | - expect(pattern.test('/any/route')).to.equal(true); |
192 | | - }); |
| 191 | + expect(pattern.test('/any/route')).to.equal(true); |
| 192 | + }); |
193 | 193 | }); |
194 | 194 |
|
195 | | - describe('Regex string spliting', function() { |
| 195 | + describe('Regex string spliting', function () { |
196 | 196 |
|
197 | | - it('can be used to split a string at each space', function() { |
198 | | - expect('Hello world'.split(/\s/)).to.deep.equal(['Hello', 'world']); |
199 | | - }); |
| 197 | + it('can be used to split a string at each space', function () { |
| 198 | + expect('Hello world'.split(/\s/)).to.deep.equal(['Hello', 'world']); |
| 199 | + }); |
200 | 200 |
|
201 | | - it('can be used to split a string at each 2 characters', function() { |
202 | | - expect('Helo'.match(/.{2}/g)).to.deep.equal(['He', 'lo']); |
203 | | - }); |
| 201 | + it('can be used to split a string at each 2 characters', function () { |
| 202 | + expect('Helo'.match(/.{2}/g)).to.deep.equal(['He', 'lo']); |
| 203 | + }); |
204 | 204 |
|
205 | | - it('can be used with a variable', function() { |
206 | | - var length = 2; |
207 | | - var regex = new RegExp('.{' + length + '}', 'g'); |
208 | | - expect('Helo'.match(regex)).to.deep.equal(['He', 'lo']); |
209 | | - }); |
| 205 | + it('can be used with a variable', function () { |
| 206 | + var length = 2; |
| 207 | + var regex = new RegExp('.{' + length + '}', 'g'); |
| 208 | + expect('Helo'.match(regex)).to.deep.equal(['He', 'lo']); |
| 209 | + }); |
210 | 210 | }); |
211 | 211 | }); |
0 commit comments