@@ -48,6 +48,14 @@ test('gives an error when @value statement is invalid', async (t) => {
48
48
await t . throws ( processor . process ( input , parserOpts ) ) ;
49
49
} ) ;
50
50
51
+ test ( 'shouldn\'t break on draft spec syntax' , async ( t ) => {
52
+ await run (
53
+ t ,
54
+ '.foo { width: calc(2+2); }' ,
55
+ '.foo { width: calc(2+2); }' ,
56
+ ) ;
57
+ } ) ;
58
+
51
59
test ( 'should replace constants within the file' , async ( t ) => {
52
60
await run (
53
61
t ,
@@ -56,6 +64,14 @@ test('should replace constants within the file', async (t) => {
56
64
) ;
57
65
} ) ;
58
66
67
+ test ( 'shouldn\'t replace number-like values' , async ( t ) => {
68
+ await run (
69
+ t ,
70
+ '@value 3char #000; .foo { color: 3char; }' ,
71
+ '@value 3char #000; .foo { color: 3char; }' ,
72
+ ) ;
73
+ } ) ;
74
+
59
75
test ( 'shouldn\'t replace selector' , async ( t ) => {
60
76
await run (
61
77
t ,
@@ -72,6 +88,22 @@ test('shouldn\'t replace inside url', async (t) => {
72
88
) ;
73
89
} ) ;
74
90
91
+ test ( 'should replace within calc' , async ( t ) => {
92
+ await run (
93
+ t ,
94
+ '@value base: 10px;\n.a { margin: calc(base * 2); }' ,
95
+ '@value base: 10px;\n.a { margin: calc(10px * 2); }' ,
96
+ ) ;
97
+ } ) ;
98
+
99
+ test ( 'should replace within calc without spaces' , async ( t ) => {
100
+ await run (
101
+ t ,
102
+ '@value base: 10px;\n.a { margin: calc(base*2); }' ,
103
+ '@value base: 10px;\n.a { margin: calc(10px*2); }' ,
104
+ ) ;
105
+ } ) ;
106
+
75
107
test ( 'should replace two constants with same name within the file and the latter should win' , async ( t ) => {
76
108
await run (
77
109
t ,
@@ -191,6 +223,22 @@ test('should allow transitive values within calc', async (t) => {
191
223
) ;
192
224
} ) ;
193
225
226
+ test ( 'should allow transitive values within calc without spaces' , async ( t ) => {
227
+ await run (
228
+ t ,
229
+ '@value base: 10px;\n@value large: calc(base*2);\n.a { margin: large; }' ,
230
+ '@value base: 10px;\n@value large: calc(10px*2);\n.a { margin: calc(10px*2); }' ,
231
+ ) ;
232
+ } ) ;
233
+
234
+ test ( 'should replace inside custom properties' , async ( t ) => {
235
+ await run (
236
+ t ,
237
+ '@value path: test.png;\n:root {--path: path};\n.foo { background-image: url(var(--path)); }' ,
238
+ '@value path: test.png;\n:root {--path: test.png};\n.foo { background-image: url(var(--path)); }' ,
239
+ ) ;
240
+ } ) ;
241
+
194
242
test ( 'should allow custom-property-style names' , async ( t ) => {
195
243
await run (
196
244
t ,
@@ -202,9 +250,9 @@ test('should allow custom-property-style names', async (t) => {
202
250
test ( 'should allow all colour types' , async ( t ) => {
203
251
await run (
204
252
t ,
205
- '@value named: red; @value 3char #0f0; @value 6char #00ff00; @value rgba rgba(34, 12, 64, 0.3); @value hsla hsla(220, 13.0%, 18.0%, 1);\n' +
206
- '.foo { color: named; background-color: 3char ; border-top-color: 6char ; border-bottom-color: rgba; outline-color: hsla; }' ,
207
- '@value named: red; @value 3char #0f0; @value 6char #00ff00; @value rgba rgba(34, 12, 64, 0.3); @value hsla hsla(220, 13.0%, 18.0%, 1);\n' +
253
+ '@value named: red; @value hex3char #0f0; @value hex6char #00ff00; @value rgba rgba(34, 12, 64, 0.3); @value hsla hsla(220, 13.0%, 18.0%, 1);\n' +
254
+ '.foo { color: named; background-color: hex3char ; border-top-color: hex6char ; border-bottom-color: rgba; outline-color: hsla; }' ,
255
+ '@value named: red; @value hex3char #0f0; @value hex6char #00ff00; @value rgba rgba(34, 12, 64, 0.3); @value hsla hsla(220, 13.0%, 18.0%, 1);\n' +
208
256
'.foo { color: red; background-color: #0f0; border-top-color: #00ff00; border-bottom-color: rgba(34, 12, 64, 0.3); outline-color: hsla(220, 13.0%, 18.0%, 1); }' ,
209
257
) ;
210
258
} ) ;
0 commit comments