Skip to content

Refactor parser tests to be file-driven - #37

Merged
kyleconroy merged 1 commit into
mainfrom
claude/parser-test-refactor-plan-n3rncy
Aug 18, 2026
Merged

Refactor parser tests to be file-driven#37
kyleconroy merged 1 commit into
mainfrom
claude/parser-test-refactor-plan-n3rncy

Conversation

@kyleconroy

Copy link
Copy Markdown
Contributor

Summary

Moves the []testCase tables out of parser/parser_test.go into file-driven testdata folders. 58 tables covering 3,987 cases migrated; parser_test.go shrinks from 9,965 to 4,551 lines.

Layout

Each subdirectory of parser/testdata/parser/ is one test group, run as TestParserData/<name>:

  • input.sql — source SQL cases separated by -- case lines, with an optional -- flags: header (window_func, mariadb, real_as_float) configuring the parser for the group.
  • output.sql — one segment per case: either the expected Restore() output (joined by ; for multi-statement sources), or -- error: <message> matched verbatim against the parse error.

The new runner in parser/datadriven_test.go replicates the previous RunTest behavior — parse, restore, re-parse, and require deep-equal ASTs — and supports regenerating goldens with:

go test ./parser -run TestParserData -update

A README in the testdata directory documents the format.

Notes

  • Error cases previously asserted only that parsing fails; they now match the exact error message, consistent with the error-message compatibility contract.
  • The migration was done with a throwaway go/ast extraction tool that only moved tables it could prove safe (literal strings, referenced solely by declaration plus a single RunTest call) and deleted code by exact line ranges; the tool is not committed.
  • Deliberately left in Go: TestIdentifier (one case embeds a NUL byte, another raw invalid UTF-8), TestWindowFunctionIdentifier (table built at runtime from the exported token map), and all tests with custom AST assertions — those kept their custom code while their tables moved to files.
  • The now-unused RunTestInRealAsFloatMode helpers were removed.

Verification

  • go test ./... -count=1 -timeout 120s passes.
  • Per-folder case counts match the extracted tables exactly (3,987).
  • -update regenerates every output.sql byte-for-byte identical to the table-derived goldens.
  • Negative check: corrupting a golden makes the runner fail with a restore mismatch.

🤖 Generated with Claude Code

https://claude.ai/code/session_01Cgv9F31AGeWoex2Q2KoPFo


Generated by Claude Code

Move the []testCase tables from parser_test.go into per-group testdata
folders under parser/testdata/parser/. Each folder holds an input.sql
(source cases separated by '-- case' lines, with an optional '-- flags:'
header for window_func/mariadb/real_as_float) and an output.sql golden
(expected Restore() output per case, or '-- error: <message>' with the
exact parse error).

A new TestParserData in datadriven_test.go walks the folders, replicates
the parse -> restore -> re-parse round-trip previously done by RunTest,
and matches error messages verbatim; goldens can be regenerated with
'go test ./parser -run TestParserData -update'.

58 tables (3,987 cases) migrated; error cases now assert the exact
message instead of just failure. Tests with runtime-built tables or
non-UTF-8 sources (TestIdentifier, TestWindowFunctionIdentifier) and
AST-inspecting tests stay in Go. The now-unused RealAsFloat RunTest
helpers are removed; parser_test.go shrinks from 9,965 to 4,551 lines.

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01Cgv9F31AGeWoex2Q2KoPFo
@kyleconroy
kyleconroy merged commit 393e696 into main Aug 18, 2026
1 check passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants