web: parse search type prefixes into kind filters
This commit is contained in:
@@ -0,0 +1,38 @@
|
||||
import { test } from "node:test";
|
||||
import assert from "node:assert/strict";
|
||||
import { parseSearchQuery, SEARCH_KINDS } from "../src/search.js";
|
||||
|
||||
test("both type aliases and kinds are case insensitive", () => {
|
||||
for (const { value } of SEARCH_KINDS.filter((kind) => kind.value)) {
|
||||
for (const prefix of ["t", "type", "T", "TyPe"]) {
|
||||
assert.deepEqual(parseSearchQuery(`${prefix}:${value.toUpperCase()} plan`), {
|
||||
query: " plan", kind: value, hasType: true,
|
||||
});
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
test("normal, quoted and unsupported text is preserved byte for byte", () => {
|
||||
for (const query of [
|
||||
' ordinary text\twith\nspacing ',
|
||||
'"t:pipeline" "hello world"', "'type:artifact'",
|
||||
'"escaped \\" t:run"', '"unclosed t:run',
|
||||
"t:prompt type:unknown t: t:PIPELINES", "not:t:run t:run,",
|
||||
"prefix\"t:run\"", "\\t:run",
|
||||
]) {
|
||||
assert.deepEqual(parseSearchQuery(query, "field"), { query, kind: "field", hasType: false });
|
||||
}
|
||||
assert.equal(parseSearchQuery('t:artifact "t:pipeline" report').query, ' "t:pipeline" report');
|
||||
});
|
||||
|
||||
test("last supported token wins over selector; unknown tokens do not override it", () => {
|
||||
assert.deepEqual(parseSearchQuery("t:run plan TYPE:artifact t:unknown", "pipeline"), {
|
||||
query: " plan t:unknown", kind: "artifact", hasType: true,
|
||||
});
|
||||
assert.equal(parseSearchQuery("plan", "step").kind, "step");
|
||||
});
|
||||
|
||||
test("type-only query is distinguishable from literal text and blank input", () => {
|
||||
assert.deepEqual(parseSearchQuery("t:pipeline"), { query: "", kind: "pipeline", hasType: true });
|
||||
assert.deepEqual(parseSearchQuery(""), { query: "", kind: "", hasType: false });
|
||||
});
|
||||
Reference in New Issue
Block a user