refactor(desktop): organize lib modules by domain

This commit is contained in:
t8y2 committed 2026-07-04 13:53:52 +08:00
1 parent 90f0594e93
commit 7e7c4944e9
700 files changed
+1292 -1264

No files matched your search

@@ -0,0 +1,54 @@
import { describe, expect, it } from "vitest";
import { extractIdentifierAt, matchTable, splitQualifiedIdentifier } from "@/lib/sql/sqlNavigation";
describe("extractIdentifierAt", () => {
it("extracts unquoted qualified identifiers", () => {
const sql = "select * from MAAC00.Accounts";
expect(extractIdentifierAt(sql, sql.indexOf("Accounts"))).toBe("MAAC00.Accounts");
});
it("extracts backtick-quoted qualified identifiers", () => {
const sql = "select * from `MAAC00`.Accounts";
expect(extractIdentifierAt(sql, sql.indexOf("Accounts"))).toBe("MAAC00.Accounts");
expect(extractIdentifierAt(sql, sql.indexOf("MAAC00"))).toBe("MAAC00.Accounts");
});
it("extracts double-quoted qualified identifiers", () => {
const sql = 'select * from "MAAC00"."Accounts"';
expect(extractIdentifierAt(sql, sql.indexOf("Accounts"))).toBe("MAAC00.Accounts");
});
});
describe("splitQualifiedIdentifier", () => {
it("splits quoted and multi-part identifiers", () => {
expect(splitQualifiedIdentifier('catalog."MAAC00".Accounts')).toEqual(["catalog", "MAAC00", "Accounts"]);
expect(splitQualifiedIdentifier("`MAAC00`.Accounts")).toEqual(["MAAC00", "Accounts"]);
});
});
describe("matchTable", () => {
it("matches schema-qualified table identifiers", () => {
const table = { schema: "MAAC00", name: "Accounts" };
expect(matchTable("maac00.accounts", [table])).toBe(table);
});
it("matches catalog.schema.table identifiers against schema-scoped tables", () => {
const table = { schema: "MAAC00", name: "Accounts" };
expect(matchTable("catalog.maac00.accounts", [table])).toBe(table);
});
it("matches quoted schema-qualified table identifiers", () => {
const table = { schema: "MAAC00", name: "Accounts" };
expect(matchTable("`MAAC00`.Accounts", [table])).toBe(table);
});
it("does not treat non-schema qualifiers as table matches", () => {
expect(matchTable("u.users", [{ schema: "public", name: "users" }])).toBeNull();
});
});