📖 3 min read (~ 500 words).

Curated cases

A parser’s own tests and fuzzers find small documents worth keeping. Most of them are not worth a change to a generator. Add them to a corpus as curated cases instead: each grammar’s build reads a file of them and adds every entry to the corpus it writes.

grammarfile
YAMLyaml/yamlgen/yamlbuild/curated.json
JSONjson/curated.json

Add a case

  1. Append an entry to the file. It is one JSON object with a cases array:

    {
      "cases": [
        {
          "name": "a tab opens a root flow sequence's continuation line",
          "src": "[a,\n\tb]\n",
          "wellFormed": true,
          "tags": ["separation/tab"],
          "means": ["a", "b"],
          "because": "A bare document is s-l+block-node(-1, block-in), so the flow content is at n=0 ...",
          "from": "go-yaml defect 223"
        }
      ]
    }
  2. Regenerate the compact corpus, and bump the build’s Generator:

    go test ./yaml/yamlgen/yamlbuild/ -run TestRegenerate -args -yamlbuild.write
    go test ./json/ -run TestRegenerate -args -jsoncorpus.write
  3. Run the tests. The build fails on an entry whose verdict the recognizer does not give.

The fields

fieldrequiredcontent
nameyesUnique in the file. The corpus names the case curated/ and this name.
srcsrc or srcBase64The document, as a JSON string. Use \t, \r and  for the usual bytes.
srcBase64src or srcBase64The document as base64, for bytes that are not UTF-8.
wellFormedyesThe verdict you derived from the grammar’s productions.
verdictAtnoparse (the default), compose or construct.
tagsnoThe implementation-defined properties the document exhibits. Each one must be in the grammar’s vocabulary.
meansnoWhat the document denotes under the corpus’s default reading, as a JSON value. YAML only, and only on a well-formed document.
becauseyesThe derivation: the productions and the section of the specification that give the verdict.
fromyesWhere the case came from: go-yaml defect 223, go-yaml FuzzScanner.

The build rejects an unknown field, a duplicate name and a tag outside the vocabulary. Encoding tags, such as encoding/bom, come from the bytes, so leave them out.

When the recognizer disagrees

The corpus takes wellFormed from the recognizer, as for every other case, and the build fails when your entry gives the other verdict. The message holds your derivation. Then either the derivation is wrong, or the grammar file or its transcription is, and you fix that one. The corpus never carries a verdict the grammar does not give.

In the corpus

A curated case has origin.mutation set to curated, origin.from set to the entry’s from, and a because field. The build adds the curated cases after the enumerated shapes and never drops one when it minimizes.

The consensus report lists every curated case on its Curated page, with each parser’s answer, and the case page shows the case’s derivation and where it came from.