fix(editor): preserve current SQL execution boundaries
This commit is contained in:
13 files changed
+232
-44
No files matched your search
@@ -1,5 +1,9 @@
|
||||
import { describe, expect, it } from "vitest";
|
||||
import { resolveExecutableSql } from "@/lib/sql/sqlExecutionTarget";
|
||||
import { executionCandidateForMode, resolveExecutableSql, type SqlExecutionCandidate } from "@/lib/sql/sqlExecutionTarget";
|
||||
|
||||
function candidate(kind: SqlExecutionCandidate["kind"], supportedKinds: SqlExecutionCandidate["supportedKinds"]): SqlExecutionCandidate {
|
||||
return { kind, supportedKinds, label: kind, sql: "SELECT 1", from: 0, to: 8 };
|
||||
}
|
||||
|
||||
describe("resolveExecutableSql", () => {
|
||||
it("uses selected SQL before cursor-mode resolution", () => {
|
||||
@@ -10,3 +14,27 @@ describe("resolveExecutableSql", () => {
|
||||
expect(resolveExecutableSql(sql, selectedSql, { mode: "current", cursorPos: cursorAfterFirstSemicolon })).toBe("select 2;");
|
||||
});
|
||||
});
|
||||
|
||||
describe("executionCandidateForMode", () => {
|
||||
it("does not fall back to all SQL when current mode has no cursor statement", () => {
|
||||
const all = candidate("all", ["all"]);
|
||||
|
||||
expect(executionCandidateForMode([all], "current")).toBeNull();
|
||||
expect(executionCandidateForMode([all], "all")).toBe(all);
|
||||
});
|
||||
|
||||
it("uses the deduplicated candidate when one statement is both current and all", () => {
|
||||
const currentAndAll = candidate("all", ["cursor", "all"]);
|
||||
|
||||
expect(executionCandidateForMode([currentAndAll], "current")).toBe(currentAndAll);
|
||||
expect(executionCandidateForMode([currentAndAll], "all")).toBe(currentAndAll);
|
||||
});
|
||||
|
||||
it("selects the exact target when current and all candidates are distinct", () => {
|
||||
const current = candidate("cursor", ["cursor"]);
|
||||
const all = candidate("all", ["all"]);
|
||||
|
||||
expect(executionCandidateForMode([current, all], "current")).toBe(current);
|
||||
expect(executionCandidateForMode([current, all], "all")).toBe(all);
|
||||
});
|
||||
});
|
||||
Reference in new issue
Block a user