fix(editor): preserve current SQL execution boundaries
This commit is contained in:
13 files changed
+232
-44
No files matched your search
@@ -2,15 +2,42 @@ import { describe, expect, it } from "vitest";
|
||||
import { currentStatementFrameRangeTo, estimateInlineHintVisualColumns, isWideSqlChar, shouldRebuildCurrentStatementFrame, visualSqlColumns, visualSqlColumnsWithInlineHints } from "@/lib/sql/currentStatementFrame";
|
||||
import type { SqlTextRange } from "@/lib/sql/sqlStatementRanges";
|
||||
|
||||
function frameDocument(sql: string) {
|
||||
return {
|
||||
length: sql.length,
|
||||
sliceString: (from: number, to: number) => sql.slice(from, to),
|
||||
};
|
||||
}
|
||||
|
||||
describe("currentStatementFrameRangeTo", () => {
|
||||
it("includes a directly adjacent trailing semicolon in frame width calculations", () => {
|
||||
const sql = "SELECT 1;";
|
||||
const range: SqlTextRange = { from: 0, to: "SELECT 1".length, sql: "SELECT 1" };
|
||||
expect(currentStatementFrameRangeTo(";", range)).toBe(range.to + 1);
|
||||
expect(currentStatementFrameRangeTo(frameDocument(sql), range)).toBe(sql.length);
|
||||
});
|
||||
|
||||
it("does not extend the frame when the next character is not a semicolon", () => {
|
||||
it("includes a trailing semicolon on its own line", () => {
|
||||
const sql = "SELECT 1\n;\n\nSELECT 2;";
|
||||
const range: SqlTextRange = { from: 0, to: "SELECT 1".length, sql: "SELECT 1" };
|
||||
expect(currentStatementFrameRangeTo("\n", range)).toBe(range.to);
|
||||
expect(currentStatementFrameRangeTo(frameDocument(sql), range)).toBe(sql.indexOf(";") + 1);
|
||||
});
|
||||
|
||||
it("does not extend the frame across a comment before a later semicolon", () => {
|
||||
const sql = "SELECT 1\n-- comment\n;";
|
||||
const range: SqlTextRange = { from: 0, to: "SELECT 1".length, sql: "SELECT 1" };
|
||||
expect(currentStatementFrameRangeTo(frameDocument(sql), range)).toBe(range.to);
|
||||
});
|
||||
|
||||
it("does not extend the frame across a blank line before a later semicolon", () => {
|
||||
const sql = "SELECT 1\n\n;";
|
||||
const range: SqlTextRange = { from: 0, to: "SELECT 1".length, sql: "SELECT 1" };
|
||||
expect(currentStatementFrameRangeTo(frameDocument(sql), range)).toBe(range.to);
|
||||
});
|
||||
|
||||
it("does not extend the frame when the next non-whitespace character is not a semicolon", () => {
|
||||
const sql = "SELECT 1\n\nSELECT 2";
|
||||
const range: SqlTextRange = { from: 0, to: "SELECT 1".length, sql: "SELECT 1" };
|
||||
expect(currentStatementFrameRangeTo(frameDocument(sql), range)).toBe(range.to);
|
||||
});
|
||||
});
|
||||
|
||||
|
||||
Reference in new issue
Block a user