Bug 1523562 [wpt PR 15060] - An+B Parsing, a=testonly
authorTab Atkins Jr <jackalmage@gmail.com>
Fri, 01 Feb 2019 11:39:48 +0000
changeset 458153 b8829a6e3dac738893ea8852f168b4b669128d1a
parent 458152 d53221b682207601eb560fa7480ebcfcba0115b0
child 458154 a6c6d6a83e42e7b72d73d33afbbbd89cb70e136a
push id35518
push useropoprus@mozilla.com
push dateFri, 08 Feb 2019 09:55:14 +0000
treeherdermozilla-central@3a3e393396f4 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewerstestonly
bugs1523562, 15060
milestone67.0a1
first release with
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
last release without
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
Bug 1523562 [wpt PR 15060] - An+B Parsing, a=testonly Automatic update from web-platform-tests An+B Parsing Exercise all the An+B parsing clauses -- Merge pull request #15060 from web-platform-tests/tabatkins-patch-3 An+B Parsing -- wpt-commits: 64471426ded3256f691420ba40df523d9a73ebdd, 129adcb38de49f31df9dfaea8d5d32f032cad2da wpt-pr: 15060
testing/web-platform/tests/css/css-syntax/anb-serialization.html
new file mode 100644
--- /dev/null
+++ b/testing/web-platform/tests/css/css-syntax/anb-serialization.html
@@ -0,0 +1,125 @@
+<!doctype html>
+<title>An+B Parsing</title>
+<script src="/resources/testharness.js"></script>
+<script src="/resources/testharnessreport.js"></script>
+<style>
+
+foo { color: blue; }
+
+</style>
+
+<meta name="author" title="Tab Atkins-Bittner">
+<link rel=help href="https://drafts.csswg.org/css-syntax/#the-anb-type">
+
+<script>
+
+function roundtripANB(str) {
+    const rule = document.styleSheets[0].cssRules[0];
+    rule.selectorText = "foo";
+    rule.selectorText = `:nth-child(${str})`;
+    // Check for parse error.
+    if(rule.selectorText == "foo") return "parse error";
+    return rule.selectorText.slice(11, -1);
+}
+function testANB(input, expected) {
+    test(()=>{
+        assert_equals(roundtripANB(input), expected);
+    }, `"${input}" becomes "${expected}"`);
+}
+
+/* Just going down all the syntax clauses one-by-one */
+//  odd | even |
+testANB("odd", "2n+1");
+testANB("even", "2n");
+//  <integer> |
+testANB("1", "1");
+testANB("+1", "1");
+testANB("-1", "-1");
+//
+//  <n-dimension> |
+testANB("5n", "5n");
+testANB("5N", "5n");
+//  '+'?† n |
+testANB("+n", "n");
+testANB("n", "n");
+testANB("N", "n");
+testANB("+ n", "parse error");
+//  -n |
+testANB("-n", "-n");
+testANB("-N", "-n");
+//
+//  <ndashdigit-dimension> |
+testANB("5n-5", "5n-5");
+//  '+'?† <ndashdigit-ident> |
+testANB("+n-5", "n-5");
+testANB("n-5", "n-5");
+testANB("+ n-5", "parse error");
+//  <dashndashdigit-ident> |
+testANB("-n-5", "-n-5");
+//
+//  <n-dimension> <signed-integer> |
+testANB("5n +5", "5n+5");
+testANB("5n -5", "5n-5");
+//  '+'?† n <signed-integer> |
+testANB("+n +5", "n+5");
+testANB("n +5", "n+5");
+testANB("+n -5", "n-5");
+testANB("+ n +5", "parse error");
+testANB("n 5", "parse error");
+//  -n <signed-integer> |
+testANB("-n +5", "-n+5");
+testANB("-n -5", "-n-5");
+testANB("-n 5", "parse error");
+//
+//  <ndash-dimension> <signless-integer> |
+testANB("5n- 5", "5n-5");
+testANB("5n- -5", "parse error");
+testANB("5n- +5", "parse error");
+testANB("-5n- 5", "-5n-5");
+//  '+'?† n- <signless-integer> |
+testANB("+n- 5", "n-5");
+testANB("n- 5", "n-5");
+testANB("+ n- 5", "parse error");
+testANB("n- +5", "parse error");
+testANB("n- -5", "parse error");
+//  -n- <signless-integer> |
+testANB("-n- 5", "-n-5");
+testANB("-n- +5", "parse error");
+testANB("-n- -5", "parse error");
+//
+//  <n-dimension> ['+' | '-'] <signless-integer>
+testANB("5n + 5", "5n+5");
+testANB("5n - 5", "5n-5");
+testANB("5n + +5", "parse error");
+testANB("5n + -5", "parse error");
+testANB("5n - +5", "parse error");
+testANB("5n - -5", "parse error");
+//  '+'?† n ['+' | '-'] <signless-integer> |
+testANB("+n + 5", "n+5");
+testANB("n + 5", "n+5");
+testANB("+ n + 5", "parse error");
+testANB("+n - 5", "n-5");
+testANB("+n + +5", "parse error");
+testANB("+n + -5", "parse error");
+testANB("+n - +5", "parse error");
+testANB("+n - -5", "parse error");
+//  -n ['+' | '-'] <signless-integer>
+testANB("-n + 5", "-n+5");
+testANB("-n - 5", "-n-5");
+testANB("-n + +5", "parse error");
+testANB("-n + -5", "parse error");
+testANB("-n - +5", "parse error");
+testANB("-n - -5", "parse error");
+
+/* Swapped ordering is invalid */
+testANB("1 - n", "parse error");
+testANB("0 - n", "parse error");
+testANB("-1 + n", "parse error");
+
+/* Odd space usage */
+testANB("2 n + 2", "parse error");
+testANB("- 2n", "parse error");
+testANB("+ 2n", "parse error");
+testANB("+2 n", "parse error");
+
+</script>