@@ -116,14 +116,70 @@ test(
116
116
'should reduce additions and subtractions (4)' ,
117
117
testValue ,
118
118
'calc((100vw - 50em) / 2)' ,
119
- 'calc((100vw - 50em)/2 )' ,
119
+ 'calc(50vw - 25em )' ,
120
120
) ;
121
121
122
122
test (
123
123
'should reduce additions and subtractions (5)' ,
124
124
testValue ,
125
125
'calc(10px - (100vw - 50em) / 2)' ,
126
- 'calc(10px - (100vw - 50em)/2)' ,
126
+ 'calc(10px - 50vw + 25em)' ,
127
+ ) ;
128
+
129
+ test (
130
+ 'should reduce additions and subtractions (6)' ,
131
+ testValue ,
132
+ 'calc(1px - (2em + 4vh + 3%))' ,
133
+ 'calc(1px - 2em - 4vh - 3%)' ,
134
+ ) ;
135
+
136
+ test (
137
+ 'should reduce additions and subtractions (7)' ,
138
+ testValue ,
139
+ 'calc(0px - (24px - (var(--a) - var(--b)) / 2 + var(--c)))' ,
140
+ 'calc(-24px + var(--a)/2 - var(--b)/2 - var(--c))' ,
141
+ ) ;
142
+
143
+ test (
144
+ 'should reduce additions and subtractions (8)' ,
145
+ testValue ,
146
+ 'calc(1px + (2em + (3vh + 4px)))' ,
147
+ 'calc(5px + 2em + 3vh)' ,
148
+ ) ;
149
+
150
+ test (
151
+ 'should reduce additions and subtractions (9)' ,
152
+ testValue ,
153
+ 'calc(1px - (2em + 4px - 6vh) / 2)' ,
154
+ 'calc(-1px - 1em + 3vh)' ,
155
+ ) ;
156
+
157
+ test (
158
+ 'should reduce multiplication' ,
159
+ testValue ,
160
+ 'calc(((var(--a) + 4px) * 2) * 2)' ,
161
+ 'calc(var(--a)*2*2 + 16px)' ,
162
+ ) ;
163
+
164
+ test (
165
+ 'should reduce multiplication before reducing additions' ,
166
+ testValue ,
167
+ 'calc(((var(--a) + 4px) * 2) * 2 + 4px)' ,
168
+ 'calc(var(--a)*2*2 + 20px)' ,
169
+ ) ;
170
+
171
+ test (
172
+ 'should reduce division' ,
173
+ testValue ,
174
+ 'calc(((var(--a) + 4px) / 2) / 2)' ,
175
+ 'calc(var(--a)/2/2 + 1px)' ,
176
+ ) ;
177
+
178
+ test (
179
+ 'should reduce division before reducing additions' ,
180
+ testValue ,
181
+ 'calc(((var(--a) + 4px) / 2) / 2 + 4px)' ,
182
+ 'calc(var(--a)/2/2 + 5px)' ,
127
183
) ;
128
184
129
185
test (
@@ -243,7 +299,7 @@ test(
243
299
'should ignore calc with css variables (7)' ,
244
300
testValue ,
245
301
'calc(var(--popupHeight) / 2 + var(--popupWidth) / 2)' ,
246
- 'calc(( var(--popupHeight) + var(--popupWidth) )/2)' ,
302
+ 'calc(var(--popupHeight)/2 + var(--popupWidth)/2)' ,
247
303
) ;
248
304
249
305
@@ -372,35 +428,35 @@ test(
372
428
'should reduce subtracted expression from zero' ,
373
429
testValue ,
374
430
'calc( 0 - calc(1px + 1em) )' ,
375
- 'calc(-1px + - 1em)' ,
431
+ 'calc(-1px - 1em)' ,
376
432
) ;
377
433
378
434
test (
379
435
'should reduce substracted expression from zero (1)' ,
380
436
testValue ,
381
437
'calc( 0 - (100vw - 10px) / 2 )' ,
382
- 'calc((-100vw - -10px)/2 )' ,
438
+ 'calc(-50vw + 5px )' ,
383
439
) ;
384
440
385
441
test (
386
442
'should reduce substracted expression from zero (2)' ,
387
443
testValue ,
388
444
'calc( 0px - (100vw - 10px))' ,
389
- 'calc(-100vw - -10px )' ,
445
+ 'calc(10px - 100vw )' ,
390
446
) ;
391
447
392
448
test (
393
449
'should reduce substracted expression from zero (3)' ,
394
450
testValue ,
395
- 'calc( 0px - (100vw - 10px) * 2px )' ,
396
- 'calc((-100vw - -10px)*2px )' ,
451
+ 'calc( 0px - (100vw - 10px) * 2 )' ,
452
+ 'calc(20px - 200vw )' ,
397
453
) ;
398
454
399
455
test (
400
456
'should reduce substracted expression from zero (4)' ,
401
457
testValue ,
402
458
'calc( 0px - (100vw + 10px))' ,
403
- 'calc(-100vw + -10px )' ,
459
+ 'calc(-10px - 100vw )' ,
404
460
) ;
405
461
406
462
test (
@@ -587,14 +643,14 @@ test(
587
643
'should handle complex calculations (reduce-css-calc#45) (1)' ,
588
644
testValue ,
589
645
'calc(100% + (2 * 100px) - ((75.37% - 63.5px) - 900px))' ,
590
- 'calc(100% + 200px - 75.37 % + 963 .5px)' ,
646
+ 'calc(24.63 % + 1163 .5px)' ,
591
647
) ;
592
648
593
649
test (
594
650
'should handle complex calculations (reduce-css-calc#45) (2)' ,
595
651
testValue ,
596
652
'calc(((((100% + (2 * 30px) + 63.5px) / 0.7537) - (100vw - 60px)) / 2) + 30px)' ,
597
- 'calc(((100 % + 123.5px)/0.7537 - 100vw + 60px)/2 + 30px )' ,
653
+ 'calc(66.33939 % + 141.92915px - 50vw )' ,
598
654
) ;
599
655
600
656
test (
@@ -783,7 +839,7 @@ test(
783
839
'should handle nested calc function (#13)' ,
784
840
testValue ,
785
841
'calc(100vh - 5rem - calc(10rem + 100px))' ,
786
- 'calc(100vh - 5rem - 10rem - 100px)' ,
842
+ 'calc(100vh - 15rem - 100px)' ,
787
843
) ;
788
844
789
845
test (
0 commit comments