Files
wehub-resource-sync 7df9ebf22c
Sync labels / sync (push) Failing after 1m9s
Publish Container Image / Build and publish container image (push) Has been cancelled
Deploy Website / Deploy to GitHub Pages (push) Has been cancelled
Deploy Website / Build website and demo (push) Has been cancelled
Deploy viewer / Deploy viewer proxy to Cloudflare Workers (push) Has been cancelled
Deploy tiles / Deploy planetary tile proxy to Cloudflare Workers (push) Has been cancelled
Deploy collab / Deploy collaboration relay to Cloudflare Workers (push) Has been cancelled
CI / Dependency audit (push) Has been cancelled
CI / E2E smoke (Playwright) (push) Has been cancelled
CI / Validate CITATION.cff (push) Has been cancelled
CI / Build and test (push) Has been cancelled
chore: import upstream snapshot with attribution
2026-07-13 12:33:00 +08:00

60 lines
2.1 KiB
TypeScript

import assert from "node:assert/strict";
import { describe, it } from "node:test";
import {
sqlCompletionCandidates,
wordPrefixAt,
} from "../apps/geolibre-desktop/src/lib/sql-completion";
import type { SqlWorkspaceTableColumns } from "../apps/geolibre-desktop/src/lib/sql-workspace";
// Hand-built tables so the test stays free of the DuckDB-WASM import that
// sql-workspace.ts pulls in (it cannot load under the node test runner). The
// shape mirrors what previewLayerColumns produces for a loaded layer.
const tables: SqlWorkspaceTableColumns[] = [
{ tableName: "us_cities", columns: ["NAME", "POP", "geom"] },
];
describe("wordPrefixAt", () => {
it("returns the identifier word before the cursor", () => {
const text = "SELECT * FROM us_cit";
assert.deepEqual(wordPrefixAt(text, text.length), {
prefix: "us_cit",
start: 14,
});
});
it("returns an empty prefix when the cursor follows whitespace", () => {
const text = "SELECT * FROM ";
assert.deepEqual(wordPrefixAt(text, text.length), {
prefix: "",
start: text.length,
});
});
});
describe("sqlCompletionCandidates", () => {
it("ranks table names before functions and keywords", () => {
const candidates = sqlCompletionCandidates("us", tables);
assert.equal(candidates[0], "us_cities");
});
it("matches case-insensitively and offers columns", () => {
assert.ok(sqlCompletionCandidates("na", tables).includes("NAME"));
});
it("offers SQL keywords and ST_ functions on a prefix", () => {
assert.ok(sqlCompletionCandidates("sel", tables).includes("SELECT"));
assert.ok(sqlCompletionCandidates("st_ce", tables).includes("ST_Centroid"));
});
it("offers only tables and columns for an empty prefix", () => {
const candidates = sqlCompletionCandidates("", tables);
assert.ok(candidates.includes("us_cities"));
assert.ok(candidates.includes("NAME"));
assert.ok(!candidates.includes("SELECT"));
});
it("returns nothing when no candidate matches", () => {
assert.deepEqual(sqlCompletionCandidates("zzz", tables), []);
});
});