@@ -147,18 +147,19 @@ def parse_many(first, *others):
147147 'Negation[Element[div]:not(Class[Element[div].foo])]' ]
148148 assert parse_many ('td ~ th' ) == [
149149 '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]]'
152152 ]
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]]'
156156 ]
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]]'
160160 ]
161161
162+ # TODO ADD TESTS
162163 def test_pseudo_elements (self ):
163164 def parse_pseudo (css ):
164165 result = []
@@ -179,6 +180,7 @@ def parse_one(css):
179180 assert parse_one ('foo' ) == ('Element[foo]' , None )
180181 assert parse_one ('*' ) == ('Element[*]' , None )
181182 assert parse_one (':empty' ) == ('Pseudo[Element[*]:empty]' , None )
183+ assert parse_one (':scope' ) == ('Pseudo[Element[*]:scope]' , None )
182184
183185 # Special cases for CSS 2.1 pseudo-elements
184186 assert parse_one (':BEfore' ) == ('Element[*]' , 'before' )
@@ -322,11 +324,9 @@ def get_error(css):
322324 "Got pseudo-element ::before inside :not() at 12" )
323325 assert get_error (':not(:not(a))' ) == (
324326 "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'
327329 )
328- assert get_error ('< div p' ) == (
329- 'Got incomplete immediate child pseudo-element "<>" (no ">")' )
330330 assert get_error ('> div p' ) == ("Expected selector, got <DELIM '>' at 0>" )
331331
332332 def test_translation (self ):
@@ -501,8 +501,8 @@ def test_quoting(self):
501501 '''descendant-or-self::*[@aval = '"']''' )
502502 assert css_to_xpath ('*[aval=\' """\' ]' ) == (
503503 '''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>']" )
506506
507507 def test_unicode_escapes (self ):
508508 # \22 == '"' \20 == ' '
@@ -580,6 +580,7 @@ def xpath(css):
580580 assert xpath ('::attr-href' ) == "descendant-or-self::*/@href"
581581 assert xpath ('p img::attr(src)' ) == (
582582 "descendant-or-self::p/descendant-or-self::*/img/@src" )
583+ assert xpath (':scope' ) == "descendant-or-self::*[1]"
583584
584585 def test_series (self ):
585586 def series (css ):
@@ -692,11 +693,11 @@ def pcss(main, *selectors, **kwargs):
692693 assert pcss (':lang("EN")' , '*:lang(en-US)' , html_only = True ) == [
693694 'second-li' , 'li-div' ]
694695 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' ) == []
700701
701702 # --- nth-* and nth-last-* -------------------------------------
702703
@@ -878,7 +879,9 @@ def count(selector):
878879 assert count ('div[class|=dialog]' ) == 50 # ? Seems right
879880 assert count ('div[class!=madeup]' ) == 243 # ? Seems right
880881 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
882885
883886XMLLANG_IDS = '''
884887<test>
0 commit comments