|
8 | 8 | */
|
9 | 9 |
|
10 | 10 | import assert from 'node:assert';
|
11 |
| -import { autoCompare, normalizeDefinition, buildSortByKeys, getValueComplexity } from './compare-database.js'; |
| 11 | +import { autoCompare, buildSortByKeys, getValueComplexity } from './compare-database.js'; |
12 | 12 |
|
13 | 13 | // Test helper function
|
14 | 14 | const runTest = (testName, testFn) => {
|
@@ -201,104 +201,6 @@ runTest('autoCompare - buildSortByKeys integration for database data', () => {
|
201 | 201 | assert.strictEqual(comparison, 0); // Should be identical
|
202 | 202 | });
|
203 | 203 |
|
204 |
| -// Test cases for normalizeDefinition function |
205 |
| -runTest('normalizeDefinition - single line without leading/trailing spaces', () => { |
206 |
| - const input = 'CREATE FUNCTION test() RETURNS void'; |
207 |
| - const expected = 'CREATE FUNCTION test() RETURNS void'; |
208 |
| - const result = normalizeDefinition(input); |
209 |
| - |
210 |
| - assert.strictEqual(result, expected); |
211 |
| -}); |
212 |
| - |
213 |
| -runTest('normalizeDefinition - single line with leading/trailing spaces', () => { |
214 |
| - const input = ' CREATE FUNCTION test() RETURNS void '; |
215 |
| - const expected = 'CREATE FUNCTION test() RETURNS void'; |
216 |
| - const result = normalizeDefinition(input); |
217 |
| - |
218 |
| - assert.strictEqual(result, expected); |
219 |
| -}); |
220 |
| - |
221 |
| -runTest('normalizeDefinition - multi-line with various indentation', () => { |
222 |
| - const input = `CREATE OR REPLACE FUNCTION test_function() |
223 |
| - RETURNS trigger |
224 |
| - LANGUAGE plpgsql |
225 |
| - AS $function$ |
226 |
| - BEGIN |
227 |
| - IF NEW.status IS NULL THEN |
228 |
| - NEW.status := 'active'; |
229 |
| - END IF; |
230 |
| - RETURN NEW; |
231 |
| - END; |
232 |
| - $function$`; |
233 |
| - |
234 |
| - const expected = `CREATE OR REPLACE FUNCTION test_function() |
235 |
| -RETURNS trigger |
236 |
| -LANGUAGE plpgsql |
237 |
| -AS $function$ |
238 |
| -BEGIN |
239 |
| -IF NEW.status IS NULL THEN |
240 |
| -NEW.status := 'active'; |
241 |
| -END IF; |
242 |
| -RETURN NEW; |
243 |
| -END; |
244 |
| -$function$`; |
245 |
| - |
246 |
| - const result = normalizeDefinition(input); |
247 |
| - assert.strictEqual(result, expected); |
248 |
| -}); |
249 |
| - |
250 |
| -runTest('normalizeDefinition - trigger action statement', () => { |
251 |
| - const input = ` BEGIN |
252 |
| - UPDATE table1 SET updated_at = NOW() WHERE id = NEW.id; |
253 |
| - INSERT INTO audit_log (table_name, action) VALUES ('table1', 'UPDATE'); |
254 |
| - RETURN NEW; |
255 |
| - END `; |
256 |
| - |
257 |
| - const expected = `BEGIN |
258 |
| -UPDATE table1 SET updated_at = NOW() WHERE id = NEW.id; |
259 |
| -INSERT INTO audit_log (table_name, action) VALUES ('table1', 'UPDATE'); |
260 |
| -RETURN NEW; |
261 |
| -END`; |
262 |
| - |
263 |
| - const result = normalizeDefinition(input); |
264 |
| - assert.strictEqual(result, expected); |
265 |
| -}); |
266 |
| - |
267 |
| -runTest('normalizeDefinition - empty lines and mixed spacing', () => { |
268 |
| - const input = ` CREATE FUNCTION complex_func() |
269 |
| -
|
270 |
| - RETURNS TABLE(id integer, name text) |
271 |
| - AS $$ |
272 |
| - SELECT id, name |
273 |
| - FROM users |
274 |
| - WHERE active = true; |
275 |
| - $$`; |
276 |
| - |
277 |
| - const expected = `CREATE FUNCTION complex_func() |
278 |
| -
|
279 |
| -RETURNS TABLE(id integer, name text) |
280 |
| -AS $$ |
281 |
| -SELECT id, name |
282 |
| -FROM users |
283 |
| -WHERE active = true; |
284 |
| -$$`; |
285 |
| - |
286 |
| - const result = normalizeDefinition(input); |
287 |
| - assert.strictEqual(result, expected); |
288 |
| -}); |
289 |
| - |
290 |
| -runTest('normalizeDefinition - non-string input', () => { |
291 |
| - assert.strictEqual(normalizeDefinition(null), null); |
292 |
| - assert.strictEqual(normalizeDefinition(undefined), undefined); |
293 |
| - assert.strictEqual(normalizeDefinition(123), 123); |
294 |
| - assert.deepStrictEqual(normalizeDefinition({ key: 'value' }), { key: 'value' }); |
295 |
| -}); |
296 |
| - |
297 |
| -runTest('normalizeDefinition - empty string', () => { |
298 |
| - assert.strictEqual(normalizeDefinition(''), ''); |
299 |
| - assert.strictEqual(normalizeDefinition(' '), ''); |
300 |
| -}); |
301 |
| - |
302 | 204 | // Test cases for getValueComplexity function
|
303 | 205 | runTest('getValueComplexity - returns correct complexity scores', () => {
|
304 | 206 | assert.strictEqual(getValueComplexity(null), 0);
|
|
0 commit comments