Skip to content

Commit 1143ed2

Browse files
h3n4lclaude
andauthored
test(postgresql): add regression tests for fixed bugs (#41)
Add regression test suite to prevent reintroduction of bugs fixed in this PR. Tests added: 1. function_names_as_identifiers.sql - Tests that function names (exp, div, floor, mod, etc.) work as identifiers - Validates fix for removing builtin_function_name tokens 2. json_typecast.sql - Tests JSON/JSONB typecast syntax (::json, ::jsonb) - Validates fix for missing jsontype rule 3. complex_joins.sql - Tests complex multi-table JOINs with ORDER BY - General regression test for query patterns All tests are automatically included in 'make test' via recursive directory processing. 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-authored-by: Claude <[email protected]>
1 parent 734ef85 commit 1143ed2

File tree

4 files changed

+132
-0
lines changed

4 files changed

+132
-0
lines changed
Lines changed: 62 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,62 @@
1+
# Regression Tests
2+
3+
This directory contains regression tests for specific bugs that were fixed in the parser.
4+
5+
## Test Files
6+
7+
### `function_names_as_identifiers.sql`
8+
**Issue**: After removing `builtin_function_name` tokens, mathematical and string function names should be usable as regular identifiers.
9+
10+
**Tests**:
11+
- Using function names (exp, div, floor, mod, power, sqrt, log, reverse) as column names
12+
- Using function names as table names
13+
- SELECT statements with these identifiers
14+
15+
**Related PR**: #40 - Remove non-standard builtin_function_name tokens
16+
17+
### `json_typecast.sql`
18+
**Issue**: Missing `jsontype` rule caused `::json` and `::jsonb` typecasts to fail with "mismatched input ';' expecting '%'"
19+
20+
**Tests**:
21+
- Basic JSON/JSONB typecast syntax
22+
- JSON with unicode escape sequences
23+
- JSON with surrogate pairs
24+
- JSON type in CREATE TABLE
25+
- JSON typecast with -> operator
26+
27+
**Related PR**: #40 - Add jsontype rule for proper JSON type support
28+
29+
### `complex_joins.sql`
30+
**Issue**: Complex multi-table JOINs with multiple LEFT JOINs and ORDER BY clauses
31+
32+
**Tests**:
33+
- Multiple LEFT JOIN statements
34+
- Column aliases with AS keyword
35+
- WHERE clause filtering
36+
- ORDER BY with multiple columns and mixed ASC/DESC
37+
38+
**Related PR**: #40 - General regression test for complex query patterns
39+
40+
## Running Tests
41+
42+
These tests are automatically included when running the full test suite:
43+
44+
```bash
45+
cd postgresql
46+
make test
47+
```
48+
49+
To run only regression tests:
50+
51+
```bash
52+
go test -run "TestPostgreSQLParser/examples/regression" -v
53+
```
54+
55+
## Adding New Regression Tests
56+
57+
When fixing a parser bug:
58+
59+
1. Create a new `.sql` file in this directory
60+
2. Add a comment at the top describing the issue and fix
61+
3. Include minimal test cases that reproduce the bug
62+
4. The test will be automatically picked up by the test runner
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
-- Regression test: Complex multi-table JOINs with ORDER BY
2+
-- Tests parser handling of multiple LEFT JOINs, aliases, and ordering
3+
4+
SELECT
5+
se.id,
6+
se.name,
7+
se.description,
8+
st.type AS step_type,
9+
st.index AS step_index,
10+
sr.conditional,
11+
sr.index AS sr_index,
12+
script.script_content
13+
FROM test se
14+
LEFT JOIN test_step st ON se.id = st.sequence_id
15+
LEFT JOIN test_rel sr ON sr.step_id = sr.script_id
16+
LEFT JOIN msg_script script ON script.id = sr.script_id
17+
WHERE se.creator_id = 1
18+
ORDER BY se.id DESC, sr_index ASC;
Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
-- Regression test: Function names should be usable as identifiers
2+
-- Issue: After removing builtin_function_name tokens, mathematical function names
3+
-- should work as regular identifiers (table names, column names, etc.)
4+
5+
-- Mathematical functions as column names
6+
CREATE TABLE test_math (
7+
exp INT,
8+
div INT,
9+
floor INT,
10+
mod INT,
11+
power INT,
12+
sqrt INT,
13+
log INT
14+
);
15+
16+
-- String function REVERSE as column name
17+
CREATE TABLE test_string (
18+
reverse VARCHAR(100)
19+
);
20+
21+
-- Function names as table names
22+
CREATE TABLE exp (id INT);
23+
CREATE TABLE div (id INT);
24+
25+
-- Select from tables with function names
26+
SELECT exp, div, floor, mod FROM test_math;
27+
SELECT reverse FROM test_string;
28+
SELECT * FROM exp;
Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
-- Regression test: JSON and JSONB type casting
2+
-- Issue: Missing jsontype rule caused ::json and ::jsonb typecasts to fail
3+
-- Fix: Added jsontype rule to simpletypename and consttypename
4+
5+
-- Basic JSON typecast
6+
SELECT '{"a": 1}'::json;
7+
SELECT '{"b": 2}'::jsonb;
8+
9+
-- JSON with unicode escapes
10+
SELECT '"\u0000"'::json;
11+
SELECT '"\uaBcD"'::json;
12+
13+
-- JSON with surrogate pairs
14+
SELECT '{ "a": "\ud83d\ude04\ud83d\udc36" }'::json;
15+
16+
-- JSON in table definition
17+
CREATE TABLE json_test (
18+
data json,
19+
data_b jsonb
20+
);
21+
22+
-- JSON typecast in expressions
23+
SELECT '{"a": 1}'::json -> 'a';
24+
SELECT '{"b": 2}'::jsonb -> 'b';

0 commit comments

Comments
 (0)