@@ -41,13 +41,19 @@ public void HandlesMultipleSelectors()
41
41
var result = RewriteCssCommand . AddScopeToSelectors ( "file.css" , @"
42
42
.first, .second { color: red; }
43
43
.third { color: blue; }
44
+ :root { color: green; }
45
+ * { color: white; }
46
+ #some-id { color: yellow; }
44
47
" , "TestScope" , out var diagnostics ) ;
45
48
46
49
// Assert
47
50
Assert . Empty ( diagnostics ) ;
48
51
Assert . Equal ( @"
49
52
.first[TestScope], .second[TestScope] { color: red; }
50
53
.third[TestScope] { color: blue; }
54
+ :root[TestScope] { color: green; }
55
+ *[TestScope] { color: white; }
56
+ #some-id[TestScope] { color: yellow; }
51
57
" , result ) ;
52
58
}
53
59
@@ -81,6 +87,83 @@ public void HandlesSpacesAndCommentsWithinSelectors()
81
87
" , result ) ;
82
88
}
83
89
90
+ [ Fact ]
91
+ public void HandlesPseudoClasses ( )
92
+ {
93
+ // Arrange/act
94
+ var result = RewriteCssCommand . AddScopeToSelectors ( "file.css" , @"
95
+ a:fake-pseudo-class { color: red; }
96
+ a:focus b:hover { color: green; }
97
+ tr:nth-child(4n + 1) { color: blue; }
98
+ a:has(b > c) { color: yellow; }
99
+ a:last-child > ::deep b { color: pink; }
100
+ a:not(#something) { color: purple; }
101
+ " , "TestScope" , out var diagnostics ) ;
102
+
103
+ // Assert
104
+ Assert . Empty ( diagnostics ) ;
105
+ Assert . Equal ( @"
106
+ a:fake-pseudo-class[TestScope] { color: red; }
107
+ a:focus b:hover[TestScope] { color: green; }
108
+ tr:nth-child(4n + 1)[TestScope] { color: blue; }
109
+ a:has(b > c)[TestScope] { color: yellow; }
110
+ a:last-child[TestScope] > b { color: pink; }
111
+ a:not(#something)[TestScope] { color: purple; }
112
+ " , result ) ;
113
+ }
114
+
115
+ [ Fact ]
116
+ public void HandlesPseudoElements ( )
117
+ {
118
+ // Arrange/act
119
+ var result = RewriteCssCommand . AddScopeToSelectors ( "file.css" , @"
120
+ a::before { content: ""✋""; }
121
+ a::after::placeholder { content: ""🐯""; }
122
+ custom-element::part(foo) { content: ""🤷""; }
123
+ a::before > ::deep another { content: ""👞""; }
124
+ a::fake-PsEuDo-element { content: ""🐔""; }
125
+ ::selection { content: ""😾""; }
126
+ other, ::selection { content: ""👂""; }
127
+ " , "TestScope" , out var diagnostics ) ;
128
+
129
+ // Assert
130
+ Assert . Empty ( diagnostics ) ;
131
+ Assert . Equal ( @"
132
+ a[TestScope]::before { content: ""✋""; }
133
+ a[TestScope]::after::placeholder { content: ""🐯""; }
134
+ custom-element[TestScope]::part(foo) { content: ""🤷""; }
135
+ a[TestScope]::before > another { content: ""👞""; }
136
+ a[TestScope]::fake-PsEuDo-element { content: ""🐔""; }
137
+ [TestScope]::selection { content: ""😾""; }
138
+ other[TestScope], [TestScope]::selection { content: ""👂""; }
139
+ " , result ) ;
140
+ }
141
+
142
+ [ Fact ]
143
+ public void HandlesSingleColonPseudoElements ( )
144
+ {
145
+ // Arrange/act
146
+ var result = RewriteCssCommand . AddScopeToSelectors ( "file.css" , @"
147
+ a:after { content: ""x""; }
148
+ a:before { content: ""x""; }
149
+ a:first-letter { content: ""x""; }
150
+ a:first-line { content: ""x""; }
151
+ a:AFTER { content: ""x""; }
152
+ a:not(something):before { content: ""x""; }
153
+ " , "TestScope" , out var diagnostics ) ;
154
+
155
+ // Assert
156
+ Assert . Empty ( diagnostics ) ;
157
+ Assert . Equal ( @"
158
+ a[TestScope]:after { content: ""x""; }
159
+ a[TestScope]:before { content: ""x""; }
160
+ a[TestScope]:first-letter { content: ""x""; }
161
+ a[TestScope]:first-line { content: ""x""; }
162
+ a[TestScope]:AFTER { content: ""x""; }
163
+ a:not(something)[TestScope]:before { content: ""x""; }
164
+ " , result ) ;
165
+ }
166
+
84
167
[ Fact ]
85
168
public void RespectsDeepCombinator ( )
86
169
{
0 commit comments