<!doctype html>
<html>
<head>
<script src="../../resources/js-test.js"></script>
<style id="style-container">
</style>
</head>
<body>
</body>
<script>
description('Test the parsing of :lang(stringList) for querySelector and style.');

function testValidLanguageRange(languageRangeString, expectedSerializedLanguageRange) {
    shouldNotThrow('document.querySelector(\':lang(' + languageRangeString.replace(/\\/g, '\\\\') + ')\')');

    var styleContainer = document.getElementById('style-container');
    styleContainer.innerHTML = ':lang(' + languageRangeString + ') { }';
    shouldBe("document.getElementById('style-container').sheet.cssRules.length", "1");
    if (expectedSerializedLanguageRange.indexOf('"') == 0)
        expectedSerializedLanguageRange = expectedSerializedLanguageRange.replace(/\\/g, "");
    shouldBeEqualToString("document.getElementById('style-container').sheet.cssRules[0].selectorText", ':lang(' + expectedSerializedLanguageRange + ')');
    styleContainer.innerHTML = '';
}

var validLanguageRanges = [

    "e",
    "en",
    "en-",
    "en--",
    "en---",
    "en-fr",
    "en-fr-",
    "en-fr--",
    "en--fr",
    "en---fr",
    "en---fr---",

    "de-DE",
    "de-DE-1996", 
    "de-Latn-DE", 
    "de-Latf-DE", 
    "de-Latn-DE-1996", 
    "de-CH", 
    "it-CH", 
    "fr-CH", 
    "rm-CH",

    '"*-CH"',
    '"*-DE-1996"',
    '"*-br-zh"',
    "id-\\*-sumatra",
    '"*-en-\\*-fr"',
    '"*-en-\\*-\\*"',

    "\\*",
    '"*-\\*"',
    '"*-\\*-\\*"',
    '"*-\\*-\\*"',

    '"ab-\\*"',
    '"*-ab-\\*"',
    '"*-ab-\\*-"',
    '"*-ab-\\*--"',
    '"*-ab-\\*---"',

    '"*-foo-\\:"',
    '"*-foo-\\:"',
    '"*-foo-\\:\\`\\)"',
    '"*-foo-\\:\\*"',

    '"en-\\*"',
    '"fr-*"'
];

debug("valid language ranges");
for (var i = 0; i < validLanguageRanges.length; ++i) {
    var languageRangeString = validLanguageRanges[i];
    testValidLanguageRange(languageRangeString, languageRangeString);
    testValidLanguageRange(languageRangeString + "    ", languageRangeString);
}

</script>
</html>
