Skip to content

Commit bac935b

Browse files
Calc functions tests (#1912)
* Sqrt calc function test * Pow calc function * Round calc tests * Unary calc functions tests * Arguments with no units correction * Refactor round function * Add round three-args tests * Return incompatible message fix * Add wpt tests
1 parent 08eb143 commit bac935b

29 files changed

+4976
-89
lines changed

spec/core_functions/math/abs.hrx

Lines changed: 43 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,13 @@
1+
<===> options.yml
2+
---
3+
:ignore_for:
4+
- libsass
5+
6+
<===>
7+
================================================================================
18
<===> zero/input.scss
2-
a {b: abs(0)}
9+
@use "sass:math";
10+
a {b: math.abs(0)}
311

412
<===> zero/output.css
513
a {
@@ -9,7 +17,8 @@ a {
917
<===>
1018
================================================================================
1119
<===> positive/integer/input.scss
12-
a {b: abs(1)}
20+
@use "sass:math";
21+
a {b: math.abs(1)}
1322

1423
<===> positive/integer/output.css
1524
a {
@@ -19,7 +28,8 @@ a {
1928
<===>
2029
================================================================================
2130
<===> positive/decimal/input.scss
22-
a {b: abs(5.6)}
31+
@use "sass:math";
32+
a {b: math.abs(5.6)}
2333

2434
<===> positive/decimal/output.css
2535
a {
@@ -29,7 +39,8 @@ a {
2939
<===>
3040
================================================================================
3141
<===> negative/integer/input.scss
32-
a {b: abs(-17)}
42+
@use "sass:math";
43+
a {b: math.abs(-17)}
3344

3445
<===> negative/integer/output.css
3546
a {
@@ -39,7 +50,8 @@ a {
3950
<===>
4051
================================================================================
4152
<===> negative/decimal/input.scss
42-
a {b: abs(-123.456)}
53+
@use "sass:math";
54+
a {b: math.abs(-123.456)}
4355

4456
<===> negative/decimal/output.css
4557
a {
@@ -53,7 +65,8 @@ a {
5365
- sass/libsass#2887
5466

5567
<===> preserves_units/input.scss
56-
a {b: abs(-7px / 4em) * 1em}
68+
@use "sass:math";
69+
a {b: math.abs(-7px / 4em) * 1em}
5770

5871
<===> preserves_units/output.css
5972
a {
@@ -68,15 +81,16 @@ Recommendation: math.div(-7px, 4em)
6881
More info and automated migrator: https://sass-lang.com/d/slash-div
6982

7083
,
71-
1 | a {b: abs(-7px / 4em) * 1em}
72-
| ^^^^^^^^^^
84+
2 | a {b: math.abs(-7px / 4em) * 1em}
85+
| ^^^^^^^^^^
7386
'
74-
input.scss 1:11 root stylesheet
87+
input.scss 2:16 root stylesheet
7588

7689
<===>
7790
================================================================================
7891
<===> named/input.scss
79-
a {b: abs($number: -3)}
92+
@use "sass:math";
93+
a { b: math.abs($number: 3)}
8094

8195
<===> named/output.css
8296
a {
@@ -86,69 +100,71 @@ a {
86100
<===>
87101
================================================================================
88102
<===> error/type/input.scss
89-
a {b: abs(c)}
103+
@use "sass:math";
104+
a {b: math.abs(c)}
90105

91106
<===> error/type/error
92107
Error: $number: c is not a number.
93108
,
94-
1 | a {b: abs(c)}
95-
| ^^^^^^
109+
2 | a {b: math.abs(c)}
110+
| ^^^^^^^^^^^
96111
'
97-
input.scss 1:7 root stylesheet
112+
input.scss 2:7 root stylesheet
98113

99114
<===> error/type/error-libsass
100-
Error: argument `$number` of `abs($number)` must be a number
115+
Error: argument `$number` of `math.abs($number)` must be a number
101116
on line 1:7 of input.scss, in function `round`
102117
from line 1:7 of input.scss
103-
>> a {b: abs(c)}
118+
>> a {b: math.abs(c)}
104119

105120
------^
106121

107122
<===>
108123
================================================================================
109124
<===> error/too_few_args/input.scss
110-
a {b: abs()}
125+
@use "sass:math";
126+
a {b: math.abs()}
111127

112128
<===> error/too_few_args/error
113129
Error: Missing argument $number.
114130
,--> input.scss
115-
1 | a {b: abs()}
116-
| ^^^^^ invocation
131+
2 | a {b: math.abs()}
132+
| ^^^^^^^^^^ invocation
117133
'
118134
,--> sass:math
119135
1 | @function abs($number) {
120136
| ============ declaration
121137
'
122-
input.scss 1:7 root stylesheet
138+
input.scss 2:7 root stylesheet
123139

124140
<===> error/too_few_args/error-libsass
125141
Error: Function abs is missing argument $number.
126142
on line 1 of input.scss
127-
>> a {b: abs()}
143+
>> a {b: math.abs()}
128144

129145
------^
130146

131147
<===>
132148
================================================================================
133149
<===> error/too_many_args/input.scss
134-
a {b: abs(1, 2)}
135-
150+
@use "sass:math";
151+
a {b: math.abs(1, 2)}
136152

137153
<===> error/too_many_args/error
138154
Error: Only 1 argument allowed, but 2 were passed.
139155
,--> input.scss
140-
1 | a {b: abs(1, 2)}
141-
| ^^^^^^^^^ invocation
156+
2 | a {b: math.abs(1, 2)}
157+
| ^^^^^^^^^^^^^^ invocation
142158
'
143159
,--> sass:math
144160
1 | @function abs($number) {
145161
| ============ declaration
146162
'
147-
input.scss 1:7 root stylesheet
163+
input.scss 2:7 root stylesheet
148164

149165
<===> error/too_many_args/error-libsass
150166
Error: wrong number of arguments (2 for 1) for `abs'
151167
on line 1:7 of input.scss
152-
>> a {b: abs(1, 2)}
168+
>> a {b: math.abs(1, 2)}
153169

154170
------^

spec/core_functions/math/round.hrx

Lines changed: 47 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,13 @@
1+
<===> options.yml
2+
---
3+
:ignore_for:
4+
- libsass
5+
6+
<===>
7+
================================================================================
18
<===> integer/input.scss
2-
a {b: round(1)}
9+
@use "sass:math";
10+
a {b: math.round(1)}
311

412
<===> integer/output.css
513
a {
@@ -9,7 +17,8 @@ a {
917
<===>
1018
================================================================================
1119
<===> up/high/input.scss
12-
a {b: round(2.9)}
20+
@use "sass:math";
21+
a {b: math.round(2.9)}
1322

1423
<===> up/high/output.css
1524
a {
@@ -19,7 +28,8 @@ a {
1928
<===>
2029
================================================================================
2130
<===> up/point_five/input.scss
22-
a {b: round(16.5)}
31+
@use "sass:math";
32+
a {b: math.round(16.5)}
2333

2434
<===> up/point_five/output.css
2535
a {
@@ -29,7 +39,8 @@ a {
2939
<===>
3040
================================================================================
3141
<===> up/negative/input.scss
32-
a {b: round(-5.4)}
42+
@use "sass:math";
43+
a {b: math.round(-5.4)}
3344

3445
<===> up/negative/output.css
3546
a {
@@ -39,7 +50,8 @@ a {
3950
<===>
4051
================================================================================
4152
<===> up/to_zero/input.scss
42-
a {b: round(-0.2)}
53+
@use "sass:math";
54+
a {b: math.round(-0.2)}
4355

4456
<===> up/to_zero/output.css
4557
a {
@@ -49,7 +61,8 @@ a {
4961
<===>
5062
================================================================================
5163
<===> down/low/input.scss
52-
a {b: round(2.2)}
64+
@use "sass:math";
65+
a {b: math.round(2.2)}
5366

5467
<===> down/low/output.css
5568
a {
@@ -59,7 +72,8 @@ a {
5972
<===>
6073
================================================================================
6174
<===> down/negative/input.scss
62-
a {b: round(-5.6)}
75+
@use "sass:math";
76+
a {b: math.round(-5.6)}
6377

6478
<===> down/negative/output.css
6579
a {
@@ -69,7 +83,8 @@ a {
6983
<===>
7084
================================================================================
7185
<===> down/to_zero/input.scss
72-
a {b: round(0.2)}
86+
@use "sass:math";
87+
a {b: math.round(0.2)}
7388

7489
<===> down/to_zero/output.css
7590
a {
@@ -85,7 +100,8 @@ a {
85100
<===> down/within_precision/input.scss
86101
// This is the largest number that's representable as a float and outside the
87102
// precision range to be considered equal to 1.5.
88-
a {b: round(1.4999999999949998)}
103+
@use "sass:math";
104+
a {b: math.round(1.4999999999949998)}
89105

90106
<===> down/within_precision/output.css
91107
a {
@@ -99,7 +115,8 @@ a {
99115
- sass/libsass#2887
100116

101117
<===> preserves_units/input.scss
102-
a {b: round(7px / 4em) * 1em}
118+
@use "sass:math";
119+
a {b: math.round(7px / 4em) * 1em}
103120

104121
<===> preserves_units/output.css
105122
a {
@@ -114,15 +131,16 @@ Recommendation: math.div(7px, 4em)
114131
More info and automated migrator: https://sass-lang.com/d/slash-div
115132

116133
,
117-
1 | a {b: round(7px / 4em) * 1em}
118-
| ^^^^^^^^^
134+
2 | a {b: math.round(7px / 4em) * 1em}
135+
| ^^^^^^^^^
119136
'
120-
input.scss 1:13 root stylesheet
137+
input.scss 2:18 root stylesheet
121138

122139
<===>
123140
================================================================================
124141
<===> named/input.scss
125-
a {b: round($number: 1.6)}
142+
@use "sass:math";
143+
a {b: math.round($number: 1.6)}
126144

127145
<===> named/output.css
128146
a {
@@ -132,15 +150,16 @@ a {
132150
<===>
133151
================================================================================
134152
<===> error/type/input.scss
135-
a {b: round(c)}
153+
@use "sass:math";
154+
a {b: math.round(c)}
136155

137156
<===> error/type/error
138157
Error: $number: c is not a number.
139158
,
140-
1 | a {b: round(c)}
141-
| ^^^^^^^^
159+
2 | a {b: math.round(c)}
160+
| ^^^^^^^^^^^^^
142161
'
143-
input.scss 1:7 root stylesheet
162+
input.scss 2:7 root stylesheet
144163

145164
<===> error/type/error-libsass
146165
Error: argument `$number` of `round($number)` must be a number
@@ -153,19 +172,20 @@ Error: argument `$number` of `round($number)` must be a number
153172
<===>
154173
================================================================================
155174
<===> error/too_few_args/input.scss
156-
a {b: round()}
175+
@use "sass:math";
176+
a {b: math.round()}
157177

158178
<===> error/too_few_args/error
159179
Error: Missing argument $number.
160180
,--> input.scss
161-
1 | a {b: round()}
162-
| ^^^^^^^ invocation
181+
2 | a {b: math.round()}
182+
| ^^^^^^^^^^^^ invocation
163183
'
164184
,--> sass:math
165185
1 | @function round($number) {
166186
| ============== declaration
167187
'
168-
input.scss 1:7 root stylesheet
188+
input.scss 2:7 root stylesheet
169189

170190
<===> error/too_few_args/error-libsass
171191
Error: Function round is missing argument $number.
@@ -177,20 +197,21 @@ Error: Function round is missing argument $number.
177197
<===>
178198
================================================================================
179199
<===> error/too_many_args/input.scss
180-
a {b: round(1, 2)}
200+
@use "sass:math";
201+
a {b: math.round(1, 2)}
181202

182203

183204
<===> error/too_many_args/error
184205
Error: Only 1 argument allowed, but 2 were passed.
185206
,--> input.scss
186-
1 | a {b: round(1, 2)}
187-
| ^^^^^^^^^^^ invocation
207+
2 | a {b: math.round(1, 2)}
208+
| ^^^^^^^^^^^^^^^^ invocation
188209
'
189210
,--> sass:math
190211
1 | @function round($number) {
191212
| ============== declaration
192213
'
193-
input.scss 1:7 root stylesheet
214+
input.scss 2:7 root stylesheet
194215

195216
<===> error/too_many_args/error-libsass
196217
Error: wrong number of arguments (2 for 1) for `round'

0 commit comments

Comments
 (0)