Skip to content

Commit 9848e67

Browse files
committed
feat(deparser): add join fixtures for pretty printing tests
Add SQL fixtures for testing JOIN parsing and deparsing: - Simple inner join - Left outer join - Multiple joins - Joined tables with specific columns - Raw ast passthrough These fixtures help verify that JOIN statements are parsed and deparsed correctly.
1 parent 132971c commit 9848e67

4 files changed

Lines changed: 82 additions & 0 deletions

File tree

__fixtures__/generated/generated.json

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -96,6 +96,11 @@
9696
"pretty/misc-15.sql": "ALTER DEFAULT PRIVILEGES IN SCHEMA dashboard_jobs \n GRANT EXECUTE ON FUNCTIONS TO administrator",
9797
"pretty/misc-16.sql": "GRANT EXECUTE ON FUNCTION dashboard_private.uuid_generate_seeded_uuid TO PUBLIC",
9898
"pretty/misc-17.sql": "SELECT CAST(t.date AT TIME ZONE $$America/New_York$$ AS text)::date FROM tbl t",
99+
"pretty/joins-1.sql": "SELECT *\nFROM public.posts AS t0 INNER JOIN public.users ON t0.author_id = users.id",
100+
"pretty/joins-2.sql": "SELECT *\nFROM public.posts AS t0 LEFT OUTER JOIN public.comments ON t0.id = comments.post_id",
101+
"pretty/joins-3.sql": "SELECT *\nFROM public.posts AS t0 INNER JOIN public.users ON t0.author_id = users.id LEFT OUTER JOIN public.categories ON t0.category_id = categories.id",
102+
"pretty/joins-4.sql": "SELECT\n t0.id,\n t0.title,\n users.name\nFROM public.posts AS t0 INNER JOIN public.users ON t0.author_id = users.id",
103+
"pretty/joins-5.sql": "SELECT id\nFROM public.users",
99104
"pretty/formatting-1.sql": "EXPLAIN (COSTS OFF) SELECT * FROM onek2 WHERE unique2 = 11 AND stringu1 = 'ATAAAA'",
100105
"pretty/formatting-2.sql": "EXPLAIN SELECT * FROM onek2 WHERE unique2 = 11 AND stringu1 = 'ATAAAA'",
101106
"pretty/formatting-3.sql": "INSERT INTO objects.object (name, val, active, hash)\nVALUES ('name', 'val', 't'::boolean, 'abcdefg'),\n ('name', 'val', 't'::boolean, 'abcdefg'),\n ('name', 'val', 't'::boolean, 'abcdefg')",
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
-- 1. Simple inner join
2+
SELECT *
3+
FROM public.posts AS t0 INNER JOIN public.users ON t0.author_id = users.id;
4+
5+
-- 2. Left outer join
6+
SELECT *
7+
FROM public.posts AS t0 LEFT OUTER JOIN public.comments ON t0.id = comments.post_id;
8+
9+
-- 3. Multiple joins
10+
SELECT *
11+
FROM public.posts AS t0 INNER JOIN public.users ON t0.author_id = users.id LEFT OUTER JOIN public.categories ON t0.category_id = categories.id;
12+
13+
-- 4. Joined tables with specific columns
14+
SELECT
15+
t0.id,
16+
t0.title,
17+
users.name
18+
FROM public.posts AS t0 INNER JOIN public.users ON t0.author_id = users.id;
19+
20+
-- 5. Raw ast passthrough
21+
SELECT id
22+
FROM public.users;
Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
// Jest Snapshot v1, https://jestjs.io/docs/snapshot-testing
2+
3+
exports[`non-pretty: pretty/joins-1.sql 1`] = `"SELECT * FROM public.posts AS t0 JOIN public.users ON t0.author_id = users.id"`;
4+
5+
exports[`non-pretty: pretty/joins-2.sql 1`] = `"SELECT * FROM public.posts AS t0 LEFT JOIN public.comments ON t0.id = comments.post_id"`;
6+
7+
exports[`non-pretty: pretty/joins-3.sql 1`] = `"SELECT * FROM public.posts AS t0 JOIN public.users ON t0.author_id = users.id LEFT JOIN public.categories ON t0.category_id = categories.id"`;
8+
9+
exports[`non-pretty: pretty/joins-4.sql 1`] = `"SELECT t0.id, t0.title, users.name FROM public.posts AS t0 JOIN public.users ON t0.author_id = users.id"`;
10+
11+
exports[`non-pretty: pretty/joins-5.sql 1`] = `"SELECT id FROM public.users"`;
12+
13+
exports[`pretty: pretty/joins-1.sql 1`] = `
14+
"SELECT *
15+
FROM public.posts AS t0
16+
JOIN public.users ON t0.author_id = users.id"
17+
`;
18+
19+
exports[`pretty: pretty/joins-2.sql 1`] = `
20+
"SELECT *
21+
FROM public.posts AS t0
22+
LEFT JOIN public.comments ON t0.id = comments.post_id"
23+
`;
24+
25+
exports[`pretty: pretty/joins-3.sql 1`] = `
26+
"SELECT *
27+
FROM public.posts AS t0
28+
JOIN public.users ON t0.author_id = users.id
29+
LEFT JOIN public.categories ON t0.category_id = categories.id"
30+
`;
31+
32+
exports[`pretty: pretty/joins-4.sql 1`] = `
33+
"SELECT
34+
t0.id,
35+
t0.title,
36+
users.name
37+
FROM public.posts AS t0
38+
JOIN public.users ON t0.author_id = users.id"
39+
`;
40+
41+
exports[`pretty: pretty/joins-5.sql 1`] = `
42+
"SELECT id
43+
FROM public.users"
44+
`;
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
import { PrettyTest } from '../../test-utils/PrettyTest';
2+
3+
const prettyTest = new PrettyTest([
4+
'pretty/joins-1.sql',
5+
'pretty/joins-2.sql',
6+
'pretty/joins-3.sql',
7+
'pretty/joins-4.sql',
8+
'pretty/joins-5.sql',
9+
]);
10+
11+
prettyTest.generateTests();

0 commit comments

Comments
 (0)