-
Notifications
You must be signed in to change notification settings - Fork 32
Expand file tree
/
Copy pathroundtrip.test.ts.snap
More file actions
161 lines (144 loc) Β· 3.84 KB
/
roundtrip.test.ts.snap
File metadata and controls
161 lines (144 loc) Β· 3.84 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
// Jest Snapshot v1, https://jestjs.io/docs/snapshot-testing
exports[`fixture round-trip tests exception-handler.sql deparsed output matches snapshot 1`] = `
"-- Function with comments in exception handler
CREATE FUNCTION safe_divide(
a numeric,
b numeric
) RETURNS numeric LANGUAGE plpgsql AS $$
DECLARE
v_result numeric;
BEGIN
-- Attempt the division
v_result := a / b;
RETURN v_result;
EXCEPTION
WHEN division_by_zero THEN
-- Log the error and return null
RAISE NOTICE 'Division by zero: % / %', a, b;
RETURN NULL;
END;
$$;"
`;
exports[`fixture round-trip tests loop-with-comments.sql deparsed output matches snapshot 1`] = `
"-- Function with comments inside loops
CREATE FUNCTION process_batch(
p_batch_size int
) RETURNS int LANGUAGE plpgsql AS $$
DECLARE
v_processed integer := 0;
r RECORD;
BEGIN
-- Process items in batches
FOR r IN SELECT id, data FROM pending_items LIMIT p_batch_size LOOP
-- Process each item
PERFORM process_item(r.id, r.data);
v_processed := v_processed + 1;
END LOOP;
-- Return the count of processed items
RETURN v_processed;
END;
$$;"
`;
exports[`fixture round-trip tests multi-function.sql deparsed output matches snapshot 1`] = `
"-- Multiple functions in one file
-- with outer SQL comments preserved
CREATE FUNCTION add_numbers(
a int,
b int
) RETURNS int LANGUAGE plpgsql AS $$
BEGIN
-- Simple addition
RETURN a + b;
END;
$$;
-- Second function with its own body comments
CREATE FUNCTION multiply_numbers(
a int,
b int
) RETURNS int LANGUAGE plpgsql AS $$
BEGIN
-- Multiply the inputs
RETURN a * b;
END;
$$;"
`;
exports[`fixture round-trip tests multiple-comments.sql deparsed output matches snapshot 1`] = `
"-- Function with multiple comment groups
CREATE FUNCTION process_order(
p_order_id int
) RETURNS void LANGUAGE plpgsql AS $$
DECLARE
v_total numeric;
v_status text;
BEGIN
-- First, calculate the order total
SELECT sum(amount) INTO v_total FROM order_items WHERE order_id = p_order_id;
-- Then update the order status
-- based on the total amount
IF v_total > 1000 THEN
v_status := 'premium';
ELSE
v_status := 'standard';
END IF;
-- Finally, record the result
UPDATE orders SET status = v_status, total = v_total WHERE id = p_order_id;
END;
$$;"
`;
exports[`fixture round-trip tests nested-blocks.sql deparsed output matches snapshot 1`] = `
"-- Function with nested blocks and comments
CREATE FUNCTION complex_logic(
p_id int
) RETURNS text LANGUAGE plpgsql AS $$
DECLARE
v_result text;
BEGIN
-- Initialize result
v_result := 'unknown';
-- Try the main logic
BEGIN
-- Fetch and process
SELECT status INTO v_result FROM items WHERE id = p_id;
EXCEPTION
WHEN no_data_found THEN
-- Handle missing item
v_result := 'not_found';
END;
RETURN v_result;
END;
$$;"
`;
exports[`fixture round-trip tests no-comments.sql deparsed output matches snapshot 1`] = `
"CREATE FUNCTION get_one() RETURNS int LANGUAGE plpgsql AS $$
BEGIN
RETURN 1;
END;
$$;"
`;
exports[`fixture round-trip tests simple-function.sql deparsed output matches snapshot 1`] = `
"-- Simple function with body comments
CREATE FUNCTION get_user_count() RETURNS int LANGUAGE plpgsql AS $$
DECLARE
v_count integer;
BEGIN
-- Count all active users
SELECT count(*) INTO v_count FROM users WHERE is_active = true;
RETURN v_count;
END;
$$;"
`;
exports[`fixture round-trip tests trigger-function.sql deparsed output matches snapshot 1`] = `
"-- Trigger function with comments in body
CREATE FUNCTION audit_trigger() RETURNS trigger LANGUAGE plpgsql AS $$
BEGIN
-- Set the updated_at timestamp
NEW.updated_at := now();
-- Record the change in audit log
IF TG_OP = 'UPDATE' THEN
INSERT INTO audit_log (table_name, operation, old_data, new_data)
VALUES (TG_TABLE_NAME, TG_OP, row_to_json(OLD), row_to_json(NEW));
END IF;
RETURN NEW;
END;
$$;"
`;