input-preprocessing.html 1.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546
  1. <!doctype html>
  2. <title>Input Preprocessing</title>
  3. <script src="../../resources/testharness.js"></script>
  4. <script src="../../resources/testharnessreport.js"></script>
  5. <style>
  6. foo { color: blue; }
  7. </style>
  8. <meta name="author" title="Tab Atkins-Bittner">
  9. <link rel=help href="https://drafts.csswg.org/css-syntax/#input-preprocessing">
  10. <script>
  11. function roundtripIdent(str) {
  12. const rule = document.styleSheets[0].cssRules[0];
  13. rule.selectorText = "original-ident";
  14. rule.selectorText = str;
  15. // Check for parse error.
  16. if(rule.selectorText == "original-ident") return "parse error";
  17. return rule.selectorText;
  18. }
  19. function testParsing(input, expected) {
  20. test(()=>{
  21. assert_equals(roundtripIdent(input), expected);
  22. }, `"${input}" becomes "${expected}"`);
  23. }
  24. /* Can't figure out how to test the newline normalization... */
  25. /* NULL becomes FFFD */
  26. testParsing("foo\x00", "foo\ufffd");
  27. testParsing("f\x00oo", "f\ufffdoo");
  28. testParsing("\x00foo", "\ufffdfoo");
  29. testParsing("\x00", "\ufffd");
  30. testParsing("\x00\x00\x00", "\ufffd\ufffd\ufffd");
  31. /* surrogates become FFFD */
  32. testParsing("foo\ud800", "foo\ufffd");
  33. testParsing("f\ud800oo", "f\ufffdoo");
  34. testParsing("\ud800foo", "\ufffdfoo");
  35. testParsing("\ud800", "\ufffd");
  36. testParsing("\ud800\ud800\ud800", "\ufffd\ufffd\ufffd");
  37. </script>