Skip to content

Commit 32c983a

Browse files
authored
Style-guide-ify selector-parse() specs (#1451)
1 parent d10b618 commit 32c983a

File tree

7 files changed

+625
-85
lines changed

7 files changed

+625
-85
lines changed
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
These tests verify that `selector-parse()` accepts a wide range of input
2+
structures and selector types.
3+
4+
We don't test the full gamut of possible inputs for every selector function
5+
because it's assumed that they use the same parsing infrastructure, but they are
6+
required to support all the same inputs as `selector-parse()`.
Lines changed: 188 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,188 @@
1+
<===> parent/input.scss
2+
a {b: selector-parse("&")}
3+
4+
<===> parent/error
5+
Error: $selector: Parent selectors aren't allowed here.
6+
,
7+
1 | &
8+
| ^
9+
'
10+
- 1:1 root stylesheet
11+
,
12+
1 | a {b: selector-parse("&")}
13+
| ^^^^^^^^^^^^^^^^^^^
14+
'
15+
input.scss 1:7 root stylesheet
16+
17+
<===> parent/error-libsass
18+
Error: Parent selectors aren't allowed here.
19+
on line 1:22 of input.scss, in function `selector-parse`
20+
from line 1:7 of input.scss
21+
>> a {b: selector-parse("&")}
22+
23+
---------------------^
24+
25+
<===>
26+
================================================================================
27+
<===> parse/invalid/input.scss
28+
a {b: selector-parse("[c")}
29+
30+
<===> parse/invalid/error
31+
Error: $selector: expected more input.
32+
,
33+
1 | [c
34+
| ^
35+
'
36+
- 1:3 root stylesheet
37+
,
38+
1 | a {b: selector-parse("[c")}
39+
| ^^^^^^^^^^^^^^^^^^^^
40+
'
41+
input.scss 1:7 root stylesheet
42+
43+
<===> parse/invalid/error-libsass
44+
Error: invalid operator in attribute selector for c
45+
on line 1:23 of input.scss, in function `selector-parse`
46+
from line 1:7 of input.scss
47+
>> a {b: selector-parse("[c")}
48+
49+
----------------------^
50+
51+
<===>
52+
================================================================================
53+
<===> parse/extra/options.yml
54+
---
55+
:todo:
56+
- sass/libsass#2965
57+
58+
<===> parse/extra/input.scss
59+
a {b: selector-parse("c {")}
60+
61+
<===> parse/extra/error
62+
Error: $selector: expected selector.
63+
,
64+
1 | c {
65+
| ^
66+
'
67+
- 1:3 root stylesheet
68+
,
69+
1 | a {b: selector-parse("c {")}
70+
| ^^^^^^^^^^^^^^^^^^^^^
71+
'
72+
input.scss 1:7 root stylesheet
73+
74+
<===>
75+
================================================================================
76+
<===> too_nested/options.yml
77+
---
78+
:todo:
79+
- sass/libsass#2964
80+
81+
<===> too_nested/input.scss
82+
a {b: selector-parse((append((), append((), c)),))}
83+
84+
<===> too_nested/error
85+
Error: c is not a valid selector: it must be a string,
86+
a list of strings, or a list of lists of strings.
87+
,
88+
1 | a {b: selector-parse((append((), append((), c)),))}
89+
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
90+
'
91+
input.scss 1:7 root stylesheet
92+
93+
<===>
94+
================================================================================
95+
<===> inner_comma/options.yml
96+
---
97+
:todo:
98+
- sass/libsass#2964
99+
100+
<===> inner_comma/input.scss
101+
a {b: selector-parse(((c,),))}
102+
103+
<===> inner_comma/error
104+
Error: $selector: ((c,),) is not a valid selector: it must be a string,
105+
a list of strings, or a list of lists of strings.
106+
,
107+
1 | a {b: selector-parse(((c,),))}
108+
| ^^^^^^^^^^^^^^^^^^^^^^^
109+
'
110+
input.scss 1:7 root stylesheet
111+
112+
<===>
113+
================================================================================
114+
<===> outer_space/options.yml
115+
---
116+
:todo:
117+
- sass/libsass#2964
118+
119+
<===> outer_space/input.scss
120+
a {b: selector-parse(append((), append((), c)))}
121+
122+
<===> outer_space/error
123+
Error: $selector: c is not a valid selector: it must be a string,
124+
a list of strings, or a list of lists of strings.
125+
,
126+
1 | a {b: selector-parse(append((), append((), c)))}
127+
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
128+
'
129+
input.scss 1:7 root stylesheet
130+
131+
<===>
132+
================================================================================
133+
<===> type/options.yml
134+
---
135+
:todo:
136+
- sass/libsass#2964
137+
138+
<===> type/input.scss
139+
a {b: selector-parse(1)}
140+
141+
<===> type/error
142+
Error: $selector: 1 is not a valid selector: it must be a string,
143+
a list of strings, or a list of lists of strings.
144+
,
145+
1 | a {b: selector-parse(1)}
146+
| ^^^^^^^^^^^^^^^^^
147+
'
148+
input.scss 1:7 root stylesheet
149+
150+
<===>
151+
================================================================================
152+
<===> too_many_args/input.scss
153+
a {b: selector-parse(c, d)}
154+
155+
<===> too_many_args/error
156+
Error: Only 1 argument allowed, but 2 were passed.
157+
,
158+
1 | a {b: selector-parse(c, d)}
159+
| ^^^^^^^^^^^^^^^^^^^^
160+
'
161+
input.scss 1:7 root stylesheet
162+
163+
<===> too_many_args/error-libsass
164+
Error: wrong number of arguments (2 for 1) for `selector-parse'
165+
on line 1:7 of input.scss
166+
>> a {b: selector-parse(c, d)}
167+
168+
------^
169+
170+
<===>
171+
================================================================================
172+
<===> too_few_args/input.scss
173+
a {b: selector-parse()}
174+
175+
<===> too_few_args/error
176+
Error: Missing argument $selector.
177+
,
178+
1 | a {b: selector-parse()}
179+
| ^^^^^^^^^^^^^^^^
180+
'
181+
input.scss 1:7 root stylesheet
182+
183+
<===> too_few_args/error-libsass
184+
Error: Function selector-parse is missing argument $selector.
185+
on line 1 of input.scss
186+
>> a {b: selector-parse()}
187+
188+
------^
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
<===> input.scss
2+
a {b: selector-parse($selector: "c")}
3+
4+
<===> output.css
5+
a {
6+
b: c;
7+
}

0 commit comments

Comments
 (0)