Read a corpus
A corpus is one file. This page reads it with jq and with Python, and turns a case into an expected outcome
without the Go packages. File format lists every field.
Get a corpus file
Each release tag holds the compact corpus of each suite, at a fixed path in the repository:
| suite | file |
|---|---|
| JSON | json/testdata/json-compact.jsonl.gz |
| YAML | yaml/corpus/testdata/yaml-compact.jsonl.gz |
Download a file at a release tag, so your tests read the same cases until you choose to move:
The releases page lists the tags. The header records
what built the file: gunzip -c yaml-compact.jsonl.gz | head -1 | jq '{tier, cases, generator, digest}'.
Note
Releases do not attach corpus files yet. The plan is for each release to attach the compact and extended corpora of both suites, with a checksum list. Until then, the tag is the way to pin a corpus.
To get the full JSON corpus, build it with Go:
Choose a tier
| tier | JSON cases | YAML cases | use it to | where to get it |
|---|---|---|---|---|
compact | 3921 | 28279 | run on every change: it keeps up to 16 cases per coverage signature | the repository, at a release tag |
extended | 11982 | 112578 | run before you release: five times the documents, with the same quota | planned as a release asset |
full | 144396 | built on demand | run on a schedule: it keeps every generated document | build it with Go, as above |
The header’s tier field says which one a file holds. Coverage explains what the
compact tier leaves out.
The layout
- The file is gzip-compressed JSON Lines.
- Line 1 is the header.
- Every following line is one case.
- A case’s
srcholds the test document in base64, because many documents are not valid UTF-8.
Read it with jq
The header:
Every tag the corpus uses, with its stage and whether the specification settles it:
How many cases carry each tag:
The documents carrying one tag, decoded:
@base64d writes text, so use it only on documents that are valid UTF-8. For the bytes of any case, pipe .src
to base64 -d.
Read it in another language
Any language with gzip, JSON and base64 can read a corpus. In Python:
The example checks the format first and the length last, as File format asks.
Check the vocabulary
Before you score anything, read header.vocabulary and decide your parser’s position on every tag in it that
is not settled. A tag you have no position on leaves every case carrying it unscored. A newer corpus can add a
tag, so run this check on every new file.
Turn a case into an expected outcome
You need three things about your parser:
- Its stage: how far it takes a document.
parsefor a parser that only checks syntax,composefor one that builds a tree and resolves aliases,constructfor one that builds native values. - Its stand on each open tag: it accepts such documents, refuses them on purpose, or does not guarantee either answer.
- Which settled rules it declines. A parser that never resolves aliases cannot check a rule about them, and declines it.
Then work through these steps in order. The first step that gives an answer decides.
- Leave out the tags past your stage. A tag whose
stagein the header comes later than your parser’s stage asks nothing of it. - Settled tags. Go through the case’s tags in the order it lists them. For a tag whose spec has
settled:- if you decline its rule, the case is not scored;
- if
settledisreject, expect a rejection; - if
settledisaccept, the construct is legal and the grammar still decides, so go on.
- Open tags. Go through the remaining tags in order:
- you refuse it: expect a rejection;
- you have no position, or you do not guarantee either answer: the case is not scored;
- you accept it, and the case is
opaque: the case is not scored, because nothing can say what the bytes denote without the decoder your parser uses; - you accept it: go on.
- The grammar refuses it. If
wellFormedisfalse, expect a rejection. A document that does not parse does not compose or construct either. - The verdict’s reach.
verdictAtis the last stage at which the grammar’s acceptance is evidence. If it is earlier than your parser’s stage, the case is not scored. An absentverdictAtmeansparse. - Otherwise, expect acceptance.
A case that is not scored tells nothing about your parser. Skip it, and do not count it as a pass. The Go
package stance runs the same steps in Table.Expect; see Score a parser in Go.
Info
The YAML Test Suite view, a jq filter that writes in.yaml, in.json and error for each case, comes with the
YAML pages.