Docs menu

Conformance

View as Markdown

conformance/cases.json in the package holds about 800 templates. pnpm conformance runs each through Go's text/template and records the output, or the error, in golden.json. The test suite then runs each case through obol and compares:

  • Output must match byte for byte.
  • A parse error must match Go's message exactly.
  • An execution error must fail at the same line, column and node.

The cases keep clear of the differences, which have tests of their own.

Add a case #

The file holds one shared data object and a list of cases. Each case needs a template and may set the rest:

{
  "template": "{{range $i, $u := .users}}{{$i}}:{{$u.name | upper}} {{end}}",
  "data": { "users": [{ "name": "Ada" }, { "name": "Bob" }] },
  "options": ["missingkey=error"],
  "delims": ["{{", "}}"],
  "templates": { "row": "<li>{{.}}</li>" }
}
Key Sets
template the body of the template under test
data the data, in place of the shared object
options options passed to option
delims the delimiters
templates other templates in the set, by name

Both sides add the same functions: upper, add, repeat, list and fail, which throws its argument.

Then record Go's answer and run the tests:

pnpm conformance
pnpm test

Recording needs Go 1.26 or later. The tests need only Node, and one of them fails when golden.json lags behind cases.json.