This repository contains implementation-independent test for CSS parsers, based
on the 2025 Editor's Draft of the CSS Syntax Level 3
specification.
The upstream repository for these tests is at CourtBouillon/css-parsing-tests
CSS parsers using these tests:
tinycss(Ruby)
The recommended way to use these tests in an implementation is to import them with git-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/heyvito/css-parsing-tests.git main
Later, to merge changes made in the upstream repository, run:
git subtree pull -P css-parsing-tests https://github.com/heyvito/css-parsing-tests.git main
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.
Tests 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.
Tests Parse a component value.
The Unicode input is represented by a JSON string, the output as a
component value.
Tests Parse a block’s contents.
The Unicode input is represented by a JSON string,
the output as an array of declarations and at-rules.
TODO: Merge
declaration_list.jsonandblocks_contents.jsonintoblocks_contents.json
Tests Parse a block’s contents.
The Unicode input is represented by a JSON string,
the output as an array of declarations, at-rules and qualified rules.
Tests Parse a declaration.
The Unicode input is represented by a JSON string, the output as a
declaration.
Tests Parse a rule.
The Unicode input is represented by a JSON string, the output as a
qualified rule or at-rule.
Tests Parse a stylesheet's contents.
The Unicode input is represented by a JSON string, the output as a list of
qualified rules or at-rules.
Tests Parse a stylesheet.
The Unicode input is represented by a JSON string, the output as a list of
qualified rules or at-rules.
Tests Parse a stylesheet together with _The 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
commentthat is ignored.
The output is represented a list of qualified rules or at-rules.
Tests the <color> syntax defined in both in
CSS Color Level 3 and
CSS Color Level 4.
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, or
- a string corresponding to the serialization of the result, as defined in level 4.
Tests the An+B syntax
defined in CSS Syntax Level 3.
This differs from the
nth grammar rule in
Selectors Level 3 only in that - characters 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].
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.
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.
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.
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.
Array of length 2: the string "ident", and the value as a string.
Array of length 2: the string "at-keyword", and the value as a string.
Array of length 3: the string "hash", the value as a string,
and the type as the string "id" or "unrestricted".
Array of length 2: the string "string", and the value as a string.
Array of length 1: the string "bad-string".
Array of length 2: the string "url", and the value as a string.
Array of length 1: the string "bad-url".
The value as a one-character string.
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".
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".
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.
Array of length 3: the string "unicode-range",
followed by the start and end integers as two numbers.
The string " " (a single space.)
The string "<!--".
The string "-->".
The string ":".
The string ";".
The string ",".
An array of length N+1: the string "{}"
followed by the N component values of the block’s content.
An array of length N+1: the string "[]"
followed by the N component values of the block’s content.
An array of length N+1: the string "()"
followed by the N component values of the block’s content.
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.
The array of two strings ["error", "bad-string"].
The array of two strings ["error", "bad-url"].
The array of two strings ["error", "}"].
The array of two strings ["error", "]"].
The array of two strings ["error", ")"].