Refactor parser tests to be file-driven - #37
Merged
Conversation
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
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Moves the
[]testCasetables out ofparser/parser_test.gointo file-driven testdata folders. 58 tables covering 3,987 cases migrated;parser_test.goshrinks from 9,965 to 4,551 lines.Layout
Each subdirectory of
parser/testdata/parser/is one test group, run asTestParserData/<name>:input.sql— source SQL cases separated by-- caselines, 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 expectedRestore()output (joined by;for multi-statement sources), or-- error: <message>matched verbatim against the parse error.The new runner in
parser/datadriven_test.goreplicates the previousRunTestbehavior — parse, restore, re-parse, and require deep-equal ASTs — and supports regenerating goldens with:go test ./parser -run TestParserData -updateA README in the testdata directory documents the format.
Notes
go/astextraction tool that only moved tables it could prove safe (literal strings, referenced solely by declaration plus a singleRunTestcall) and deleted code by exact line ranges; the tool is not committed.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.RunTestInRealAsFloatModehelpers were removed.Verification
go test ./... -count=1 -timeout 120spasses.-updateregenerates everyoutput.sqlbyte-for-byte identical to the table-derived goldens.🤖 Generated with Claude Code
https://claude.ai/code/session_01Cgv9F31AGeWoex2Q2KoPFo
Generated by Claude Code