|
1 | | -import { Parser } from '@pgsql/parser'; |
2 | | -import { deparse } from 'pgsql-deparser'; |
3 | | -import { PG13ToPG17Transformer } from '../src/transformer'; |
4 | | - |
5 | | -import generated from '../../../__fixtures__/generated/generated.json'; |
| 1 | +import { FullTransformFlowFixture } from '../test-utils/full-transform-flow'; |
6 | 2 | import { skipTests } from '../test-utils/skip-tests'; |
7 | 3 |
|
8 | | -describe('Full Transform Flow Tests', () => { |
9 | | - const testFiles = [ |
10 | | - 'original/upstream/plpgsql-86.sql', |
11 | | - 'original/upstream/plpgsql-202.sql', |
12 | | - 'original/upstream/plpgsql-203.sql', |
13 | | - 'original/upstream/plpgsql-204.sql', |
14 | | - 'original/upstream/plpgsql-205.sql', |
15 | | - 'original/upstream/plpgsql-206.sql', |
16 | | - 'original/upstream/plpgsql-207.sql', |
17 | | - 'original/upstream/plpgsql-208.sql', |
18 | | - 'original/upstream/plpgsql-209.sql', |
19 | | - 'original/upstream/plpgsql-210.sql', |
20 | | - 'original/upstream/plpgsql-211.sql', |
21 | | - 'original/upstream/plpgsql-212.sql', |
22 | | - 'original/upstream/plpgsql-213.sql', |
23 | | - 'original/upstream/plpgsql-214.sql', |
24 | | - 'original/upstream/plpgsql-215.sql', |
25 | | - 'original/upstream/plpgsql-216.sql', |
26 | | - 'original/upstream/plpgsql-217.sql', |
27 | | - 'original/upstream/plpgsql-218.sql', |
28 | | - 'original/upstream/plpgsql-219.sql', |
29 | | - 'original/upstream/plpgsql-220.sql', |
30 | | - 'original/upstream/plpgsql-221.sql', |
31 | | - 'original/upstream/plpgsql-222.sql', |
32 | | - 'original/upstream/plpgsql-223.sql', |
33 | | - "pretty/select_statements-1.sql", |
34 | | - "pretty/select_statements-2.sql", |
35 | | - "pretty/select_statements-3.sql", |
36 | | - "pretty/select_statements-4.sql", |
37 | | - "pretty/select_statements-5.sql", |
38 | | - "pretty/select_statements-6.sql", |
39 | | - "pretty/misc-1.sql", |
40 | | - "pretty/misc-2.sql", |
41 | | - "pretty/misc-3.sql", |
42 | | - "pretty/misc-4.sql", |
43 | | - // "pretty/misc-5.sql", |
44 | | - "pretty/misc-6.sql", |
45 | | - "pretty/misc-7.sql", |
46 | | - "pretty/misc-8.sql", |
47 | | - "pretty/misc-9.sql", |
48 | | - "pretty/misc-10.sql", |
49 | | - "pretty/misc-11.sql", |
50 | | - "pretty/misc-12.sql", |
51 | | - "pretty/misc-13.sql", |
52 | | - "pretty/create_table-1.sql", |
53 | | - "pretty/create_table-2.sql", |
54 | | - "pretty/create_table-3.sql", |
55 | | - "pretty/create_table-4.sql", |
56 | | - "pretty/create_table-5.sql", |
57 | | - "pretty/create_policy-1.sql", |
58 | | - "pretty/create_policy-2.sql", |
59 | | - "pretty/create_policy-3.sql", |
60 | | - "pretty/create_policy-4.sql", |
61 | | - "pretty/constraints-1.sql", |
62 | | - "pretty/constraints-2.sql", |
63 | | - "pretty/constraints-4.sql", |
64 | | - ].filter(filename => !skipTests.some(([from, to, f]) => filename === f)); |
65 | | - |
66 | | - console.log(testFiles); |
| 4 | +const testFiles = [ |
| 5 | + 'original/upstream/plpgsql-86.sql', |
| 6 | + 'original/upstream/plpgsql-202.sql', |
| 7 | + 'original/upstream/plpgsql-203.sql', |
| 8 | + 'original/upstream/plpgsql-204.sql', |
| 9 | + 'original/upstream/plpgsql-205.sql', |
| 10 | + 'original/upstream/plpgsql-206.sql', |
| 11 | + 'original/upstream/plpgsql-207.sql', |
| 12 | + 'original/upstream/plpgsql-208.sql', |
| 13 | + 'original/upstream/plpgsql-209.sql', |
| 14 | + 'original/upstream/plpgsql-210.sql', |
| 15 | + 'original/upstream/plpgsql-211.sql', |
| 16 | + 'original/upstream/plpgsql-212.sql', |
| 17 | + 'original/upstream/plpgsql-213.sql', |
| 18 | + 'original/upstream/plpgsql-214.sql', |
| 19 | + 'original/upstream/plpgsql-215.sql', |
| 20 | + 'original/upstream/plpgsql-216.sql', |
| 21 | + 'original/upstream/plpgsql-217.sql', |
| 22 | + 'original/upstream/plpgsql-218.sql', |
| 23 | + 'original/upstream/plpgsql-219.sql', |
| 24 | + 'original/upstream/plpgsql-220.sql', |
| 25 | + 'original/upstream/plpgsql-221.sql', |
| 26 | + 'original/upstream/plpgsql-222.sql', |
| 27 | + 'original/upstream/plpgsql-223.sql', |
| 28 | + "pretty/select_statements-1.sql", |
| 29 | + "pretty/select_statements-2.sql", |
| 30 | + "pretty/select_statements-3.sql", |
| 31 | + "pretty/select_statements-4.sql", |
| 32 | + "pretty/select_statements-5.sql", |
| 33 | + "pretty/select_statements-6.sql", |
| 34 | + "pretty/misc-1.sql", |
| 35 | + "pretty/misc-2.sql", |
| 36 | + "pretty/misc-3.sql", |
| 37 | + "pretty/misc-4.sql", |
| 38 | + // "pretty/misc-5.sql", |
| 39 | + "pretty/misc-6.sql", |
| 40 | + "pretty/misc-7.sql", |
| 41 | + "pretty/misc-8.sql", |
| 42 | + "pretty/misc-9.sql", |
| 43 | + "pretty/misc-10.sql", |
| 44 | + "pretty/misc-11.sql", |
| 45 | + "pretty/misc-12.sql", |
| 46 | + "pretty/misc-13.sql", |
| 47 | + "pretty/create_table-1.sql", |
| 48 | + "pretty/create_table-2.sql", |
| 49 | + "pretty/create_table-3.sql", |
| 50 | + "pretty/create_table-4.sql", |
| 51 | + "pretty/create_table-5.sql", |
| 52 | + "pretty/create_policy-1.sql", |
| 53 | + "pretty/create_policy-2.sql", |
| 54 | + "pretty/create_policy-3.sql", |
| 55 | + "pretty/create_policy-4.sql", |
| 56 | + "pretty/constraints-1.sql", |
| 57 | + "pretty/constraints-2.sql", |
| 58 | + "pretty/constraints-4.sql", |
| 59 | +].filter(filename => !skipTests.some(([from, to, f]) => filename === f)); |
67 | 60 |
|
68 | | - // Initialize parsers and transformer once for all tests |
69 | | - const pg13Parser = new Parser({ version: 13 }); |
70 | | - const pg17Parser = new Parser({ version: 17 }); |
71 | | - const transformer = new PG13ToPG17Transformer(); |
| 61 | +describe('Full Transform Flow Tests', () => { |
| 62 | + const fixture = new FullTransformFlowFixture(); |
72 | 63 |
|
73 | 64 | testFiles.forEach((filename) => { |
74 | 65 | it(`tests end-to-end flow for ${filename}`, async () => { |
75 | | - const sql = generated[filename as keyof typeof generated]; |
76 | | - if (!sql) { |
77 | | - throw new Error(`SQL for ${filename} not found`); |
78 | | - } |
79 | | - // Step 1: Parse with PG13 |
80 | | - const pg13Ast = await pg13Parser.parse(sql); |
81 | | - |
82 | | - // Step 2: Transform PG13 → PG17 |
83 | | - const pg17Ast = transformer.transform(pg13Ast as any); |
84 | | - |
85 | | - // Step 3: Deparse with PG17 deparser |
86 | | - const deparsedSql = await deparse(pg17Ast, { |
87 | | - pretty: true |
88 | | - }); |
89 | | - |
90 | | - // Step 4: Parse with PG13 |
91 | | - const pg13Ast2 = await pg13Parser.parse(deparsedSql); |
92 | | - // console.log({pg13Ast}); |
93 | | - // console.log({pg13Ast2}); |
94 | | - |
95 | | - // Step 5: Compare the two ASTs |
96 | | - // expect(cleanTree(pg13Ast2)).toEqual(cleanTree(pg13Ast)); |
97 | | - // Step 6: Parse with PG13 |
98 | | - const pg17Ast2 = await pg17Parser.parse(deparsedSql); |
99 | | - // console.log({pg17Ast2}); |
100 | | - |
101 | | - // Step 7: Compare the two ASTs |
102 | | - // expect(cleanTree(pg17Ast2)).toEqual(cleanTree(pg17Ast)); |
103 | | - |
104 | | - // Step 3: Deparse with PG17 deparser |
105 | | - const deparsedSql2 = await deparse(pg17Ast2 as any, { |
106 | | - pretty: true |
107 | | - }); |
108 | | - |
109 | | - // Step 9: Compare the two deparsed SQLs |
110 | | - expect(deparsedSql2).toEqual(deparsedSql); |
111 | | - |
112 | | - // console.log(`Result for ${filename}:`, deparsedSql); |
113 | | - |
114 | | - // Add assertions here if needed |
115 | | - expect(deparsedSql).toBeDefined(); |
116 | | - expect(typeof deparsedSql).toBe('string'); |
| 66 | + await fixture.runTransformFlowTest(filename); |
117 | 67 | }); |
118 | 68 | }); |
119 | 69 | }); |
0 commit comments