Documentation
¶
Overview ¶
Package harness verifies the port against the Python reference.
testdata/expected holds one JSON file per statement: the SQL, its dialect, and the tree the reference produced (serde.dump format). The port parses the same SQL, dumps its own tree the same way, and the two are diffed. A mismatch is a failing test; the reference is the oracle.
Coverage is reported as a number per dialect -- what fraction of the reference corpus the port reproduces identically -- and written to testdata/coverage.json so the README can show it and CI can refuse a regression. A statement the port cannot parse counts against coverage; it never counts as a silent divergence.
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func Diff ¶
Diff returns a human-readable description of the first disagreement between two normalised dumps, or "" if they match.
func Load ¶
func Load(dir string) (*Index, []Expectation, error)
Load reads every expectation under dir.
Types ¶
type Coverage ¶
type Coverage struct {
Reference string `json:"reference"`
Total int `json:"total"`
Matched int `json:"matched"`
ByDialect map[string]DialectCoverage `json:"by_dialect"`
}
Coverage is the per-dialect tally a run produces.
type DialectCoverage ¶
type DialectCoverage struct {
Total int `json:"total"`
Matched int `json:"matched"`
Unparsed int `json:"unparsed"` // the port refused or errored
Mismatched int `json:"mismatched"` // parsed, but a different tree
}
DialectCoverage counts one dialect's outcomes.
func (DialectCoverage) Percent ¶
func (c DialectCoverage) Percent() float64
Percent is matched/total, to one decimal.
type Expectation ¶
type Expectation struct {
Key string `json:"-"`
Dialect string `json:"dialect"`
SQL string `json:"sql"`
// Rendered is what the reference writes this statement back out as. The
// guard rewrites a tree and hands SQL to the engine, so the port needs a
// generator, and it is held to this string rather than to "something that
// parses".
Rendered string `json:"rendered"`
Tokens []RefToken `json:"tokens"`
Tree []map[string]any `json:"tree"`
}
Expectation is one reference statement, its token stream and its tree.
type Index ¶
type Index struct {
Reference string `json:"reference"`
Count int `json:"count"`
Statements []struct {
Key string `json:"key"`
Dialect string `json:"dialect"`
SQL string `json:"sql"`
} `json:"statements"`
}
Index lists every expectation and the reference commit they came from.
type RefToken ¶
type RefToken struct {
Type string `json:"t"`
Text string `json:"x"`
Line int `json:"l"`
Col int `json:"c"`
Start int `json:"s"`
End int `json:"e"`
Comments []string `json:"o,omitempty"`
}
RefToken is one token as the reference produced it. The short field names are the oracle's, kept short because there are a few hundred thousand of them.