1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301
|
CSS parsing tests
#################
This repository contains implementation-independent test for CSS parsers,
based on the 2013 draft of the `CSS Syntax Level 3`_ specification.
.. _CSS Syntax Level 3: http://dev.w3.org/csswg/css-syntax-3/
The upstream repository for these tests is at
https://github.com/SimonSapin/css-parsing-tests
Projects using this
===================
CSS parsers using these tests:
* `tinycss2 <https://github.com/SimonSapin/tinycss2>`_ (Python)
* `rust-cssparser <https://github.com/mozilla-servo/rust-cssparser>`_
(Rust, used in `Servo <https://github.com/mozilla/servo/>`_)
* `Crass <https://github.com/rgrove/crass/>`_ (Ruby)
Importing
=========
The recommended way to use these tests in an implementation
is to import them with git-subtree_.
.. _git-subtree: https://github.com/git/git/tree/master/contrib/subtree
To import the first time to a ``./css-parsing-tests`` sub-directory,
run this from the top-level of a git repository::
git subtree add -P css-parsing-tests https://github.com/SimonSapin/css-parsing-tests.git master
Later, to merge changes made in the upstream repository, run::
git subtree pull -P css-parsing-tests https://github.com/SimonSapin/css-parsing-tests.git master
Test files
==========
CSS Syntax specification describes a number of "functions".
Each ``.json`` file in this repository corresponds to such a function.
The files are encoded as UTF-8
and each contain a JSON array with an even number of items,
where each pair of items is one function input
associated with the expected result.
``component_value_list.json``
Tests `Parse a list of component values
<http://dev.w3.org/csswg/css-syntax-3/#parse-a-list-of-component-values>`_.
The Unicode input is represented by a JSON string,
the output as an array of `component values`_ as described below.
``component_value_list.json``
Tests `Parse a component value
<http://dev.w3.org/csswg/css-syntax-3/#parse-a-component-value>`_.
The Unicode input is represented by a JSON string,
the output as a `component value`_.
``declaration_list.json``
Tests `Parse a list of declarations
<http://dev.w3.org/csswg/css-syntax-3/#parse-a-list-of-declarations>`_.
The Unicode input is represented by a JSON string,
the output as an array of declarations_ and at-rules_.
``one_declaration.json``
Tests `Parse a declaration
<http://dev.w3.org/csswg/css-syntax-3/#parse-a-declaration>`_.
The Unicode input is represented by a JSON string,
the output as a declaration_.
``one_rule.json``
Tests `Parse a rule
<http://dev.w3.org/csswg/css-syntax-3/#parse-a-rule>`_.
The Unicode input is represented by a JSON string,
the output as a `qualified rule`_ or at-rule_.
``rule_list.json``
Tests `Parse a list of rules
<http://dev.w3.org/csswg/css-syntax-3/#parse-a-list-of-rules>`_.
The Unicode input is represented by a JSON string,
the output as a list of `qualified rules`_ or at-rules_.
``stylesheet.json``
Tests `Parse a stylesheet
<http://dev.w3.org/csswg/css-syntax-3/#parse-a-stylesheet>`_.
The Unicode input is represented by a JSON string,
the output as a list of `qualified rules`_ or at-rules_.
``stylesheet_bytes.json``
Tests `Parse a stylesheet
<http://dev.w3.org/csswg/css-syntax-3/#parse-a-stylesheet>`_
together with `The input byte stream
<http://dev.w3.org/csswg/css-syntax/#input-byte-stream>`_.
The input is represented as a JSON object containing:
* A required ``css_bytes``, the input byte string,
represented as a JSON string where code points U+0000 to U+00FF
represent bytes of the same value.
* An optional ``protocol_encoding``,
a protocol encoding label as a JSON string, or null.
* An optional ``environment_encoding``,
an environment encoding label as a JSON string, or null.
* An optional ``comment`` that is ignored.
The output is represented a list of `qualified rules`_ or at-rules_.
``color3.json``
Tests the ``<color>`` syntax `defined in CSS Color Level 3
<http://www.w3.org/TR/css3-color/#colorunits>`_.
The Unicode input is represented by a JSON string,
the output as one of:
* null if the input is not a valid color in CSS syntax
* The string "currentColor" for the currentColor keyword
* An array of length 4 for every other values:
four (floating point) numbers for the Red, Green, Blue and Alpha channel.
Each value is between 0 and 1.
``color3_hsl.json``
Same as ``color3.json``.
This file is generated by the ``make_color3_hsl.py`` Python script.
``color3_keywords.json``
Same as ``color3.json``,
except that the values for the Red, Green and Blue channel
are between 0 and 255.
This file is generated by the ``make_color3_keywords.py`` Python script.
``An+B.json``
Tests the `An+B <http://dev.w3.org/csswg/css-syntax/#the-anb-type>`_
syntax defined in CSS Syntax Level 3.
This `differs <http://dev.w3.org/csswg/css-syntax/#changes>`_ from the
`nth grammar rule <http://www.w3.org/TR/css3-selectors/#nth-child-pseudo>`_
in Selectors Level 3 only in that
``-`` charecters and digits can be escaped in some cases.
The Unicode input is represented by a JSON string,
the output as null for invalid syntax,
or an array of two integers ``[A, B]``.
Result representation
=====================
AST nodes (the results of parsing) are represented in JSON as follow.
This representation was chosen to be compact
(and thus less annoying to write by hand)
while staying unambiguous.
For example, the difference between ``@import`` and ``\@import`` is not lost:
they are represented as ``["at-keyword", "import"]`` and ``["ident", "@import"]``,
respectively.
Rules and declarations
----------------------
.. _at-rule:
.. _at-rules:
.. _qualified rule:
.. _qualified rules:
.. _declaration:
.. _declarations:
At-rule
An array of length 4: the string ``"at-rule"``,
the name (value of the at-keyword) as a string,
the prelude as a nested array of `component values`_,
and the optional block as a nested array of component value, or null.
Qualified rule
An array of length 3: the string ``"qualified rule"``,
the prelude as a nested array of `component values`_,
and the block as a nested array of component value.
Declaration
An array of length 4: the string ``"declaration"``, the name as a string,
the value as a nested array of `component values`_,
and a the important flag as a boolean.
.. _component value:
.. _component values:
Component values
----------------
<ident>
Array of length 2: the string ``"ident"``, and the value as a string.
<at-keyword>
Array of length 2: the string ``"at-keyword"``, and the value as a string.
<hash>
Array of length 3: the string ``"hash"``, the value as a string,
and the type as the string ``"id"`` or ``"unrestricted"``.
<string>
Array of length 2: the string ``"string"``, and the value as a string.
<bad-string>
Array of length 1: the string ``"bad-string"``.
<url>
Array of length 2: the string ``"url"``, and the value as a string.
<bad-url>
Array of length 1: the string ``"bad-url"``.
<delim>
The value as a one-character string.
<number>
Array of length 4: the string ``"number"``, the representation as a string,
the value as a number, and the type as the string ``"integer"`` or ``"number"``.
<percentage>
Array of length 4: the string ``"percentage"``, the representation as a string,
the value as a number, and the type as the string ``"integer"`` or ``"number"``.
<dimension>
Array of length 4: the string ``"dimension"``, the representation as a string,
the value as a number, the type as the string ``"integer"`` or ``"number"``,
and the unit as a string.
<unicode-range>
Array of length 3: the string ``"unicode-range"``,
followed by the *start* and *end* integers as two numbers.
<include-match>
The string ``"~="``.
<dash-match>
The string ``"|="``.
<prefix-match>
The string ``"^="``.
<suffix-match>
The string ``"$="``.
<substring-match>
The string ``"*="``.
<column>
The string ``"||"``.
<whitespace>
The string ``" "`` (a single space.)
<CDO>
The string ``"<!--"``.
<CDC>
The string ``"-->"``.
<colon>
The string ``":"``.
<semicolon>
The string ``";"``.
<comma>
The string ``","``.
{} block
An array of length N+1: the string ``"{}"``
followed by the N `component values`_ of the block’s content.
[] block
An array of length N+1: the string ``"[]"``
followed by the N `component values`_ of the block’s content.
() block
An array of length N+1: the string ``"()"``
followed by the N `component values`_ of the block’s content.
Function
An array of length N+2: the string ``"function"``
and the name of the function as a string
followed by the N `component values`_ of the function’s arguments.
<bad-string>
The array of two strings ``["error", "bad-string"]``.
<bad-url>
The array of two strings ``["error", "bad-url"]``.
Unmatched <}>
The array of two strings ``["error", "}"]``.
Unmatched <]>
The array of two strings ``["error", "]"]``.
Unmatched <)>
The array of two strings ``["error", ")"]``.
|