Files
2026-07-13 13:09:14 +08:00

64 lines
1.5 KiB
TypeScript
Vendored

import { strict as assert } from "node:assert";
import { test } from "vitest";
import { caretPositionInsideInsertedSqlSingleQuotes, insertedSqlSingleQuoteAtCaret } from "../../apps/desktop/src/lib/sql/sqlQuoteCaret.ts";
test("detects a newly typed SQL single quote", () => {
assert.equal(
insertedSqlSingleQuoteAtCaret({
previousValue: "name = ",
nextValue: "name = '",
selectionStart: 8,
}),
true,
);
assert.equal(
insertedSqlSingleQuoteAtCaret({
previousValue: "name = '",
nextValue: "name = ''",
selectionStart: 9,
}),
true,
);
});
test("moves the caret between SQL single quotes after typing the closing quote", () => {
assert.equal(
caretPositionInsideInsertedSqlSingleQuotes({
previousValue: "name = '",
nextValue: "name = ''",
selectionStart: 9,
}),
8,
);
});
test("moves the caret between pasted SQL single quotes", () => {
assert.equal(
caretPositionInsideInsertedSqlSingleQuotes({
previousValue: "name = ",
nextValue: "name = ''",
selectionStart: 9,
}),
8,
);
});
test("keeps the caret unchanged for ordinary quote edits", () => {
assert.equal(
caretPositionInsideInsertedSqlSingleQuotes({
previousValue: "name = ",
nextValue: "name = '",
selectionStart: 8,
}),
null,
);
assert.equal(
caretPositionInsideInsertedSqlSingleQuotes({
previousValue: "name = 'a",
nextValue: "name = 'a'",
selectionStart: 10,
}),
null,
);
});