| 1 | import assert from "node:assert/strict"; |
| 2 | import { test } from "node:test"; |
| 3 | |
| 4 | import { isValue, qualifier, searchHref, shortCount, tokens, withIs, withQualifier } from "./search.ts"; |
| 5 | |
| 6 | test("quoted runs stay whole", () => { |
| 7 | assert.deepEqual(tokens('parse "two words" label:"good first issue" x'), ["parse", '"two words"', 'label:"good first issue"', "x"]); |
| 8 | }); |
| 9 | |
| 10 | test("a qualifier is read, quotes and all", () => { |
| 11 | assert.equal(qualifier("x language:rust", "language"), "rust"); |
| 12 | assert.equal(qualifier('x label:"good first issue"', "label"), "good first issue"); |
| 13 | assert.equal(qualifier("x", "language"), null); |
| 14 | }); |
| 15 | |
| 16 | test("a filter replaces its qualifier and keeps the rest", () => { |
| 17 | assert.equal(withQualifier("parse language:go repo:a/b", "language", "rust"), "parse repo:a/b language:rust"); |
| 18 | assert.equal(withQualifier("parse language:go", "language", null), "parse"); |
| 19 | assert.equal(withQualifier("crash", "label", "good first issue"), 'crash label:"good first issue"'); |
| 20 | assert.equal(withQualifier("x workspace:acme", "org", "beta", ["workspace"]), "x org:beta"); |
| 21 | }); |
| 22 | |
| 23 | test("is: values of one family replace each other", () => { |
| 24 | assert.equal(withIs("crash is:open is:pr", ["open", "closed", "merged"], "closed"), "crash is:pr is:closed"); |
| 25 | assert.equal(withIs("crash is:open", ["open", "closed"], null), "crash"); |
| 26 | assert.equal(isValue("crash is:Closed", ["open", "closed"]), "closed"); |
| 27 | assert.equal(isValue("crash", ["open", "closed"]), null); |
| 28 | }); |
| 29 | |
| 30 | test("addresses carry the query, the tab and the page", () => { |
| 31 | assert.equal(searchHref(" fn main ", "code"), "/search?q=fn+main&type=code"); |
| 32 | assert.equal(searchHref("x", null, 3), "/search?q=x&page=3"); |
| 33 | assert.equal(searchHref("x", "items", 1), "/search?q=x&type=items"); |
| 34 | }); |
| 35 | |
| 36 | test("counts stop at the cap", () => { |
| 37 | assert.equal(shortCount(12), "12"); |
| 38 | assert.equal(shortCount(1000), "1k+"); |
| 39 | }); |