Skip to content

Commit d5b388e

Browse files
authored
Merge pull request #1386 from sass/attribute-modifier
Add specs for attribute selectors with modifiers
2 parents 18b91d4 + 6a11df8 commit d5b388e

File tree

5 files changed

+208
-52
lines changed

5 files changed

+208
-52
lines changed

lib/sass_spec/util.rb

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ class << self
33
# Normalizes the whitespace in the given CSS to make it easier to compare
44
# across implementations.
55
def normalize_output(css)
6-
css.gsub(/(?:\r?\n)+/, "\n")
6+
css.gsub(/(?:\r?\n)+/, "\n").force_encoding("utf-8")
77
end
88

99
# Normalizes the path names and whitespace in the given error message.
@@ -16,6 +16,7 @@ def normalize_error(error)
1616
.sub(/(?:\r?\n)*\z/, "\n") # make sure we have exactly one trailing linefeed
1717
.sub(/\A(?:\r?\s)+\z/, "") # clear the whole file if only whitespace
1818
.gsub(/\r\n/, "\n") # remove Windows line feeds
19+
.force_encoding("utf-8")
1920
end
2021

2122
# Yields each directory in `path`, from the outermost to the innermost.

spec/css/selector.hrx

Lines changed: 206 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,206 @@
1+
<===> attribute/dash_dash/input.scss
2+
// Attribute selector values are allowed to be unquoted as long as they're plain
3+
// CSS identifiers. However, IE 11 doesn't recognize custom-property-style
4+
// identifiers like `--foo` as identifiers, so they should always be quoted.
5+
6+
[class="--foo"], [class*="--foo"] {
7+
x: y;
8+
}
9+
10+
<===> attribute/dash_dash/output.css
11+
[class="--foo"], [class*="--foo"] {
12+
x: y;
13+
}
14+
15+
<===>
16+
================================================================================
17+
<===> attribute/modifier/unknown/options.yml
18+
---
19+
:todo:
20+
- libsass # sass/libsass#2886
21+
22+
<===> attribute/modifier/unknown/input.scss
23+
// At time of writing, only the modifiers "i" and "s" are allowed by the CSS
24+
// spec. However, for forwards-compatibility with future CSS additions, any
25+
// single character should be allowed.
26+
[a=b c] {d: e}
27+
28+
<===> attribute/modifier/unknown/output.css
29+
[a=b c] {
30+
d: e;
31+
}
32+
33+
<===>
34+
================================================================================
35+
<===> attribute/modifier/caps/input.scss
36+
[a=b I] {c: d}
37+
38+
<===> attribute/modifier/caps/output.css
39+
[a=b I] {
40+
c: d;
41+
}
42+
43+
<===>
44+
================================================================================
45+
<===> attribute/modifier/after_string/input.scss
46+
[a="b"i] {c: d}
47+
48+
<===> attribute/modifier/after_string/output.css
49+
[a=b i] {
50+
c: d;
51+
}
52+
53+
<===> attribute/modifier/after_string/output-libsass.css
54+
[a="b" i] {
55+
c: d;
56+
}
57+
58+
<===>
59+
================================================================================
60+
<===> reference_combinator/options.yml
61+
---
62+
:todo:
63+
- libsass
64+
65+
<===> reference_combinator/input.scss
66+
// Reference combinators used to be supported by Sass when they were part of the
67+
// CSS spec, but they're no longer supported and should now produce errors.
68+
.foo /bar/ .baz {
69+
a: b;
70+
}
71+
72+
<===> reference_combinator/error
73+
Error: expected selector.
74+
,
75+
3 | .foo /bar/ .baz{
76+
| ^
77+
'
78+
input.scss 3:6 root stylesheet
79+
80+
<===>
81+
================================================================================
82+
<===> slotted/input.scss
83+
::slotted(.a) {x: y}
84+
85+
::slotted(.c.d) {x: y}
86+
.e {@extend .c}
87+
88+
::slotted(.f) {x: y}
89+
::slotted(.g) {@extend .f}
90+
91+
<===> slotted/output.css
92+
::slotted(.a) {
93+
x: y;
94+
}
95+
96+
::slotted(.c.d, .d.e) {
97+
x: y;
98+
}
99+
100+
::slotted(.f, ::slotted(.g)) {
101+
x: y;
102+
}
103+
104+
<===>
105+
================================================================================
106+
<===> error/attribute/modifier/no_operator/input.scss
107+
[a b] {c: d}
108+
109+
<===> error/attribute/modifier/no_operator/error
110+
Error: Expected "]".
111+
,
112+
1 | [a b]{c: d}
113+
| ^
114+
'
115+
input.scss 1:4 root stylesheet
116+
117+
<===> error/attribute/modifier/no_operator/error-libsass
118+
Error: invalid operator in attribute selector for a
119+
on line 1:2 of input.scss
120+
>> [a b] {c: d}
121+
122+
-^
123+
124+
<===>
125+
================================================================================
126+
<===> error/attribute/modifier/too_long/input.scss
127+
// Attribute modifiers must be single characters.
128+
[a=b cd] {e: f}
129+
130+
<===> error/attribute/modifier/too_long/error
131+
Error: expected "]".
132+
,
133+
2 | [a=b cd]{e: f}
134+
| ^
135+
'
136+
input.scss 2:7 root stylesheet
137+
138+
<===> error/attribute/modifier/too_long/error-libsass
139+
Error: unterminated attribute selector for a
140+
on line 2:4 of input.scss
141+
>> [a=b cd] {e: f}
142+
143+
---^
144+
145+
<===>
146+
================================================================================
147+
<===> error/attribute/modifier/underscore/input.scss
148+
// Attribute modifiers must be ASCII alphabetical characters.
149+
[a=b _] {c: d}
150+
151+
<===> error/attribute/modifier/underscore/error
152+
Error: expected "]".
153+
,
154+
2 | [a=b _]{c: d}
155+
| ^
156+
'
157+
input.scss 2:6 root stylesheet
158+
159+
<===> error/attribute/modifier/underscore/error-libsass
160+
Error: unterminated attribute selector for a
161+
on line 2:4 of input.scss
162+
>> [a=b _] {c: d}
163+
164+
---^
165+
166+
<===>
167+
================================================================================
168+
<===> error/attribute/modifier/digit/input.scss
169+
// Attribute modifiers must be ASCII alphabetical characters.
170+
[a=b 1] {c: d}
171+
172+
<===> error/attribute/modifier/digit/error
173+
Error: expected "]".
174+
,
175+
2 | [a=b 1]{c: d}
176+
| ^
177+
'
178+
input.scss 2:6 root stylesheet
179+
180+
<===> error/attribute/modifier/digit/error-libsass
181+
Error: unterminated attribute selector for a
182+
on line 2:4 of input.scss
183+
>> [a=b 1] {c: d}
184+
185+
---^
186+
187+
<===>
188+
================================================================================
189+
<===> error/attribute/modifier/unicode/input.scss
190+
// Attribute modifiers must be ASCII alphabetical characters.
191+
[a=b ï] {c: d}
192+
193+
<===> error/attribute/modifier/unicode/error
194+
Error: expected "]".
195+
,
196+
2 | [a=b ï]{c: d}
197+
| ^
198+
'
199+
input.scss 2:6 root stylesheet
200+
201+
<===> error/attribute/modifier/unicode/error-libsass
202+
Error: unterminated attribute selector for a
203+
on line 2:4 of input.scss
204+
>> [a=b ï] {c: d}
205+
206+
---^

spec/css/selector/attribute/dash-dash.hrx

Lines changed: 0 additions & 13 deletions
This file was deleted.

spec/css/selector/reference_combinator.hrx

Lines changed: 0 additions & 17 deletions
This file was deleted.

spec/css/selector/slotted.hrx

Lines changed: 0 additions & 21 deletions
This file was deleted.

0 commit comments

Comments
 (0)