Documentation
¶
Overview ¶
Package testfile reads and writes the consolidated corpus format shared by the sqlc parser family: cases separated by `== <name>` lines, input and expectation separated by a `--` line, with a metadata.json sidecar per file tracking which cases are still todo.
Layout of a .test file:
== 001
SELECT 1
--
{"version":170007,...}
== 002
...
Because the inputs are SQL — where a line consisting of exactly `--` is a perfectly ordinary comment — content lines that would collide with the markers are escaped with a leading `|` (and lines starting with `|` are escaped too, making the encoding a bijection). Files are written only by cmd/regenerate; expectations are never edited by hand.
Index ¶
- Constants
- func IsError(expected string) bool
- func RenderError(e ErrorExpectation) string
- func RenderScanToken(start, end int32, token, keywordKind string) string
- func RenderSplit(stmts []string) string
- func RenderSummary(s SummaryExpectation) string
- func SplitTruncateLimit(input string) (limit int, sql string, err error)
- func WithTruncateLimit(limit int, sql string) string
- func Write(path string, cases []Case) error
- func WriteMetadata(testPath string, m Metadata) error
- type Case
- type ErrorExpectation
- type Metadata
- type SummaryExpectation
- type SummaryFilterColumn
- type SummaryFunction
- type SummaryTable
Constants ¶
const TruncateLimitPrefix = "-- truncate_limit: "
The summary_truncate suite carries the truncation limit as a leading comment line in the case input; both cmd/regenerate and the corpus harness strip it before calling Summary, so the SQL the oracle and oliphant see is byte-identical to the raw statement.
Variables ¶
This section is empty.
Functions ¶
func RenderError ¶
func RenderError(e ErrorExpectation) string
RenderError encodes an error expectation block:
ERROR: syntax error at or near "$" CURSORPOS: 8 FILENAME: scan.l FUNCNAME: scanner_yyerror
func RenderScanToken ¶
RenderScanToken encodes one token of a scan golden:
0 6 SELECT RESERVED_KEYWORD
Token and keyword kind are the protobuf enum value names; a full scan golden is these lines joined with "\n".
func RenderSplit ¶
RenderSplit encodes a statement-split golden as one statement per line, each Go-quoted (statements routinely contain newlines).
func RenderSummary ¶
func RenderSummary(s SummaryExpectation) string
RenderSummary encodes a SummaryResult golden, one entry per line. Repeated fields keep their protobuf order; aliases (a protobuf map, unordered by definition) are sorted by key. The empty summary renders as "".
TABLE: name="public.x" schema="public" table="x" ctx=DDL ALIAS: "a"="b" CTE: "cte" FUNCTION: name="pg_catalog.substr" function="substr" schema="pg_catalog" ctx=Call FILTER: schema="" table="t" column="c" STMT: SelectStmt TRUNCATED: "SELECT ..."
func SplitTruncateLimit ¶
SplitTruncateLimit strips the truncation-limit directive from a summary_truncate case input.
func WithTruncateLimit ¶
WithTruncateLimit prepends the truncation-limit directive to a statement.
func WriteMetadata ¶
WriteMetadata writes the sidecar (sorted, stable bytes).
Types ¶
type Case ¶
Case is one corpus entry: an input SQL string and its oracle-derived expectation (a protobuf-JSON tree, `ERROR: ...` block, token stream, …).
type ErrorExpectation ¶
type ErrorExpectation struct {
Message string
Cursorpos int
Filename string
Funcname string
Context string
}
ErrorExpectation is the golden form of a parser.Error. Lineno is excluded from conformance by design (upstream's own tests zero it: it is a C source line number).
func ParseError ¶
func ParseError(expected string) (ErrorExpectation, error)
ParseError decodes an error expectation block written by RenderError.
type Metadata ¶
type Metadata struct {
Todo []string `json:"todo"`
}
Metadata is the per-file sidecar. Todo lists the case names not yet passing; `go test ./parser -check-parse` removes newly passing entries, and a case absent from Todo that fails is a regression, never a new todo.
func ReadMetadata ¶
ReadMetadata loads the sidecar for a .test file; a missing sidecar means nothing is todo.
type SummaryExpectation ¶
type SummaryExpectation struct {
Tables []SummaryTable
Aliases map[string]string
CteNames []string
Functions []SummaryFunction
FilterColumns []SummaryFilterColumn
StatementTypes []string
TruncatedQuery string
}
type SummaryFilterColumn ¶
type SummaryFunction ¶
type SummaryTable ¶
SummaryTable / SummaryFunction / SummaryFilterColumn / SummaryExpectation mirror the SummaryResult protobuf field-for-field, with Context enums as their protobuf value names ("None", "Select", "DML", "DDL", "Call").