<!doctype html>
<html>
<head>
<script src="../../resources/js-test-pre.js"></script>
<style>
:lang(de-DE, DE-de) {
    color: rgb(1, 2, 3);
}
</style>
</head>
<body>
    <div lang="en"></div>
    <div lang="en-"></div>
    <div lang="en--"></div>

    <div lang="de-DE" class="de"></div>
    <div lang="de-de" class="de"></div>
    <div lang="de-De" class="de"></div>
    <div lang="de-dE" class="de"></div>
    <div lang="de-DE-1996" class="de"></div>
    <div lang="de-Latn-DE" class="de"></div>
    <div lang="de-Latf-DE" class="de"></div>
    <div lang="de-Latn-DE-1996" class="de"></div>

    <div lang="Latn-de"></div>
    <div lang="Latf-de"></div>

    <div lang="foo--bar"></div>
    <div lang="id---Java"></div>

    <div lang="tic-tac-tac-toe"></div>

    <div lang="fr-x"></div>
    <div lang="fr-xenomorph"></div>
    <div lang="fr-x-xenomorph"></div>

    <div lang="cocoa-1-bar"></div>
    <div lang="cocoa-a-bar"></div>

    <div lang="a"></div>
    <div lang="a-fr-lang"></div>
    <div lang="b-fr-lang"></div>

    <div lang="de-CH"></div>
    <div lang="it-CH"></div>
    <div lang="fr-CH"></div>
    <div lang="rm-CH"></div>
    <div lang="es-CH"></div>

    <div lang="es1-KK-aa-bb-cc-dd"></div>
    <div lang="es2-KL-aa-bb-cc-dd"></div>
    <div lang="es3-KM-aa-bb-cc-dd"></div>

    <div lang="fooÉ"></div>
    <div lang="foöÉ-bÁr"></div>
    <div lang="foöÉbÁr"></div>

    <script>
    description('Verify selector specifying extended filtering of :lang() pseudo class');

    shouldBe('document.querySelectorAll(":lang(en)").length', '3');
    shouldBe('document.querySelectorAll(":lang(en-)").length', '2');
    shouldBe('document.querySelectorAll(":lang(en--)").length', '1');
    shouldBe('document.querySelectorAll(":lang(en---)").length', '0');

    debug('');

    shouldBe('document.querySelectorAll(":lang(de-de)").length', '8');
    shouldBe('document.querySelectorAll(":lang(de-DE)").length', '8');
    shouldBe('document.querySelectorAll(":lang(DE-de)").length', '8');
    shouldBe('document.querySelectorAll(":lang(dE-dE)").length', '8');
    shouldBe('document.querySelectorAll(":lang(De-De)").length', '8');
    shouldBe('document.querySelectorAll(":lang(DE-DE)").length', '8');

    shouldBe('document.querySelectorAll(":lang(Latn)").length', '1');
    shouldBe('document.querySelectorAll(":lang(Latf)").length', '1');
    shouldBe('document.querySelectorAll(":lang(Latn-de)").length', '1');
    shouldBe('document.querySelectorAll(":lang(Latf-de)").length', '1');

    shouldBe('document.querySelectorAll(":lang(Latn, de-Latn)").length', '3');
    shouldBe('document.querySelectorAll(":lang(Latf, de-Latf)").length', '2');

    shouldBe('document.querySelectorAll(":lang(Latn, de-Latn)").length', '3');
    shouldBe('document.querySelectorAll(":lang(Latf, de-Latf)").length', '2');

    shouldBe('document.querySelectorAll(":lang(de-DE--, de-DE--)").length', '0');

    debug('');

    for (var i = 0; i < document.querySelectorAll(":lang(de-DE, DE-de)").length; i++) {
        shouldBeEqualToString('getComputedStyle(document.querySelectorAll(":lang(de-DE, DE-de)")[' + i + ']).color', 'rgb(1, 2, 3)');
    }

    debug('');

    shouldBeEqualToString('getComputedStyle(document.querySelector(":lang(Latn, Latn-de)")).color', 'rgb(0, 0, 0)');
    shouldBeEqualToString('getComputedStyle(document.querySelector(":lang(Latf, Latf-de)")).color', 'rgb(0, 0, 0)');
    shouldBeEqualToString('getComputedStyle(document.querySelector(":lang(Latf, Latn)")).color', 'rgb(0, 0, 0)');
    shouldBeEqualToString('getComputedStyle(document.querySelector(":lang(Latf, Latn)")).color', 'rgb(0, 0, 0)');

    debug('');

    shouldBe('document.querySelectorAll(":lang(-en)").length', '0');
    shouldBe('document.querySelectorAll(":lang(-en-)").length', '0');
    shouldBe('document.querySelectorAll(":lang(-en--)").length', '0');

    shouldBe('document.querySelectorAll(":lang(-en, -en-)").length', '0');
    shouldBe('document.querySelectorAll(":lang(-en-, -en--)").length', '0');

    debug(''); 

    shouldBe('document.querySelectorAll(":lang(fr-x)").length', '0');
    shouldBe('document.querySelectorAll(":lang(fr-xenomorph)").length', '1');

    debug('');

    shouldBe('document.querySelectorAll(":lang(cocoa-1)").length', '0');
    shouldBe('document.querySelectorAll(":lang(cocoa-a)").length', '0');
    shouldBe('document.querySelectorAll(":lang(cocoa-bar)").length', '0');

    shouldBe('document.querySelectorAll(":lang(cocoa-1, cocoa-bar)").length', '0');
    shouldBe('document.querySelectorAll(":lang(cocoa-a, cocoa-bar)").length', '0');
    shouldBe('document.querySelectorAll(":lang(cocoa-1, cocoa-a)").length', '0');

    debug('');

    shouldBe('document.querySelectorAll(":lang(foo)").length', '1');
    shouldBe('document.querySelectorAll(":lang(foo-bar)").length', '1');
    shouldBe('document.querySelectorAll(":lang(foo--bar)").length', '1');
    shouldBe('document.querySelectorAll(":lang(foo-)").length', '1');
    shouldBe('document.querySelectorAll(":lang(foo--)").length', '0');

    shouldBe('document.querySelectorAll(":lang(foo, foo-)").length', '1');
    shouldBe('document.querySelectorAll(":lang(foo-bar, foo--bar)").length', '1');
    shouldBe('document.querySelectorAll(":lang(foo-, foo--)").length', '1');
    shouldBe('document.querySelectorAll(":lang(foo--, foo---)").length', '0');

    shouldBe('document.querySelectorAll(":lang(id)").length', '1');
    shouldBe('document.querySelectorAll(":lang(id-)").length', '1');
    shouldBe('document.querySelectorAll(":lang(id--)").length', '1');
    shouldBe('document.querySelectorAll(":lang(id---Java)").length', '1');
    shouldBe('document.querySelectorAll(":lang(id--Java)").length', '1');
    shouldBe('document.querySelectorAll(":lang(id-Java)").length', '1');
    shouldBe('document.querySelectorAll(":lang(id---)").length', '0');

    shouldBe('document.querySelectorAll(":lang(id, id-)").length', '1');
    shouldBe('document.querySelectorAll(":lang(id-, id--)").length', '1');
    shouldBe('document.querySelectorAll(":lang(id--Java, id---Java)").length', '1');
    shouldBe('document.querySelectorAll(":lang(id-Java, id--Java)").length', '1');
    shouldBe('document.querySelectorAll(":lang(id---, id----)").length', '0');

    debug('');

    shouldBe('document.querySelectorAll(":lang(tic-tac-toe)").length', '1');
    shouldBe('document.querySelectorAll(":lang(tic-toe-tac)").length', '0');

    debug('');

    shouldBe('document.querySelectorAll(":lang(\\\\*)").length', '35');
    shouldBe('document.querySelectorAll(\':lang("*-CH")\').length', '5');

    debug('');  

    shouldBe('document.querySelectorAll(":lang(a)").length', '2');
    shouldBe('document.querySelectorAll(":lang(a-\\\\*)").length', '1');
    shouldBe('document.querySelectorAll(\':lang("*-fr-\\\\*\")\').length', '2');
    shouldBe('document.querySelectorAll(\':lang("*-\\\\*-lang\")\').length', '2');   

    shouldBe('document.querySelectorAll(\':lang("*-\\\\*-aa-bb-cc-dd")\').length', '3');
    shouldBe('document.querySelectorAll(\':lang("*-\\\\*-\\\\*-bb-cc-dd")\').length', '3');
    shouldBe('document.querySelectorAll(\':lang("*-\\\\*-\\\\*-\\\\*-cc-dd")\').length', '3');
    shouldBe('document.querySelectorAll(\':lang("*-\\\\*-\\\\*-\\\\*-\\\\*-dd")\').length', '3');
    shouldBe('document.querySelectorAll(\':lang("*-\\\\*-\\\\*-\\\\*-\\\\*-\\\\*\")\').length', '3');
    shouldBe('document.querySelectorAll(\':lang("*-\\\\*-aa-\\\\*-cc-\\\\*\")\').length', '3');
    shouldBe('document.querySelectorAll(\':lang("*-\\\\*-\\\\*-bb-\\\\*")\').length', '3');

    shouldBe('document.querySelectorAll(":lang(fooÉ)").length', '1');
    shouldBe('document.querySelectorAll(":lang(fOOÉ)").length', '1');
    shouldBe('document.querySelectorAll(":lang(FoOÉ)").length', '1');
    shouldBe('document.querySelectorAll(":lang(FOOÉ)").length', '1');
    shouldBe('document.querySelectorAll(":lang(fooé)").length', '0');
    shouldBe('document.querySelectorAll(":lang(FOOé)").length', '0');

    shouldBe('document.querySelectorAll(":lang(foöÉ-bÁr)").length', '1');
    shouldBe('document.querySelectorAll(":lang(FoöÉ-bÁr)").length', '1');
    shouldBe('document.querySelectorAll(":lang(FOöÉ-bÁr)").length', '1');
    shouldBe('document.querySelectorAll(":lang(FOòÉ-bÁr)").length', '0');
    shouldBe('document.querySelectorAll(":lang(FOòę-bÁr)").length', '0');

    shouldBe('document.querySelectorAll(":lang(foöÉ-\\\\*)").length', '1');
    shouldBe('document.querySelectorAll(":lang(\\\\*-bÁr)").length', '1');
    shouldBe('document.querySelectorAll(":lang(\\\\*-BÁr)").length', '1');
    shouldBe('document.querySelectorAll(":lang(\\\\*-BÁR)").length', '1');
    shouldBe('document.querySelectorAll(":lang(\\\\*-Bár)").length', '0');
    shouldBe('document.querySelectorAll(":lang(\\\\*-báR)").length', '0');
    shouldBe('document.querySelectorAll(":lang(\\\\*-BáR)").length', '0');

    debug('');

    shouldBe('document.querySelectorAll(":lang(FOöÉ-BÁr)").length', '1');
    shouldBe('document.querySelectorAll(":lang(FOöÉ-BÁ)").length', '0');
    shouldBe('document.querySelectorAll(":lang(FOöÉ-B)").length', '0');

    shouldBe('document.querySelectorAll(":lang(f-BÁr)").length', '0');
    shouldBe('document.querySelectorAll(":lang(fO-BÁr)").length', '0');
    shouldBe('document.querySelectorAll(":lang(fOö-BÁr)").length', '0');
    shouldBe('document.querySelectorAll(":lang(FOöÉ-BÁr1)").length', '0');
    shouldBe('document.querySelectorAll(":lang(FOöÉ-BÁr12)").length', '0');
    shouldBe('document.querySelectorAll(":lang(FOöÉ-BÁr123)").length', '0');

    shouldBe('document.querySelectorAll(":lang(F-Xe)").length', '0');
    shouldBe('document.querySelectorAll(":lang(Fr-Xe)").length', '0');
    shouldBe('document.querySelectorAll(":lang(fr-Xe)").length', '0');
    shouldBe('document.querySelectorAll(":lang(fr-Xen)").length', '0');
    shouldBe('document.querySelectorAll(":lang(fr-Xeno)").length', '0');
    shouldBe('document.querySelectorAll(":lang(fr-Xenom)").length', '0');
    shouldBe('document.querySelectorAll(":lang(fr-Xenomo)").length', '0');
    shouldBe('document.querySelectorAll(":lang(fr-Xenomor)").length', '0');
    shouldBe('document.querySelectorAll(":lang(fr-Xenomorp)").length', '0');
    shouldBe('document.querySelectorAll(":lang(fr-Xènömòrph)").length', '0');
    shouldBe('document.querySelectorAll(":lang(FR-XENOMORPH)").length', '1');

    shouldBe('document.querySelectorAll(":lang(foöÉbÁr)").length', '1');
    shouldBe('document.querySelectorAll(":lang(foöÉbÁ)").length', '0');
    shouldBe('document.querySelectorAll(":lang(foöÉb)").length', '0');
    shouldBe('document.querySelectorAll(":lang(foöÉ)").length', '1');
    shouldBe('document.querySelectorAll(":lang(foö)").length', '0');
    shouldBe('document.querySelectorAll(":lang(fo)").length', '0');
    shouldBe('document.querySelectorAll(":lang(f)").length', '0');

    debug('');

    shouldThrow('document.querySelectorAll(":lang(*)").length');
    shouldThrow('document.querySelectorAll(":lang(*foöÉ)").length');
    shouldThrow('document.querySelectorAll(":lang(--en--)").length');
    shouldThrow('document.querySelectorAll(":lang(---en---)").length');
    shouldThrow('document.querySelectorAll(":lang(en us- de- fr-).length")');
    shouldThrow('document.querySelectorAll(":lang(-\\\\* \\\\*-)").length');

    </script>
    <script src="../../resources/js-test-post.js"></script>
</body>
</html>
