Mix.Statifier.Corpus.Json (Statifier v2.6.0)

Copy Markdown View Source

The corpus emitter's JSON encoding, fixed so that two emits of one tree are byte-identical and a regeneration diff is readable.

An object's keys are written in one fixed order - the order the schemas under conformance/schema/ list them in, for every object the corpus files hold - and a key outside that order after them, sorted. pretty/1 indents by two spaces with one array item per line; compact/1 writes no whitespace at all. corpus_file/2 combines the two: the file is pretty and each case is one compact line, so a changed case is a one-line diff. Strings are encoded by Elixir's JSON.

Summary

Functions

Encodes value with no whitespace.

Encodes a corpus file: the suite, then the cases, one compact case per line.

Encodes value with two-space indentation and a trailing newline.

Functions

compact(map)

@spec compact(value :: term()) :: String.t()

Encodes value with no whitespace.

Examples

iex> Mix.Statifier.Corpus.Json.compact(%{"suite" => "w3c", "id" => "w3c/test1", "steps" => []})
~s|{"id":"w3c/test1","suite":"w3c","steps":[]}|

corpus_file(suite, cases)

@spec corpus_file(suite :: String.t(), cases :: [map()]) :: String.t()

Encodes a corpus file: the suite, then the cases, one compact case per line.

pretty(value)

@spec pretty(value :: term()) :: String.t()

Encodes value with two-space indentation and a trailing newline.

Examples

iex> Mix.Statifier.Corpus.Json.pretty(%{"b" => [1], "a" => %{}})
~s|{\n  "a": {},\n  "b": [\n    1\n  ]\n}\n|