Luce packages
LuceLuce BaseLuciaOS

dymokomi/luce-browser-engine

Source of release 0.6.1

0.6.1 / src / web / css / tests_selector_engine_cases.lucb

#==============================================================================================
#
#   tests_selector_engine_cases - the SelectorEngine matching cases pinned to the reference
#                                 build
#
#   DESCRIPTION:
#       Generated (a test vector table) from the output of a local oracle that runs the
#       reference Ladybird build's test-web on a Text test doing the same queries
#       (luce-browser-tools, oracles/luce-browser-engine/selector_engine: matching_cases.txt,
#       gen_matching.py). tests_selector_engine builds each tree and runs each query through the
#       port's querySelectorAll, and compares the matched elements.
#
#==============================================================================================

## The reference document's element tree around div#root, as the oracle describes it.
let test_selector_engine_document: str = "document: html(head(script() script()) body(root() out()))"

## One oracle case: div#root's markup, its queries ("root <selector>" / "doc <selector>", one per
## line) and the reference build's results ("<query> => <ids>", one per line).
struct TestSelectorEngineCase:
    let markup: str
    let queries: str
    let expected: str

## Every oracle case, in matching_cases.txt order.
let test_selector_engine_cases: TestSelectorEngineCase[13] = [
    TestSelectorEngineCase(markup = "<div id=a class=\"x y\"><p id=b class=\"y\"><span id=c class=\"Z\"></span><em id=d></em></p><p id=e><span id=f class=\"x\"></span></p></div><section id=g><span id=h></span></section>", queries = "root *\nroot div\nroot p\nroot span\nroot DIV\nroot #b\nroot #B\nroot .y\nroot .x.y\nroot .z\nroot .Z\nroot p.y\nroot #a .x\nroot div span\nroot div > span\nroot p > span\nroot p span.x\nroot #a > p > span\nroot div p em\nroot section span, p em\nroot :scope > *\nroot :scope > p\nroot :scope span\nroot #a p:not(.y)\nroot p span ~ em\nroot span + em\nroot p + p\nroot p ~ p > span\nroot div + section\nroot #nope\nroot .x .x\nroot [id]\nroot p:is(.y, #e) span\nroot :where(#a, #g) > *\nroot :is(section) span\ndoc :root\ndoc html\ndoc :root > body > div > div\ndoc body > *\ndoc head > *\ndoc #root > div\ndoc html span\n", expected = "root * => a,b,c,d,e,f,g,h\nroot div => a\nroot p => b,e\nroot span => c,f,h\nroot DIV => a\nroot #b => b\nroot #B => \nroot .y => a,b\nroot .x.y => a\nroot .z => \nroot .Z => c\nroot p.y => b\nroot #a .x => f\nroot div span => c,f,h\nroot div > span => \nroot p > span => c,f\nroot p span.x => f\nroot #a > p > span => c,f\nroot div p em => d\nroot section span, p em => d,h\nroot :scope > * => a,g\nroot :scope > p => \nroot :scope span => c,f,h\nroot #a p:not(.y) => e\nroot p span ~ em => d\nroot span + em => d\nroot p + p => e\nroot p ~ p > span => f\nroot div + section => g\nroot #nope => \nroot .x .x => f\nroot [id] => a,b,c,d,e,f,g,h\nroot p:is(.y, #e) span => c,f\nroot :where(#a, #g) > * => b,e,h\nroot :is(section) span => h\ndoc :root => html\ndoc html => html\ndoc :root > body > div > div => a\ndoc body > * => root\ndoc head > * => script,script\ndoc #root > div => a\ndoc html span => c,f,h\n"),
    TestSelectorEngineCase(markup = "<ul id=u><li id=l1></li><li id=l2></li><li id=l3></li><li id=l4></li><li id=l5></li><li id=l6></li><li id=l7></li></ul>", queries = "root li:first-child\nroot li:last-child\nroot li:only-child\nroot li:nth-child(2)\nroot li:nth-child(odd)\nroot li:nth-child(even)\nroot li:nth-child(3n)\nroot li:nth-child(3n+1)\nroot li:nth-child(-n+3)\nroot li:nth-child(n+5)\nroot li:nth-child(-2n+5)\nroot li:nth-child(0n+0)\nroot li:nth-child(5n-2)\nroot li:nth-last-child(2)\nroot li:nth-last-child(odd)\nroot li:nth-last-child(-n+2)\nroot li:nth-of-type(3)\nroot li:nth-last-of-type(1)\nroot li:first-of-type\nroot li:last-of-type\nroot li:only-of-type\nroot ul:only-child\nroot ul:only-of-type\nroot li:nth-child(2) ~ li:nth-child(-n+5)\nroot li:nth-child(2) + li\nroot li:not(:first-child):not(:last-child)\nroot :first-child\nroot :last-child\n", expected = "root li:first-child => l1\nroot li:last-child => l7\nroot li:only-child => \nroot li:nth-child(2) => l2\nroot li:nth-child(odd) => l1,l3,l5,l7\nroot li:nth-child(even) => l2,l4,l6\nroot li:nth-child(3n) => l3,l6\nroot li:nth-child(3n+1) => l1,l4,l7\nroot li:nth-child(-n+3) => l1,l2,l3\nroot li:nth-child(n+5) => l5,l6,l7\nroot li:nth-child(-2n+5) => l1,l3,l5\nroot li:nth-child(0n+0) => \nroot li:nth-child(5n-2) => l3\nroot li:nth-last-child(2) => l6\nroot li:nth-last-child(odd) => l1,l3,l5,l7\nroot li:nth-last-child(-n+2) => l6,l7\nroot li:nth-of-type(3) => l3\nroot li:nth-last-of-type(1) => l7\nroot li:first-of-type => l1\nroot li:last-of-type => l7\nroot li:only-of-type => \nroot ul:only-child => u\nroot ul:only-of-type => u\nroot li:nth-child(2) ~ li:nth-child(-n+5) => l3,l4,l5\nroot li:nth-child(2) + li => l3\nroot li:not(:first-child):not(:last-child) => l2,l3,l4,l5,l6\nroot :first-child => u,l1\nroot :last-child => u,l7\n"),
    TestSelectorEngineCase(markup = "<div id=m><p id=p1 class=k></p><span id=s1 class=k></span><p id=p2></p><span id=s2></span><p id=p3 class=k></p><em id=e1 class=k></em><p id=p4></p></div>", queries = "root p:nth-of-type(2)\nroot p:nth-last-of-type(2)\nroot span:first-of-type\nroot span:last-of-type\nroot em:only-of-type\nroot p:first-of-type\nroot :nth-child(2n of .k)\nroot :nth-child(1 of .k)\nroot :nth-last-child(1 of .k)\nroot :nth-child(odd of p)\nroot :nth-last-child(2 of p, span)\nroot :nth-child(n of .nope)\nroot .k:nth-child(odd of .k)\nroot p:nth-of-type(odd)\nroot :nth-last-of-type(1)\n", expected = "root p:nth-of-type(2) => p2\nroot p:nth-last-of-type(2) => p3\nroot span:first-of-type => s1\nroot span:last-of-type => s2\nroot em:only-of-type => e1\nroot p:first-of-type => p1\nroot :nth-child(2n of .k) => s1,e1\nroot :nth-child(1 of .k) => p1\nroot :nth-last-child(1 of .k) => e1\nroot :nth-child(odd of p) => p1,p3\nroot :nth-last-child(2 of p, span) => p3\nroot :nth-child(n of .nope) => \nroot .k:nth-child(odd of .k) => p1,p3\nroot p:nth-of-type(odd) => p1,p3\nroot :nth-last-of-type(1) => m,s2,e1,p4\n"),
    TestSelectorEngineCase(markup = "<div id=e1></div><div id=e2> </div><div id=e3>text</div><div id=e4><span id=e5></span></div><div id=e6><b id=e7></b>x</div>", queries = "root div:empty\nroot :empty\nroot div:not(:empty)\nroot span:empty\n", expected = "root div:empty => e1\nroot :empty => e1,e5,e7\nroot div:not(:empty) => e2,e3,e4,e6\nroot span:empty => e5\n"),
    TestSelectorEngineCase(markup = "<a id=a1 href=\"http://example.com/x.pdf\" title=\"Hello World\" lang=\"en-US\" data-v=\"a b  c\" rel=\"next\"></a><a id=a2 href=\"https://Example.com/y.PDF\" title=\"hello\" lang=\"en\" data-v=\"\" rel=\"NEXT\"></a><a id=a3 lang=\"fr-en\" data-v=\"b\" type=\"TeXt\"></a><a id=a4 title></a>", queries = "root [href]\nroot [title]\nroot a[title=\"\"]\nroot [title=\"Hello World\"]\nroot [title=\"hello world\"]\nroot [title=\"hello world\" i]\nroot [title=\"Hello World\" s]\nroot [title~=World]\nroot [title~=world i]\nroot [title~=Hello]\nroot [title~=\"\"]\nroot [data-v~=b]\nroot [data-v~=c]\nroot [data-v~=\" \"]\nroot [lang|=en]\nroot [lang|=EN]\nroot [lang|=en i]\nroot [lang|=fr]\nroot [lang|=\"en-US\"]\nroot [lang|=\"\"]\nroot [title^=Hel]\nroot [title^=hel i]\nroot [title^=\"\"]\nroot [href$=\".pdf\"]\nroot [href$=\".pdf\" i]\nroot [href*=example]\nroot [href*=EXAMPLE i]\nroot [href*=\"\"]\nroot [data-v=\"\"]\nroot [rel=next]\nroot [type=text]\nroot [type=\"text\" s]\nroot [TITLE]\nroot [*|title]\nroot [*|title=\"hello\"]\nroot [|title]\nroot a:not([lang])\nroot [data-v][title]\n", expected = "root [href] => a1,a2\nroot [title] => a1,a2,a4\nroot a[title=\"\"] => a4\nroot [title=\"Hello World\"] => a1\nroot [title=\"hello world\"] => \nroot [title=\"hello world\" i] => a1\nroot [title=\"Hello World\" s] => a1\nroot [title~=World] => a1\nroot [title~=world i] => a1\nroot [title~=Hello] => a1\nroot [title~=\"\"] => \nroot [data-v~=b] => a1,a3\nroot [data-v~=c] => a1\nroot [data-v~=\" \"] => \nroot [lang|=en] => a1,a2\nroot [lang|=EN] => a1,a2\nroot [lang|=en i] => a1,a2\nroot [lang|=fr] => a3\nroot [lang|=\"en-US\"] => a1\nroot [lang|=\"\"] => \nroot [title^=Hel] => a1\nroot [title^=hel i] => a1,a2\nroot [title^=\"\"] => \nroot [href$=\".pdf\"] => a1\nroot [href$=\".pdf\" i] => a1,a2\nroot [href*=example] => a1\nroot [href*=EXAMPLE i] => a1,a2\nroot [href*=\"\"] => \nroot [data-v=\"\"] => a2\nroot [rel=next] => a1,a2\nroot [type=text] => a3\nroot [type=\"text\" s] => \nroot [TITLE] => a1,a2,a4\nroot [*|title] => a1,a2,a4\nroot [*|title=\"hello\"] => a2\nroot [|title] => a1,a2,a4\nroot a:not([lang]) => a4\nroot [data-v][title] => a1,a2\n"),
    TestSelectorEngineCase(markup = "<div id=h1><p id=h2><span id=h3 class=t></span></p><img id=h4><em id=h5></em></div><div id=h6><b id=h7></b><i id=h8 class=t></i></div><div id=h9></div>", queries = "root div:has(img)\nroot div:has(> img)\nroot div:has(> span)\nroot div:has(span)\nroot div:has(.t)\nroot p:has(+ img)\nroot p:has(~ em)\nroot img:has(+ em)\nroot b:has(+ .t)\nroot b:has(~ .t)\nroot div:has(> p > .t)\nroot div:has(p .t)\nroot :has(> .t)\nroot div:not(:has(*))\nroot div:has(.nope)\nroot :is(div, p):has(span)\nroot div:has(b, img)\nroot div:has(> b + i)\nroot div:has(~ div > b)\nroot div:has(+ div)\nroot :has(:scope)\nroot :not(:has(img)) > *\n", expected = "root div:has(img) => h1\nroot div:has(> img) => h1\nroot div:has(> span) => \nroot div:has(span) => h1\nroot div:has(.t) => h1,h6\nroot p:has(+ img) => h2\nroot p:has(~ em) => h2\nroot img:has(+ em) => h4\nroot b:has(+ .t) => h7\nroot b:has(~ .t) => h7\nroot div:has(> p > .t) => h1\nroot div:has(p .t) => h1\nroot :has(> .t) => h2,h6\nroot div:not(:has(*)) => h9\nroot div:has(.nope) => \nroot :is(div, p):has(span) => h1,h2\nroot div:has(b, img) => h1,h6\nroot div:has(> b + i) => h6\nroot div:has(~ div > b) => h1\nroot div:has(+ div) => h1,h6\nroot :has(:scope) => \nroot :not(:has(img)) > * => h3,h7,h8\n"),
    TestSelectorEngineCase(markup = "<h1 id=t1></h1><h2 id=t2></h2><h3 id=t3></h3><h4 id=t4></h4><h5 id=t5></h5><h6 id=t6></h6><p id=t7></p>", queries = "root :heading\nroot h1 ~ :heading\nroot :defined\n", expected = "root :heading => t1,t2,t3,t4,t5,t6\nroot h1 ~ :heading => t2,t3,t4,t5,t6\nroot :defined => t1,t2,t3,t4,t5,t6,t7\n"),
    TestSelectorEngineCase(markup = "<details id=d1 open><summary id=d2></summary></details><details id=d3></details><dialog id=d4 open></dialog><dialog id=d5></dialog><div id=d6></div>", queries = "root :open\nroot details:not(:open)\nroot :popover-open\nroot :target\nroot :hover\nroot :focus\nroot :focus-within\nroot :active\nroot :visited\nroot :link\nroot :autofill\nroot :fullscreen\nroot :playing\nroot :paused\nroot :volume-locked\nroot :valid\nroot :invalid\nroot :checked\nroot :indeterminate\nroot :required\nroot :optional\nroot :read-only\nroot :read-write\n", expected = "root :open => d1,d4\nroot details:not(:open) => d3\nroot :popover-open => \nroot :target => \nroot :hover => \nroot :focus => \nroot :focus-within => \nroot :active => \nroot :visited => \nroot :link => \nroot :autofill => \nroot :fullscreen => \nroot :playing => \nroot :paused => \nroot :volume-locked => \nroot :valid => \nroot :invalid => \nroot :checked => \nroot :indeterminate => \nroot :required => \nroot :optional => \nroot :read-only => d1,d2,d3,d4,d5,d6\nroot :read-write => \n"),
    TestSelectorEngineCase(markup = "<div id=n1 lang=\"en-US\"><p id=n2></p><p id=n3 lang=\"de\"><span id=n4></span></p><p id=n5 lang=\"en-GB-oed\"></p><p id=n6 lang=\"\"></p></div><div id=n7 lang=\"zh-Hant-TW\"></div><div id=n8 lang=\"de-Latn-DE-1996\"></div>", queries = "root :lang(en)\nroot :lang(en-US)\nroot :lang(\"en-GB\")\nroot :lang(de)\nroot :lang(de-DE)\nroot :lang(\"*-DE\")\nroot :lang(zh-TW)\nroot :lang(\"zh-*-TW\")\nroot :lang(fr, de)\nroot p:lang(EN)\n", expected = "root :lang(en) => n1,n2,n5\nroot :lang(en-US) => n1,n2\nroot :lang(\"en-GB\") => n5\nroot :lang(de) => n3,n4,n8\nroot :lang(de-DE) => n8\nroot :lang(\"*-DE\") => n8\nroot :lang(zh-TW) => n7\nroot :lang(\"zh-*-TW\") => n7\nroot :lang(fr, de) => n3,n4,n8\nroot p:lang(EN) => n2,n5\n"),
    TestSelectorEngineCase(markup = "<div id=x1><div id=x2><div id=x3><span id=x4></span></div></div><div id=x5><span id=x6></span><span id=x7></span></div></div>", queries = "root div div span\nroot div > div > span\nroot #x1 > div span\nroot #x1 > span\nroot div:not(#x3) > span\nroot div > div ~ div > span\nroot span + span\nroot span ~ span\nroot #x2 + div span\nroot div:is(#x2, #x5) > div > span\nroot div:where(#x3) span\nroot :is(#x1 #x3) span\nroot :not(div) + span\nroot :is(div > span) + *\n", expected = "root div div span => x4,x6,x7\nroot div > div > span => x4,x6,x7\nroot #x1 > div span => x4,x6,x7\nroot #x1 > span => \nroot div:not(#x3) > span => x6,x7\nroot div > div ~ div > span => x6,x7\nroot span + span => x7\nroot span ~ span => x7\nroot #x2 + div span => x6,x7\nroot div:is(#x2, #x5) > div > span => x4\nroot div:where(#x3) span => x4\nroot :is(#x1 #x3) span => x4\nroot :not(div) + span => x7\nroot :is(div > span) + * => x7\n"),
    TestSelectorEngineCase(markup = "<p id=q1 class=\"a\"></p><p id=q2 class=\"a b\"></p><p id=q3 class=\"A\"></p><p id=q4 class=\"  a  \"></p><p id=q5 class=\"\"></p>", queries = "root .a\nroot .b.a\nroot .A\nroot p:not(.a)\nroot [class]\nroot [class=a]\nroot [class~=a]\nroot [class=\"  a  \"]\n", expected = "root .a => q1,q2,q4\nroot .b.a => q2\nroot .A => q3\nroot p:not(.a) => q3,q5\nroot [class] => q1,q2,q3,q4,q5\nroot [class=a] => q1\nroot [class~=a] => q1,q2,q4\nroot [class=\"  a  \"] => q4\n"),
    TestSelectorEngineCase(markup = "<div id=w1></div>", queries = "root ::before\nroot div::before\nroot div:first-letter\nroot ::-webkit-foo\nroot :nth-child(\nroot a ::part(x)\nroot foo|div\nroot svg|div\nroot *|div\nroot |div\nroot div:scope\nroot :hover > div\n", expected = "root ::before => \nroot div::before => \nroot div:first-letter => \nroot ::-webkit-foo => \nroot :nth-child( => error\nroot a ::part(x) => \nroot foo|div => error\nroot svg|div => error\nroot *|div => w1\nroot |div => \nroot div:scope => \nroot :hover > div => \n"),
    TestSelectorEngineCase(markup = "<div id=k1 class=a><div id=k2 class=b><div id=k3 class=b><span id=k4 class=c></span></div></div></div><div id=k5 class=b><div id=k6 class=a><span id=k7 class=c></span></div></div>", queries = "root .a > .b .c\nroot .a > .b > .c\nroot .b > .b > .c\nroot .a .b .c\nroot .b .a > .c\nroot .b > .a .c\nroot div > div > div > span\nroot .a > .b .b > .c\nroot :scope > .b .c\ndoc :scope\ndoc :scope > *\ndoc body > :scope\n", expected = "root .a > .b .c => k4\nroot .a > .b > .c => \nroot .b > .b > .c => k4\nroot .a .b .c => k4\nroot .b .a > .c => k7\nroot .b > .a .c => k7\nroot div > div > div > span => k4,k7\nroot .a > .b .b > .c => k4\nroot :scope > .b .c => k7\ndoc :scope => \ndoc :scope > * => \ndoc body > :scope => \n"),
]