These are test cases for implementations of Structured Fields for HTTP.
Each test file is a JSON document that contains an array of test records. A test record is an object with the following members:
name
: A string describing the testraw
: An array of strings, each representing a field value receivedheader_type
: One of "item", "list", "dictionary"expected
: The expected data structure after parsing (if successful). Required, unless must_fail
is true
.must_fail
: boolean indicating whether the test is required to fail. Defaults to false
.can_fail
: boolean indicating whether failing this test is acceptable; for SHOULDs. Defaults to false
.canonical
: An array of strings representing the canonical form of the field value, if it is different from raw
. Not applicable if must_fail
is true
.The expected
data structure maps the types in Structured Fields to JSON as follows:
token
__type Object (see below)binary
__type Object (see below)date
__type Object (see below)displaystring
__type Object (see below)For any test that case that has a valid outcome (i.e. must_fail
is not true
) the expected
data structure can be serialised. The expected result of this serialisation is the canonical
member if specified, or raw
otherwise. The canonical form of a List or Dictionary with no members is an empty array, to represent the field being omitted.
Test cases in the serialisation-tests
directory can be used to test serialisation of an invalid or non-canonical value. The expected
structure (as defined above) should serialise to the canonical
form, unless must_fail
is true
-- in which case the value cannot be serialised. These cases do not have a raw
element.
JSON Schemas for these formats are provided in the schemas
directory.
Because JSON doesn't natively accommodate some data types that Structured Fields does, the expected
member uses an object with a __type
member and a value
member to represent these values.
For example:
{
"__type": "token",
"value": "foo"
}
... carries a "foo" token. The following types are defined:
token
: carries a Token as a JSON string; e.g., "bar"binary
: carries Binary Content as a base32-encoded JSON string; e.g., "ZXW6==="date
: Carries a Date as a JSON integer; e.g., 1692859242displaystring
: Carries a Display String as a JSON string; e.g. "Füü"All tests should have a descriptive name. Tests should be as simple as possible - just what's required to test a specific piece of behavior. If you want to test interacting behaviors, create tests for each behavior as well as the interaction.
If a test file ends in -generated.json
, please modify generate.py
and re-generate the tests in your PR.
Please feel free to contribute!
RetroSearch is an open source project built by @garambo | Open a GitHub Issue
Search and Browse the WWW like it's 1997 | Search results from DuckDuckGo
HTML:
3.2
| Encoding:
UTF-8
| Version:
0.7.4