-
Notifications
You must be signed in to change notification settings - Fork 1
test(postgresql): add regression tests for fixed bugs #41
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,62 @@ | ||
| # Regression Tests | ||
|
|
||
| This directory contains regression tests for specific bugs that were fixed in the parser. | ||
|
|
||
| ## Test Files | ||
|
|
||
| ### `function_names_as_identifiers.sql` | ||
| **Issue**: After removing `builtin_function_name` tokens, mathematical and string function names should be usable as regular identifiers. | ||
|
|
||
| **Tests**: | ||
| - Using function names (exp, div, floor, mod, power, sqrt, log, reverse) as column names | ||
| - Using function names as table names | ||
| - SELECT statements with these identifiers | ||
|
|
||
| **Related PR**: #40 - Remove non-standard builtin_function_name tokens | ||
|
|
||
| ### `json_typecast.sql` | ||
| **Issue**: Missing `jsontype` rule caused `::json` and `::jsonb` typecasts to fail with "mismatched input ';' expecting '%'" | ||
|
|
||
| **Tests**: | ||
| - Basic JSON/JSONB typecast syntax | ||
| - JSON with unicode escape sequences | ||
| - JSON with surrogate pairs | ||
| - JSON type in CREATE TABLE | ||
| - JSON typecast with -> operator | ||
|
|
||
| **Related PR**: #40 - Add jsontype rule for proper JSON type support | ||
|
|
||
| ### `complex_joins.sql` | ||
| **Issue**: Complex multi-table JOINs with multiple LEFT JOINs and ORDER BY clauses | ||
|
|
||
| **Tests**: | ||
| - Multiple LEFT JOIN statements | ||
| - Column aliases with AS keyword | ||
| - WHERE clause filtering | ||
| - ORDER BY with multiple columns and mixed ASC/DESC | ||
|
|
||
| **Related PR**: #40 - General regression test for complex query patterns | ||
|
|
||
| ## Running Tests | ||
|
|
||
| These tests are automatically included when running the full test suite: | ||
|
|
||
| ```bash | ||
| cd postgresql | ||
| make test | ||
| ``` | ||
|
|
||
| To run only regression tests: | ||
|
|
||
| ```bash | ||
| go test -run "TestPostgreSQLParser/examples/regression" -v | ||
| ``` | ||
|
|
||
| ## Adding New Regression Tests | ||
|
|
||
| When fixing a parser bug: | ||
|
|
||
| 1. Create a new `.sql` file in this directory | ||
| 2. Add a comment at the top describing the issue and fix | ||
| 3. Include minimal test cases that reproduce the bug | ||
| 4. The test will be automatically picked up by the test runner |
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,18 @@ | ||
| -- Regression test: Complex multi-table JOINs with ORDER BY | ||
| -- Tests parser handling of multiple LEFT JOINs, aliases, and ordering | ||
|
|
||
| SELECT | ||
| se.id, | ||
| se.name, | ||
| se.description, | ||
| st.type AS step_type, | ||
| st.index AS step_index, | ||
| sr.conditional, | ||
| sr.index AS sr_index, | ||
| script.script_content | ||
| FROM test se | ||
| LEFT JOIN test_step st ON se.id = st.sequence_id | ||
| LEFT JOIN test_rel sr ON sr.step_id = sr.script_id | ||
| LEFT JOIN msg_script script ON script.id = sr.script_id | ||
| WHERE se.creator_id = 1 | ||
| ORDER BY se.id DESC, sr_index ASC; | ||
28 changes: 28 additions & 0 deletions
28
postgresql/examples/regression/function_names_as_identifiers.sql
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,28 @@ | ||
| -- Regression test: Function names should be usable as identifiers | ||
| -- Issue: After removing builtin_function_name tokens, mathematical function names | ||
| -- should work as regular identifiers (table names, column names, etc.) | ||
|
|
||
| -- Mathematical functions as column names | ||
| CREATE TABLE test_math ( | ||
| exp INT, | ||
| div INT, | ||
| floor INT, | ||
| mod INT, | ||
| power INT, | ||
| sqrt INT, | ||
| log INT | ||
| ); | ||
|
|
||
| -- String function REVERSE as column name | ||
| CREATE TABLE test_string ( | ||
| reverse VARCHAR(100) | ||
| ); | ||
|
|
||
| -- Function names as table names | ||
| CREATE TABLE exp (id INT); | ||
| CREATE TABLE div (id INT); | ||
|
|
||
| -- Select from tables with function names | ||
| SELECT exp, div, floor, mod FROM test_math; | ||
| SELECT reverse FROM test_string; | ||
| SELECT * FROM exp; |
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,24 @@ | ||
| -- Regression test: JSON and JSONB type casting | ||
| -- Issue: Missing jsontype rule caused ::json and ::jsonb typecasts to fail | ||
| -- Fix: Added jsontype rule to simpletypename and consttypename | ||
|
|
||
| -- Basic JSON typecast | ||
| SELECT '{"a": 1}'::json; | ||
| SELECT '{"b": 2}'::jsonb; | ||
|
|
||
| -- JSON with unicode escapes | ||
| SELECT '"\u0000"'::json; | ||
| SELECT '"\uaBcD"'::json; | ||
|
|
||
| -- JSON with surrogate pairs | ||
| SELECT '{ "a": "\ud83d\ude04\ud83d\udc36" }'::json; | ||
|
|
||
| -- JSON in table definition | ||
| CREATE TABLE json_test ( | ||
| data json, | ||
| data_b jsonb | ||
| ); | ||
|
|
||
| -- JSON typecast in expressions | ||
| SELECT '{"a": 1}'::json -> 'a'; | ||
| SELECT '{"b": 2}'::jsonb -> 'b'; |
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The JOIN condition appears incorrect:
sr.step_id = sr.script_idcompares two columns from the same table alias. This likely should best.id = sr.step_idto properly join test_step with test_rel.