Skip to content

Commit 9334b30

Browse files
committed
Require space after + and - modifiers
1 parent 64e875b commit 9334b30

File tree

3 files changed

+115
-14
lines changed

3 files changed

+115
-14
lines changed

lib/parse.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,7 @@ function parse (string) {
6161
*/
6262

6363
function modifier () {
64-
var m = match(/^([\+\-\*])/);
64+
var m = match(/^([\+\-](?= )|\*)/);
6565
if (!m) return;
6666
var ret = {};
6767
ret.type = 'modifier';
@@ -185,4 +185,4 @@ function parse (string) {
185185
*/
186186

187187
return fn();
188-
}
188+
}

test/convert.js

Lines changed: 22 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -150,12 +150,16 @@ describe('#convert', function () {
150150
convert('hsl(34, 50%, 50%) hue(25)', 'rgb(191, 117, 64)');
151151
});
152152

153+
it('should set hue with explicit positive', function () {
154+
convert('hsl(34, 50%, 50%) hue(+25)', 'rgb(191, 117, 64)');
155+
});
156+
153157
it('should set hue greater than 360', function () {
154158
convert('hsl(34, 50%, 50%) hue(385)', 'rgb(191, 117, 64)');
155159
});
156160

157161
it('should set hue less than 360', function () {
158-
convert('hsl(34, 50%, 50%) hue(-369)', 'rgb(191, 117, 64)');
162+
convert('hsl(34, 50%, 50%) hue(- 369)', 'rgb(191, 117, 64)');
159163
});
160164

161165
it('should add hue', function () {
@@ -188,7 +192,7 @@ describe('#convert', function () {
188192
convert('hsl(25, 25%, 50%) saturation(+ 25%)', 'rgb(191, 117, 64)');
189193
});
190194

191-
it('should substract saturation', function () {
195+
it('should subtract saturation', function () {
192196
convert('hsl(25, 60%, 50%) saturation(- 10%)', 'rgb(191, 117, 64)');
193197
});
194198

@@ -206,7 +210,7 @@ describe('#convert', function () {
206210
convert('hsl(25, 50%, 25%) lightness(+ 25%)', 'rgb(191, 117, 64)');
207211
});
208212

209-
it('should substract lightness', function () {
213+
it('should subtract lightness', function () {
210214
convert('hsl(25, 50%, 60%) lightness(- 10%)', 'rgb(191, 117, 64)');
211215
});
212216

@@ -220,12 +224,16 @@ describe('#convert', function () {
220224
convert('hwb(0, 0%, 0%) whiteness(20%)', 'rgb(255, 51, 51)'); // hwb(0, 20%, 0%)
221225
});
222226

227+
it('should set whiteness with explicit positive', function () {
228+
convert('hwb(0, 0%, 0%) whiteness(+20%)', 'rgb(255, 51, 51)'); // hwb(0, 20%, 0%)
229+
});
230+
223231
it('should add whiteness', function () {
224-
convert('hwb(0, 75%, 0%) whiteness(+25%)', 'rgb(255, 255, 255)'); // hwb(0, 100%, 0%)
232+
convert('hwb(0, 75%, 0%) whiteness(+ 25%)', 'rgb(255, 255, 255)'); // hwb(0, 100%, 0%)
225233
});
226234

227-
it('should substract whiteness', function () {
228-
convert('hwb(0, 30%, 0%) whiteness(-10%)', 'rgb(255, 51, 51)'); // hwb(0, 20%, 0%)
235+
it('should subtract whiteness', function () {
236+
convert('hwb(0, 30%, 0%) whiteness(- 10%)', 'rgb(255, 51, 51)'); // hwb(0, 20%, 0%)
229237
});
230238

231239
it('should multiply whiteness', function () {
@@ -238,12 +246,16 @@ describe('#convert', function () {
238246
convert('hwb(0, 0%, 0%) blackness(20%)', 'rgb(204, 0, 0)'); // hwb(0, 0%, 20%)
239247
});
240248

249+
it('should set blackness with explicit positive', function () {
250+
convert('hwb(0, 0%, 0%) blackness(+20%)', 'rgb(204, 0, 0)'); // hwb(0, 0%, 20%)
251+
});
252+
241253
it('should add blackness', function () {
242-
convert('hwb(0, 0%, 75%) blackness(+25%)', 'rgb(0, 0, 0)'); // hwb(0, 0%, 100%)
254+
convert('hwb(0, 0%, 75%) blackness(+ 25%)', 'rgb(0, 0, 0)'); // hwb(0, 0%, 100%)
243255
});
244256

245-
it('should substract blackness', function () {
246-
convert('hwb(0, 0%, 30%) blackness(-10%)', 'rgb(204, 0, 0)'); // hwb(0, 0%, 20%)
257+
it('should subtract blackness', function () {
258+
convert('hwb(0, 0%, 30%) blackness(- 10%)', 'rgb(204, 0, 0)'); // hwb(0, 0%, 20%)
247259
});
248260

249261
it('should multiply blackness', function () {
@@ -289,7 +301,7 @@ describe('#convert', function () {
289301

290302
describe('nested color functions', function () {
291303
it('should convert nested color functions', function () {
292-
convert('color(rebeccapurple a(-10%)) a(-10%)', 'rgba(102, 51, 153, 0.81)');
304+
convert('color(rebeccapurple a(- 10%)) a(- 10%)', 'rgba(102, 51, 153, 0.81)');
293305
convert('color(#4C5859 shade(25%)) blend(color(#4C5859 shade(40%)) 20%)', 'rgb(55, 63, 64)');
294306
});
295307
});

test/parse.js

Lines changed: 91 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -191,7 +191,7 @@ describe('#parse', function () {
191191
});
192192

193193
it('should parse nested color functions', function () {
194-
parse('color(hsl(0, 0%, 93%) l(-5%)) l(+10%)', {
194+
parse('color(hsl(0, 0%, 93%) l(- 5%)) l(+ 10%)', {
195195
type: 'function',
196196
name: 'color',
197197
arguments: [
@@ -237,6 +237,95 @@ describe('#parse', function () {
237237
});
238238
});
239239

240+
it('should properly parse modifiers', function () {
241+
parse('red a(+ 5%) a(+5%) a(- 5%) a(-5%) a(* 50%) a(*50%)', {
242+
type: 'function',
243+
name: 'color',
244+
arguments: [
245+
{
246+
type: 'color',
247+
value: 'red',
248+
},
249+
{
250+
type: 'function',
251+
name: 'a',
252+
arguments: [
253+
{
254+
type: 'modifier',
255+
value: '+'
256+
},
257+
{
258+
type: 'number',
259+
value: '5%'
260+
}
261+
]
262+
},
263+
{
264+
type: 'function',
265+
name: 'a',
266+
arguments: [
267+
{
268+
type: 'number',
269+
value: '+5%'
270+
}
271+
]
272+
},
273+
{
274+
type: 'function',
275+
name: 'a',
276+
arguments: [
277+
{
278+
type: 'modifier',
279+
value: '-'
280+
},
281+
{
282+
type: 'number',
283+
value: '5%'
284+
}
285+
]
286+
},
287+
{
288+
type: 'function',
289+
name: 'a',
290+
arguments: [
291+
{
292+
type: 'number',
293+
value: '-5%'
294+
}
295+
]
296+
},
297+
{
298+
type: 'function',
299+
name: 'a',
300+
arguments: [
301+
{
302+
type: 'modifier',
303+
value: '*'
304+
},
305+
{
306+
type: 'number',
307+
value: '50%'
308+
}
309+
]
310+
},
311+
{
312+
type: 'function',
313+
name: 'a',
314+
arguments: [
315+
{
316+
type: 'modifier',
317+
value: '*'
318+
},
319+
{
320+
type: 'number',
321+
value: '50%'
322+
}
323+
]
324+
}
325+
]
326+
});
327+
})
328+
240329

241330
it('should throw on syntax error', function () {
242331
assert.throws(function () {
@@ -246,7 +335,7 @@ describe('#parse', function () {
246335

247336
it('should throw on syntax error for adjuster', function () {
248337
assert.throws(function () {
249-
color.parse('color(red l(+5%)');
338+
color.parse('color(red l(+ 5%)');
250339
}, /Missing closing parenthese for/);
251340
});
252341

0 commit comments

Comments
 (0)