@@ -147,18 +147,19 @@ def parse_many(first, *others):
147
147
'Negation[Element[div]:not(Class[Element[div].foo])]' ]
148
148
assert parse_many ('td ~ th' ) == [
149
149
'CombinedSelector[Element[td] ~ Element[th]]' ]
150
- assert parse_many ('< > foo' ) == [
151
- 'CombinedSelector[Element[< ] > Element[foo]]'
150
+ assert parse_many (':scope > foo' ) == [
151
+ 'CombinedSelector[Pseudo[ Element[*]:scope ] > Element[foo]]'
152
152
]
153
- assert parse_many ('< > foo bar > div' ) == [
154
- 'CombinedSelector[CombinedSelector[CombinedSelector[Element[<] > Element[foo]] '
155
- '<followed> Element[bar]] > Element[div]]'
153
+ assert parse_many (':scope > foo bar > div' ) == [
154
+ 'CombinedSelector[CombinedSelector[CombinedSelector[Pseudo[ Element[*]:scope] > '
155
+ 'Element[foo]] <followed> Element[bar]] > Element[div]]'
156
156
]
157
- assert parse_many ('< > #foo #bar' ) == [
158
- 'CombinedSelector[CombinedSelector[Element[<] > Hash[ Element[*]#foo]] '
159
- '<followed> Hash[Element[*]#bar]]'
157
+ assert parse_many (':scope > #foo #bar' ) == [
158
+ 'CombinedSelector[CombinedSelector[Pseudo[ Element[*]:scope] > '
159
+ 'Hash[Element[*]#foo]] <followed> Hash[Element[*]#bar]]'
160
160
]
161
161
162
+ # TODO ADD TESTS
162
163
def test_pseudo_elements (self ):
163
164
def parse_pseudo (css ):
164
165
result = []
@@ -179,6 +180,7 @@ def parse_one(css):
179
180
assert parse_one ('foo' ) == ('Element[foo]' , None )
180
181
assert parse_one ('*' ) == ('Element[*]' , None )
181
182
assert parse_one (':empty' ) == ('Pseudo[Element[*]:empty]' , None )
183
+ assert parse_one (':scope' ) == ('Pseudo[Element[*]:scope]' , None )
182
184
183
185
# Special cases for CSS 2.1 pseudo-elements
184
186
assert parse_one (':BEfore' ) == ('Element[*]' , 'before' )
@@ -322,11 +324,9 @@ def get_error(css):
322
324
"Got pseudo-element ::before inside :not() at 12" )
323
325
assert get_error (':not(:not(a))' ) == (
324
326
"Got nested :not()" )
325
- assert get_error ('< > div <> header' ) == (
326
- 'Got immediate child pseudo-element "<> " not at the start of a selector'
327
+ assert get_error (':scope > div :scope header' ) == (
328
+ 'Got immediate child pseudo-element ":scope " not at the start of a selector'
327
329
)
328
- assert get_error ('< div p' ) == (
329
- 'Got incomplete immediate child pseudo-element "<>" (no ">")' )
330
330
assert get_error ('> div p' ) == ("Expected selector, got <DELIM '>' at 0>" )
331
331
332
332
def test_translation (self ):
@@ -501,8 +501,8 @@ def test_quoting(self):
501
501
'''descendant-or-self::*[@aval = '"']''' )
502
502
assert css_to_xpath ('*[aval=\' """\' ]' ) == (
503
503
'''descendant-or-self::*[@aval = '"""']''' )
504
- assert css_to_xpath ('< > div[dataimg="<testmessage>"]' ) == (
505
- "child:: div[@dataimg = '<testmessage>']" )
504
+ assert css_to_xpath (':scope > div[dataimg="<testmessage>"]' ) == (
505
+ "descendant-or-self::*[1]/ div[@dataimg = '<testmessage>']" )
506
506
507
507
def test_unicode_escapes (self ):
508
508
# \22 == '"' \20 == ' '
@@ -580,6 +580,7 @@ def xpath(css):
580
580
assert xpath ('::attr-href' ) == "descendant-or-self::*/@href"
581
581
assert xpath ('p img::attr(src)' ) == (
582
582
"descendant-or-self::p/descendant-or-self::*/img/@src" )
583
+ assert xpath (':scope' ) == "descendant-or-self::*[1]"
583
584
584
585
def test_series (self ):
585
586
def series (css ):
@@ -692,11 +693,11 @@ def pcss(main, *selectors, **kwargs):
692
693
assert pcss (':lang("EN")' , '*:lang(en-US)' , html_only = True ) == [
693
694
'second-li' , 'li-div' ]
694
695
assert pcss (':lang("e")' , html_only = True ) == []
695
- assert pcss ('< > div' ) == []
696
- assert pcss ('<> body' ) == ['nil' ]
697
- assert pcss ('<> body > div' ) == ['outer-div' , 'foobar-div' ]
698
- assert pcss ('<> head' ) == ['nil' ]
699
- assert pcss ('<> html' ) == []
696
+ assert pcss (':scope > div' ) == []
697
+ assert pcss (':scope body' ) == ['nil' ]
698
+ assert pcss (':scope body > div' ) == ['outer-div' , 'foobar-div' ]
699
+ assert pcss (':scope head' ) == ['nil' ]
700
+ assert pcss (':scope html' ) == []
700
701
701
702
# --- nth-* and nth-last-* -------------------------------------
702
703
@@ -878,7 +879,9 @@ def count(selector):
878
879
assert count ('div[class|=dialog]' ) == 50 # ? Seems right
879
880
assert count ('div[class!=madeup]' ) == 243 # ? Seems right
880
881
assert count ('div[class~=dialog]' ) == 51 # ? Seems right
881
- assert count ('<> div' ) == 1
882
+ assert count (':scope > div' ) == 1
883
+ assert count (':scope > div > div[class=dialog]' ) == 1
884
+ assert count (':scope > div div' ) == 242
882
885
883
886
XMLLANG_IDS = '''
884
887
<test>
0 commit comments