roundtrip

package
v0.1.1 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Jul 31, 2026 License: MIT Imports: 3 Imported by: 0

Documentation

Overview

Package roundtrip states meyer's round-trip property in one place.

PLAN.md uses it in place of the parse-tree goldens SQLite cannot produce: rendering a tree back to SQL and re-parsing it must yield the same tree. Accept/reject conformance cannot see a dropped clause or an operator associated the wrong way; this can.

It lives in its own package because three callers need it — the corpus test, the fuzz target and cmd/difftest — and when each had its own copy they drifted: two of the three had quietly stopped checking that rendering is idempotent.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Result

type Result struct {
	Ok       bool
	Rendered string // the SQL the tree was rendered back to
	Reason   string // why it failed: one short phrase
	Want     string // the structural dump of the original tree
	Got      string // the structural dump of the re-parsed one
}

Result describes one round trip. Ok is false when the property failed, and the other fields say how.

func Check

func Check(stmts []ast.Stmt) Result

Check renders stmts back to SQL, re-parses it, and compares the two trees.

Equality is structural: byte spans and the Raw fields differ after a round trip by construction, and the renderer promises nothing about them, so dump.Structure leaves both out.

func CheckSQL

func CheckSQL(src string) Result

CheckSQL parses src and, if it parses, checks the property. An input the parser rejects is not a round-trip failure, and reports Ok.

func CheckWith added in v0.1.1

func CheckWith(opts parser.Options, stmts []ast.Stmt) Result

CheckWith is Check for a tree that was parsed with opts. The rendering is re-parsed with the same options, because a clause an option unlocked -- an UPDATE's LIMIT, say -- can only be read back with that option on.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL