23 lines
644 B
JavaScript
23 lines
644 B
JavaScript
import assert from 'node:assert/strict';
|
|
import test from 'node:test';
|
|
|
|
import { splitSqlStatements } from './db.mjs';
|
|
|
|
test('splitSqlStatements ignores semicolons in comments and strings', () => {
|
|
const statements = splitSqlStatements(`
|
|
-- comment with a semicolon; should not split
|
|
CREATE TABLE one (
|
|
label VARCHAR(64) DEFAULT 'semi;colon'
|
|
);
|
|
/* block; comment */
|
|
CREATE TABLE two (
|
|
id BIGINT PRIMARY KEY,
|
|
name VARCHAR(64) DEFAULT "two;name"
|
|
);
|
|
`);
|
|
|
|
assert.equal(statements.length, 2);
|
|
assert.match(statements[0], /^CREATE TABLE one/);
|
|
assert.match(statements[1], /^CREATE TABLE two/);
|
|
});
|