diff --git a/postgresql/examples/regression/README.md b/postgresql/examples/regression/README.md new file mode 100644 index 0000000..ed51d27 --- /dev/null +++ b/postgresql/examples/regression/README.md @@ -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 diff --git a/postgresql/examples/regression/complex_joins.sql b/postgresql/examples/regression/complex_joins.sql new file mode 100644 index 0000000..74869c6 --- /dev/null +++ b/postgresql/examples/regression/complex_joins.sql @@ -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; diff --git a/postgresql/examples/regression/function_names_as_identifiers.sql b/postgresql/examples/regression/function_names_as_identifiers.sql new file mode 100644 index 0000000..eb7da3b --- /dev/null +++ b/postgresql/examples/regression/function_names_as_identifiers.sql @@ -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; diff --git a/postgresql/examples/regression/json_typecast.sql b/postgresql/examples/regression/json_typecast.sql new file mode 100644 index 0000000..6fc2d29 --- /dev/null +++ b/postgresql/examples/regression/json_typecast.sql @@ -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';