import { describe, it, expect } from 'vitest';
import { splitSqlStatements, normalizeQuery, isSelectish } from './sql.js';
describe('sql helpers', () => {
    it('normalizeQuery collapses whitespace', () => {
        expect(normalizeQuery(' select   * \n  from   users  ')).toBe('select * from users');
    });
    it('isSelectish matches SELECT and WITH', () => {
        expect(isSelectish('select 1')).toBe(true);
        expect(isSelectish('  WITH x AS (select 1) select * from x')).toBe(true);
        expect(isSelectish('update users set name = :name')).toBe(false);
    });
    it('splitSqlStatements splits on semicolons not inside quotes/comments', () => {
        const sql = `
      -- comment with ;
      select ';' as a; 
      select "a; b" as b;
      /* block ; comment */
      select \`c;d\` as c;
      select 1 as n;
    `;
        const out = splitSqlStatements(sql);
        expect(out).toHaveLength(4);
        expect(out[0]).toMatch(/select ';' as a/i);
        expect(out[1]).toMatch(/select "a; b" as b/i);
        expect(out[2]).toMatch(/select `c;d` as c/i);
        expect(out[3]).toMatch(/select 1 as n/i);
    });
    it('splitSqlStatements ignores trailing semicolons/whitespace', () => {
        expect(splitSqlStatements('select 1;;; \n')).toEqual(['select 1']);
    });
});
