RuneStone 1.0.0
This commit is contained in:
@@ -0,0 +1,33 @@
|
||||
import { test } from "node:test";
|
||||
import assert from "node:assert/strict";
|
||||
import { documentLinks, documentLinkAt } from "../../../src/lib/editor/documentLinks.ts";
|
||||
|
||||
test("document links keep complete source ranges and decode Markdown destinations", () => {
|
||||
const source = '[Local](<notes/two words.md> "Title") and [Web](https://example.com/a_(b)) and [[Another note|Alias]]';
|
||||
const links = documentLinks(source);
|
||||
assert.deepEqual(links.map(link => [link.kind, link.target]), [["md", "notes/two words.md"], ["md", "https://example.com/a_(b)"], ["wiki", "Another note"]]);
|
||||
for (const link of links) {
|
||||
assert.equal(documentLinkAt(source, link.from + 2)?.target, link.target);
|
||||
assert.equal(documentLinkAt(source, link.to - 1)?.target, link.target);
|
||||
}
|
||||
});
|
||||
|
||||
test("literal code and images cannot become document links", () => {
|
||||
const source = ' `https://example.com`\n\n```md\n[Hidden](hidden.md)\n[[Hidden]]\n```\n\n[Open](open.md)';
|
||||
assert.deepEqual(documentLinks(source).map(link => link.target), ["open.md"]);
|
||||
});
|
||||
|
||||
test("bare and angle links omit prose punctuation and preserve balanced parentheses", () => {
|
||||
const source = 'Go to https://example.com/a_(b). Next (<https://example.org>). Mail <mailto:[email protected]>.';
|
||||
assert.deepEqual(documentLinks(source).map(link => link.target), ["https://example.com/a_(b)", "https://example.org", "mailto:[email protected]"]);
|
||||
});
|
||||
|
||||
test("edit link selects only its destination, preserving labels, titles, brackets, and spacing", () => {
|
||||
const source = '[Local](<notes/two words.md> "Title") and [Web](https://example.com/a_\\(b\\)) and [[ Another note#Heading |Alias]] and <https://example.org>.';
|
||||
const links = documentLinks(source);
|
||||
assert.deepEqual(links.map(link => source.slice(link.targetFrom, link.targetTo)), ["notes/two words.md", "https://example.com/a_\\(b\\)", "Another note#Heading", "https://example.org"]);
|
||||
});
|
||||
|
||||
test("wiki image embeds do not expose document actions", () => {
|
||||
assert.deepEqual(documentLinks('![[image.png]] [[note|label]]').map(link => link.target), ["note"]);
|
||||
});
|
||||
Reference in New Issue
Block a user