1
- import test from 'ava' ;
1
+ import test from 'ava'
2
2
3
- import reduceCalc from '..' ;
3
+ import reduceCalc from '..'
4
4
5
5
function testFixture ( t , fixture , expected = null , precision = 5 ) {
6
6
if ( expected === null )
7
- expected = fixture ;
7
+ expected = fixture
8
8
9
- const out = reduceCalc ( fixture , precision ) ;
10
- t . deepEqual ( out , expected ) ;
9
+ const out = reduceCalc ( fixture , precision )
10
+ t . deepEqual ( out , expected )
11
11
}
12
12
13
13
function testThrows ( t , fixture , expected , precision = 5 ) {
14
- t . throws ( ( ) => reduceCalc ( fixture , precision ) , expected ) ;
14
+ t . throws ( ( ) => reduceCalc ( fixture , precision ) , expected )
15
15
}
16
16
17
17
test (
18
18
'should reduce simple calc (1)' ,
19
19
testFixture ,
20
20
'calc(1px + 1px)' ,
21
21
'2px'
22
- ) ;
22
+ )
23
23
24
24
test (
25
25
'should reduce simple calc (2)' ,
26
26
testFixture ,
27
27
'calc(3em - 1em)' ,
28
28
'2em'
29
- ) ;
29
+ )
30
30
31
31
test (
32
32
'should reduce simple calc (3)' ,
33
33
testFixture ,
34
34
'calc(1rem * 1.5)' ,
35
35
'1.5rem'
36
- ) ;
36
+ )
37
37
38
38
test (
39
39
'should reduce simple calc (4)' ,
40
40
testFixture ,
41
41
'calc(2ex / 2)' ,
42
42
'1ex'
43
- ) ;
43
+ )
44
44
45
45
test (
46
46
'should ignore value surrounding calc function (1)' ,
47
47
testFixture ,
48
48
'a calc(1px + 1px)' ,
49
49
'a 2px'
50
- ) ;
50
+ )
51
51
52
52
test (
53
53
'should ignore value surrounding calc function (2)' ,
54
54
testFixture ,
55
55
'calc(1px + 1px) a' ,
56
56
'2px a'
57
- ) ;
57
+ )
58
58
59
59
test (
60
60
'should ignore value surrounding calc function (3)' ,
61
61
testFixture ,
62
62
'a calc(1px + 1px) b' ,
63
63
'a 2px b'
64
- ) ;
64
+ )
65
65
66
66
test (
67
67
'should ignore value surrounding calc function (4)' ,
68
68
testFixture ,
69
69
'a calc(1px + 1px) b calc(1em + 2em) c' ,
70
70
'a 2px b 3em c'
71
- ) ;
71
+ )
72
72
73
73
test (
74
74
'should reduce calc with newline characters' ,
75
75
testFixture ,
76
76
'calc(\n1rem \n* 2 \n* 1.5)' ,
77
77
'3rem'
78
- ) ;
78
+ )
79
79
80
80
test (
81
81
'should preserve calc with incompatible units' ,
82
82
testFixture ,
83
83
'calc(100% + 1px)' ,
84
84
'calc(100% + 1px)'
85
- ) ;
85
+ )
86
86
87
87
test (
88
88
'should parse fractions without leading zero' ,
89
89
testFixture ,
90
90
'calc(2rem - .14285em)' ,
91
91
'calc(2rem - 0.14285em)'
92
- ) ;
92
+ )
93
93
94
94
test (
95
95
'should handle precision correctly (1)' ,
96
96
testFixture ,
97
97
'calc(1/100)' ,
98
98
'0.01'
99
- ) ;
99
+ )
100
100
101
101
test (
102
102
'should handle precision correctly (2)' ,
103
103
testFixture ,
104
104
'calc(5/1000000)' ,
105
105
'0.00001'
106
- ) ;
106
+ )
107
107
108
108
test (
109
109
'should handle precision correctly (3)' ,
110
110
testFixture ,
111
111
'calc(5/1000000)' ,
112
112
'0.000005' ,
113
113
6
114
- ) ;
114
+ )
115
115
116
116
test (
117
117
'should reduce browser-prefixed calc (1)' ,
118
118
testFixture ,
119
119
'-webkit-calc(1px + 1px)' ,
120
120
'2px'
121
- ) ;
121
+ )
122
122
123
123
test (
124
124
'should reduce browser-prefixed calc (2)' ,
125
125
testFixture ,
126
126
'-moz-calc(1px + 1px)' ,
127
127
'2px'
128
- ) ;
128
+ )
129
129
130
130
test (
131
131
'should discard zero values (#2) (1)' ,
132
132
testFixture ,
133
133
'calc(100vw / 2 - 6px + 0px)' ,
134
134
'calc(50vw - 6px)'
135
- ) ;
135
+ )
136
136
137
137
test (
138
138
'should discard zero values (#2) (2)' ,
139
139
testFixture ,
140
140
'calc(500px - 0px)' ,
141
141
'500px'
142
- ) ;
142
+ )
143
143
144
144
test (
145
145
'should not perform addition on unitless values (#3)' ,
146
146
testFixture ,
147
147
'calc(1px + 1)' ,
148
148
'calc(1px + 1)'
149
- ) ;
149
+ )
150
150
151
151
152
152
test (
@@ -155,54 +155,54 @@ test(
155
155
'calc(14px + 6 * ((100vw - 320px) / 448))' ,
156
156
'calc(9.71px + 1.34vw)' ,
157
157
2
158
- ) ;
158
+ )
159
159
160
160
test (
161
161
'should produce simpler result (postcss-calc#25) (2)' ,
162
162
testFixture ,
163
163
'-webkit-calc(14px + 6 * ((100vw - 320px) / 448))' ,
164
164
'-webkit-calc(9.71px + 1.34vw)' ,
165
165
2
166
- ) ;
166
+ )
167
167
168
168
test (
169
169
'should reduce mixed units of time (postcss-calc#33)' ,
170
170
testFixture ,
171
171
'calc(1s - 50ms)' ,
172
172
'0.95s'
173
- ) ;
173
+ )
174
174
175
175
test (
176
176
'should correctly reduce calc with mixed units (cssnano#211)' ,
177
177
testFixture ,
178
178
'bar:calc(99.99% * 1/1 - 0rem)' ,
179
179
'bar:99.99%'
180
- ) ;
180
+ )
181
181
182
182
test (
183
183
'should apply algebraic reduction (cssnano#319)' ,
184
184
testFixture ,
185
185
'bar:calc((100px - 1em) + (-50px + 1em))' ,
186
186
'bar:50px'
187
- ) ;
187
+ )
188
188
189
189
test (
190
190
'should apply optimization (cssnano#320)' ,
191
191
testFixture ,
192
192
'bar:calc(50% + (5em + 5%))' ,
193
193
'bar:calc(55% + 5em)'
194
- ) ;
194
+ )
195
195
196
196
test (
197
197
'should throw an exception when attempting to divide by zero' ,
198
198
testThrows ,
199
199
'calc(500px/0)' ,
200
200
/ C a n n o t d i v i d e b y z e r o /
201
- ) ;
201
+ )
202
202
203
203
test (
204
204
'should throw an exception when attempting to divide by unit (#1)' ,
205
205
testThrows ,
206
206
'calc(500px/2px)' ,
207
207
'Cannot divide by "px", number expected'
208
- ) ;
208
+ )
0 commit comments