@@ -4,89 +4,103 @@ describe('TypeCast with negative numbers', () => {
44 it ( 'should handle negative integer with CAST syntax' , async ( ) => {
55 const sql = `SELECT -1::integer` ;
66 const result = await expectParseDeparse ( sql ) ;
7- expect ( result ) . toMatchSnapshot ( ) ;
7+ // Negative numbers require CAST() syntax for precedence
8+ expect ( result ) . toBe ( `SELECT CAST(-1 AS integer)` ) ;
89 } ) ;
910
1011 it ( 'should handle parenthesized negative integer' , async ( ) => {
1112 const sql = `SELECT (-1)::integer` ;
1213 const result = await expectParseDeparse ( sql ) ;
13- expect ( result ) . toMatchSnapshot ( ) ;
14+ // Parenthesized negative numbers can use :: syntax
15+ expect ( result ) . toBe ( `SELECT (-1)::integer` ) ;
1416 } ) ;
1517
1618 it ( 'should handle negative float with CAST syntax' , async ( ) => {
1719 const sql = `SELECT -1.5::numeric` ;
1820 const result = await expectParseDeparse ( sql ) ;
19- expect ( result ) . toMatchSnapshot ( ) ;
21+ // Negative floats require CAST() syntax for precedence
22+ expect ( result ) . toBe ( `SELECT CAST(-1.5 AS numeric)` ) ;
2023 } ) ;
2124
2225 it ( 'should handle parenthesized negative float' , async ( ) => {
2326 const sql = `SELECT (-1.5)::numeric` ;
2427 const result = await expectParseDeparse ( sql ) ;
25- expect ( result ) . toMatchSnapshot ( ) ;
28+ // Parenthesized negative floats can use :: syntax
29+ expect ( result ) . toBe ( `SELECT (-1.5)::numeric` ) ;
2630 } ) ;
2731
2832 it ( 'should handle negative bigint' , async ( ) => {
2933 const sql = `SELECT -9223372036854775808::bigint` ;
3034 const result = await expectParseDeparse ( sql ) ;
31- expect ( result ) . toMatchSnapshot ( ) ;
35+ // Negative bigints require CAST() syntax for precedence
36+ expect ( result ) . toBe ( `SELECT CAST(-9223372036854775808 AS bigint)` ) ;
3237 } ) ;
3338} ) ;
3439
3540describe ( 'TypeCast with complex expressions' , ( ) => {
3641 it ( 'should handle arithmetic expression with CAST syntax' , async ( ) => {
3742 const sql = `SELECT (1 + 2)::integer` ;
3843 const result = await expectParseDeparse ( sql ) ;
39- expect ( result ) . toMatchSnapshot ( ) ;
44+ // Complex expressions require CAST() syntax
45+ expect ( result ) . toBe ( `SELECT CAST((1 + 2) AS integer)` ) ;
4046 } ) ;
4147
4248 it ( 'should handle subtraction expression' , async ( ) => {
4349 const sql = `SELECT (a - b)::integer FROM t` ;
4450 const result = await expectParseDeparse ( sql ) ;
45- expect ( result ) . toMatchSnapshot ( ) ;
51+ // Complex expressions require CAST() syntax
52+ expect ( result ) . toBe ( `SELECT CAST((a - b) AS integer) FROM t` ) ;
4653 } ) ;
4754
4855 it ( 'should handle CASE expression with CAST syntax' , async ( ) => {
4956 const sql = `SELECT (CASE WHEN a > 0 THEN 1 ELSE 2 END)::integer FROM t` ;
5057 const result = await expectParseDeparse ( sql ) ;
51- expect ( result ) . toMatchSnapshot ( ) ;
58+ // Complex expressions require CAST() syntax
59+ expect ( result ) . toBe ( `SELECT CAST((CASE WHEN (a > 0) THEN 1 ELSE 2 END) AS integer) FROM t` ) ;
5260 } ) ;
5361
5462 it ( 'should handle boolean expression' , async ( ) => {
5563 const sql = `SELECT (a IS NULL)::boolean FROM t` ;
5664 const result = await expectParseDeparse ( sql ) ;
57- expect ( result ) . toMatchSnapshot ( ) ;
65+ // Complex expressions require CAST() syntax
66+ expect ( result ) . toBe ( `SELECT CAST((a IS NULL) AS boolean) FROM t` ) ;
5867 } ) ;
5968
6069 it ( 'should handle comparison expression' , async ( ) => {
6170 const sql = `SELECT (a > b)::boolean FROM t` ;
6271 const result = await expectParseDeparse ( sql ) ;
63- expect ( result ) . toMatchSnapshot ( ) ;
72+ // Complex expressions require CAST() syntax
73+ expect ( result ) . toBe ( `SELECT CAST((a > b) AS boolean) FROM t` ) ;
6474 } ) ;
6575} ) ;
6676
6777describe ( 'TypeCast with function calls' , ( ) => {
6878 it ( 'should handle function call with :: syntax and parentheses' , async ( ) => {
6979 const sql = `SELECT substring('test', 1, 2)::text` ;
7080 const result = await expectParseDeparse ( sql ) ;
71- expect ( result ) . toMatchSnapshot ( ) ;
81+ // Function calls can use :: syntax with parentheses for precedence
82+ expect ( result ) . toBe ( `SELECT (substring('test', 1, 2))::text` ) ;
7283 } ) ;
7384
7485 it ( 'should handle qualified function call' , async ( ) => {
7586 const sql = `SELECT pg_catalog.substring('test', 1, 2)::text` ;
7687 const result = await expectParseDeparse ( sql ) ;
77- expect ( result ) . toMatchSnapshot ( ) ;
88+ // Qualified function calls can use :: syntax with parentheses
89+ expect ( result ) . toBe ( `SELECT (pg_catalog.substring('test', 1, 2))::text` ) ;
7890 } ) ;
7991
8092 it ( 'should handle aggregate function' , async ( ) => {
8193 const sql = `SELECT sum(x)::numeric FROM t` ;
8294 const result = await expectParseDeparse ( sql ) ;
83- expect ( result ) . toMatchSnapshot ( ) ;
95+ // Aggregate functions can use :: syntax with parentheses
96+ expect ( result ) . toBe ( `SELECT (sum(x))::numeric FROM t` ) ;
8497 } ) ;
8598
8699 it ( 'should handle nested function calls' , async ( ) => {
87100 const sql = `SELECT upper(lower('TEST'))::text` ;
88101 const result = await expectParseDeparse ( sql ) ;
89- expect ( result ) . toMatchSnapshot ( ) ;
102+ // Nested function calls can use :: syntax with parentheses
103+ expect ( result ) . toBe ( `SELECT (upper(lower('TEST')))::text` ) ;
90104 } ) ;
91105} ) ;
92106
@@ -107,7 +121,8 @@ describe('TypeCast with pg_catalog.bpchar', () => {
107121 it ( 'should handle bpchar with length modifier' , async ( ) => {
108122 const sql = `SELECT 'hello'::bpchar(10)` ;
109123 const result = await expectParseDeparse ( sql ) ;
110- expect ( result ) . toMatchSnapshot ( ) ;
124+ // bpchar with length modifier uses :: syntax
125+ expect ( result ) . toBe ( `SELECT 'hello'::bpchar(10)` ) ;
111126 } ) ;
112127} ) ;
113128
@@ -167,7 +182,8 @@ describe('TypeCast with simple constants', () => {
167182 it ( 'should handle NULL cast' , async ( ) => {
168183 const sql = `SELECT NULL::integer` ;
169184 const result = await expectParseDeparse ( sql ) ;
170- expect ( result ) . toMatchSnapshot ( ) ;
185+ // NULL can use :: syntax
186+ expect ( result ) . toBe ( `SELECT NULL::integer` ) ;
171187 } ) ;
172188} ) ;
173189
@@ -187,27 +203,30 @@ describe('TypeCast with column references', () => {
187203 it ( 'should handle fully qualified column reference' , async ( ) => {
188204 const sql = `SELECT schema.t.a::integer FROM schema.t` ;
189205 const result = await expectParseDeparse ( sql ) ;
190- expect ( result ) . toMatchSnapshot ( ) ;
206+ // Fully qualified column references can use :: syntax
207+ expect ( result ) . toBe ( `SELECT schema.t.a::integer FROM schema.t` ) ;
191208 } ) ;
192209} ) ;
193210
194211describe ( 'TypeCast with pg_catalog types' , ( ) => {
195212 it ( 'should handle pg_catalog.int4 with :: syntax' , async ( ) => {
196213 const sql = `SELECT 123::pg_catalog.int4` ;
197214 const result = await expectParseDeparse ( sql ) ;
198- // Should strip pg_catalog prefix and use :: syntax
199- expect ( result ) . toBe ( `SELECT 123::int4 ` ) ;
215+ // PostgreSQL normalizes int4 to int, and strips pg_catalog prefix
216+ expect ( result ) . toBe ( `SELECT 123::int ` ) ;
200217 } ) ;
201218
202219 it ( 'should handle pg_catalog.varchar' , async ( ) => {
203220 const sql = `SELECT 'hello'::pg_catalog.varchar` ;
204221 const result = await expectParseDeparse ( sql ) ;
222+ // Should strip pg_catalog prefix and use :: syntax
205223 expect ( result ) . toBe ( `SELECT 'hello'::varchar` ) ;
206224 } ) ;
207225
208226 it ( 'should handle pg_catalog.numeric' , async ( ) => {
209227 const sql = `SELECT 3.14::pg_catalog.numeric` ;
210228 const result = await expectParseDeparse ( sql ) ;
229+ // Should strip pg_catalog prefix and use :: syntax
211230 expect ( result ) . toBe ( `SELECT 3.14::numeric` ) ;
212231 } ) ;
213232} ) ;
@@ -216,26 +235,30 @@ describe('TypeCast with arrays', () => {
216235 it ( 'should handle array literal cast' , async ( ) => {
217236 const sql = `SELECT ARRAY[1, 2, 3]::integer[]` ;
218237 const result = await expectParseDeparse ( sql ) ;
219- expect ( result ) . toMatchSnapshot ( ) ;
238+ // Array literals require CAST() syntax
239+ expect ( result ) . toBe ( `SELECT CAST(ARRAY[1, 2, 3] AS int[])` ) ;
220240 } ) ;
221241
222242 it ( 'should handle array string literal cast' , async ( ) => {
223243 const sql = `SELECT '{1,2,3}'::integer[]` ;
224244 const result = await expectParseDeparse ( sql ) ;
225- expect ( result ) . toMatchSnapshot ( ) ;
245+ // Array string literals require CAST() syntax
246+ expect ( result ) . toBe ( `SELECT CAST('{1,2,3}' AS int[])` ) ;
226247 } ) ;
227248} ) ;
228249
229250describe ( 'TypeCast with ROW expressions' , ( ) => {
230251 it ( 'should handle ROW cast' , async ( ) => {
231252 const sql = `SELECT ROW(1, 2)::record` ;
232253 const result = await expectParseDeparse ( sql ) ;
233- expect ( result ) . toMatchSnapshot ( ) ;
254+ // ROW expressions require CAST() syntax
255+ expect ( result ) . toBe ( `SELECT CAST(ROW(1, 2) AS record)` ) ;
234256 } ) ;
235257
236258 it ( 'should handle implicit row cast' , async ( ) => {
237259 const sql = `SELECT (1, 2)::record` ;
238260 const result = await expectParseDeparse ( sql ) ;
239- expect ( result ) . toMatchSnapshot ( ) ;
261+ // Implicit ROW expressions require CAST() syntax
262+ expect ( result ) . toBe ( `SELECT CAST((1, 2) AS record)` ) ;
240263 } ) ;
241264} ) ;
0 commit comments