| 1 |
// Parsing #N and @user as they are typed and hovered. |
| 2 |
import { test } from "node:test"; |
| 3 |
import assert from "node:assert/strict"; |
| 4 |
import { typingAt, numberAt, rootFromScmQuery } from "../out/refs.mjs"; |
| 5 |
|
| 6 |
test("what is being typed", () => { |
| 7 |
assert.deepEqual(typingAt("Fixes #"), { kind: "number", prefix: "", start: 6 }); |
| 8 |
assert.deepEqual(typingAt("Fixes #1"), { kind: "number", prefix: "1", start: 6 }); |
| 9 |
assert.deepEqual(typingAt("#12"), { kind: "number", prefix: "12", start: 0 }); |
| 10 |
assert.deepEqual(typingAt("(see #4"), { kind: "number", prefix: "4", start: 5 }); |
| 11 |
assert.deepEqual(typingAt("cc @an"), { kind: "user", prefix: "an", start: 3 }); |
| 12 |
assert.deepEqual(typingAt("@"), { kind: "user", prefix: "", start: 0 }); |
| 13 |
assert.equal(typingAt("a#1"), undefined, "not at a word start"); |
| 14 |
assert.equal(typingAt("mail@host"), undefined, "an address is not a mention"); |
| 15 |
assert.equal(typingAt("#1 done"), undefined, "the cursor has moved on"); |
| 16 |
}); |
| 17 |
|
| 18 |
test("which reference a position sits on", () => { |
| 19 |
const line = "Fixes #12 and (#7), not a#3"; |
| 20 |
assert.deepEqual(numberAt(line, 7), { number: 12, start: 6, end: 9 }); |
| 21 |
assert.deepEqual(numberAt(line, 9), { number: 12, start: 6, end: 9 }); |
| 22 |
assert.deepEqual(numberAt(line, 16), { number: 7, start: 15, end: 17 }); |
| 23 |
assert.equal(numberAt(line, 2), undefined); |
| 24 |
assert.equal(numberAt(line, 26), undefined, "a#3 is not a reference"); |
| 25 |
}); |
| 26 |
|
| 27 |
test("the SCM box names its repository", () => { |
| 28 |
assert.equal(rootFromScmQuery("rootUri=" + encodeURIComponent("file:///home/andy/development/oxygen")), "/home/andy/development/oxygen"); |
| 29 |
assert.equal(rootFromScmQuery("rootUri=" + encodeURIComponent("file:///home/a%20b/x")), "/home/a b/x"); |
| 30 |
assert.equal(rootFromScmQuery(""), undefined); |
| 31 |
}); |
| 32 |
|
| 33 |
import { todoTitle, annotateTodo, issueBody } from "../out/refs.mjs"; |
| 34 |
|
| 35 |
test("TODO lines become issue titles and then carry the number", () => { |
| 36 |
assert.equal(todoTitle(" // TODO: handle the empty well"), "handle the empty well"); |
| 37 |
assert.equal(todoTitle("/* FIXME - leaks a buffer */"), "leaks a buffer"); |
| 38 |
assert.equal(todoTitle("# XXX"), "XXX in the code"); |
| 39 |
assert.equal(todoTitle("let x = 1;"), undefined); |
| 40 |
assert.equal(annotateTodo(" // TODO: handle the empty well", 12), " // TODO(#12): handle the empty well"); |
| 41 |
assert.equal(annotateTodo("// TODO(#3): already linked", 12), "// TODO(#3): already linked", "an existing link is kept"); |
| 42 |
}); |
| 43 |
|
| 44 |
test("the issue body quotes the code under a permalink", () => { |
| 45 |
const body = issueBody({ permalink: "https://h/a/b/file/abc/src/x.rs#L3-L4", path: "src/x.rs", startLine: 3, endLine: 4, language: "rust", code: "fn a() {}\nfn b() {}\n", pinned: true }); |
| 46 |
assert.ok(body.startsWith("From [`src/x.rs`, lines 3–4](https://h/a/b/file/abc/src/x.rs#L3-L4)"), body); |
| 47 |
assert.ok(body.includes("```rust\nfn a() {}\nfn b() {}\n```"), body); |
| 48 |
assert.ok(!body.includes("several heads")); |
| 49 |
assert.ok(issueBody({ permalink: "p", path: "x", startLine: 1, endLine: 1, language: "", code: "a", pinned: false }).includes("several heads")); |
| 50 |
}); |