1- import test from 'ava' ;
1+ import test from 'ava'
22
3- import reduceCalc from '..' ;
3+ import reduceCalc from '..'
44
55function testFixture ( t , fixture , expected = null , precision = 5 ) {
66 if ( expected === null )
7- expected = fixture ;
7+ expected = fixture
88
9- const out = reduceCalc ( fixture , precision ) ;
10- t . deepEqual ( out , expected ) ;
9+ const out = reduceCalc ( fixture , precision )
10+ t . deepEqual ( out , expected )
1111}
1212
1313function testThrows ( t , fixture , expected , precision = 5 ) {
14- t . throws ( ( ) => reduceCalc ( fixture , precision ) , expected ) ;
14+ t . throws ( ( ) => reduceCalc ( fixture , precision ) , expected )
1515}
1616
1717test (
1818 'should reduce simple calc (1)' ,
1919 testFixture ,
2020 'calc(1px + 1px)' ,
2121 '2px'
22- ) ;
22+ )
2323
2424test (
2525 'should reduce simple calc (2)' ,
2626 testFixture ,
2727 'calc(3em - 1em)' ,
2828 '2em'
29- ) ;
29+ )
3030
3131test (
3232 'should reduce simple calc (3)' ,
3333 testFixture ,
3434 'calc(1rem * 1.5)' ,
3535 '1.5rem'
36- ) ;
36+ )
3737
3838test (
3939 'should reduce simple calc (4)' ,
4040 testFixture ,
4141 'calc(2ex / 2)' ,
4242 '1ex'
43- ) ;
43+ )
4444
4545test (
4646 'should ignore value surrounding calc function (1)' ,
4747 testFixture ,
4848 'a calc(1px + 1px)' ,
4949 'a 2px'
50- ) ;
50+ )
5151
5252test (
5353 'should ignore value surrounding calc function (2)' ,
5454 testFixture ,
5555 'calc(1px + 1px) a' ,
5656 '2px a'
57- ) ;
57+ )
5858
5959test (
6060 'should ignore value surrounding calc function (3)' ,
6161 testFixture ,
6262 'a calc(1px + 1px) b' ,
6363 'a 2px b'
64- ) ;
64+ )
6565
6666test (
6767 'should ignore value surrounding calc function (4)' ,
6868 testFixture ,
6969 'a calc(1px + 1px) b calc(1em + 2em) c' ,
7070 'a 2px b 3em c'
71- ) ;
71+ )
7272
7373test (
7474 'should reduce calc with newline characters' ,
7575 testFixture ,
7676 'calc(\n1rem \n* 2 \n* 1.5)' ,
7777 '3rem'
78- ) ;
78+ )
7979
8080test (
8181 'should preserve calc with incompatible units' ,
8282 testFixture ,
8383 'calc(100% + 1px)' ,
8484 'calc(100% + 1px)'
85- ) ;
85+ )
8686
8787test (
8888 'should parse fractions without leading zero' ,
8989 testFixture ,
9090 'calc(2rem - .14285em)' ,
9191 'calc(2rem - 0.14285em)'
92- ) ;
92+ )
9393
9494test (
9595 'should handle precision correctly (1)' ,
9696 testFixture ,
9797 'calc(1/100)' ,
9898 '0.01'
99- ) ;
99+ )
100100
101101test (
102102 'should handle precision correctly (2)' ,
103103 testFixture ,
104104 'calc(5/1000000)' ,
105105 '0.00001'
106- ) ;
106+ )
107107
108108test (
109109 'should handle precision correctly (3)' ,
110110 testFixture ,
111111 'calc(5/1000000)' ,
112112 '0.000005' ,
113113 6
114- ) ;
114+ )
115115
116116test (
117117 'should reduce browser-prefixed calc (1)' ,
118118 testFixture ,
119119 '-webkit-calc(1px + 1px)' ,
120120 '2px'
121- ) ;
121+ )
122122
123123test (
124124 'should reduce browser-prefixed calc (2)' ,
125125 testFixture ,
126126 '-moz-calc(1px + 1px)' ,
127127 '2px'
128- ) ;
128+ )
129129
130130test (
131131 'should discard zero values (#2) (1)' ,
132132 testFixture ,
133133 'calc(100vw / 2 - 6px + 0px)' ,
134134 'calc(50vw - 6px)'
135- ) ;
135+ )
136136
137137test (
138138 'should discard zero values (#2) (2)' ,
139139 testFixture ,
140140 'calc(500px - 0px)' ,
141141 '500px'
142- ) ;
142+ )
143143
144144test (
145145 'should not perform addition on unitless values (#3)' ,
146146 testFixture ,
147147 'calc(1px + 1)' ,
148148 'calc(1px + 1)'
149- ) ;
149+ )
150150
151151
152152test (
@@ -155,54 +155,54 @@ test(
155155 'calc(14px + 6 * ((100vw - 320px) / 448))' ,
156156 'calc(9.71px + 1.34vw)' ,
157157 2
158- ) ;
158+ )
159159
160160test (
161161 'should produce simpler result (postcss-calc#25) (2)' ,
162162 testFixture ,
163163 '-webkit-calc(14px + 6 * ((100vw - 320px) / 448))' ,
164164 '-webkit-calc(9.71px + 1.34vw)' ,
165165 2
166- ) ;
166+ )
167167
168168test (
169169 'should reduce mixed units of time (postcss-calc#33)' ,
170170 testFixture ,
171171 'calc(1s - 50ms)' ,
172172 '0.95s'
173- ) ;
173+ )
174174
175175test (
176176 'should correctly reduce calc with mixed units (cssnano#211)' ,
177177 testFixture ,
178178 'bar:calc(99.99% * 1/1 - 0rem)' ,
179179 'bar:99.99%'
180- ) ;
180+ )
181181
182182test (
183183 'should apply algebraic reduction (cssnano#319)' ,
184184 testFixture ,
185185 'bar:calc((100px - 1em) + (-50px + 1em))' ,
186186 'bar:50px'
187- ) ;
187+ )
188188
189189test (
190190 'should apply optimization (cssnano#320)' ,
191191 testFixture ,
192192 'bar:calc(50% + (5em + 5%))' ,
193193 'bar:calc(55% + 5em)'
194- ) ;
194+ )
195195
196196test (
197197 'should throw an exception when attempting to divide by zero' ,
198198 testThrows ,
199199 'calc(500px/0)' ,
200200 / C a n n o t d i v i d e b y z e r o /
201- ) ;
201+ )
202202
203203test (
204204 'should throw an exception when attempting to divide by unit (#1)' ,
205205 testThrows ,
206206 'calc(500px/2px)' ,
207207 'Cannot divide by "px", number expected'
208- ) ;
208+ )
0 commit comments