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"]);
|
||||
});
|
||||
@@ -0,0 +1,28 @@
|
||||
import assert from "node:assert/strict";
|
||||
import test from "node:test";
|
||||
import { documentHeadings, headingLinkLine, linkFragment } from "../../../src/lib/workspace/headingLinks.ts";
|
||||
|
||||
test("section links decode fragments without changing the file path", () => {
|
||||
assert.equal(linkFragment("notes/a%23b.md#Caf%C3%A9%20setup"), "Café setup");
|
||||
assert.equal(linkFragment("#literal%"), "literal%");
|
||||
assert.equal(linkFragment("a.md"), null);
|
||||
assert.equal(headingLinkLine("# Title", ""), 1);
|
||||
});
|
||||
|
||||
test("headings use rendered text, Unicode, and unique slugs", () => {
|
||||
const source = "# **Windows** setup!\n\n## Café `setup`\n\n## Windows setup!\n\n## Windows setup-1\n\n## Windows setup!\n";
|
||||
assert.deepEqual(documentHeadings(source).map(({ slug }) => slug),
|
||||
["windows-setup", "café-setup", "windows-setup-1", "windows-setup-1-1", "windows-setup-2"]);
|
||||
assert.equal(headingLinkLine(source, "windows-setup-2"), 9);
|
||||
assert.equal(headingLinkLine(source, "Café setup"), 3);
|
||||
assert.equal(headingLinkLine(source, "missing"), null);
|
||||
});
|
||||
|
||||
test("section lines exclude properties and code, and include Setext headings", () => {
|
||||
const source = "---\r\ntitle: Test\r\n---\r\n\r\n```md\r\n# Fake\r\n```\r\n\r\nInstall\r\n=======\r\n\r\n## Real ###\r\n";
|
||||
assert.deepEqual(documentHeadings(source), [
|
||||
{ level: 1, text: "Install", slug: "install", line: 9 },
|
||||
{ level: 2, text: "Real", slug: "real", line: 12 },
|
||||
]);
|
||||
assert.equal(headingLinkLine(source, "fake"), null);
|
||||
});
|
||||
@@ -0,0 +1,31 @@
|
||||
import assert from "node:assert/strict";
|
||||
import test from "node:test";
|
||||
import { externalLinkText, workspaceLinkText } from "../../../src/lib/editor/linkCommands.ts";
|
||||
import { linkCandidates } from "../../../src/lib/workspace/markdownLinks.ts";
|
||||
|
||||
test("external links prepare editable syntax with the cursor in the missing field", () => {
|
||||
const empty = externalLinkText("", { from: 0, to: 0 });
|
||||
assert.equal(empty.insert, "[]()");
|
||||
assert.equal(empty.anchor, 1);
|
||||
assert.equal(empty.head, 1);
|
||||
const selected = externalLinkText("before [label] after", { from: 7, to: 14 });
|
||||
assert.equal(selected.insert, "[\\[label\\]]()");
|
||||
assert.equal(selected.anchor - selected.from, selected.insert.length - 1);
|
||||
assert.equal(selected.anchor, selected.head);
|
||||
});
|
||||
|
||||
test("workspace links retain the selected label and the exact workspace path", () => {
|
||||
assert.equal(workspaceLinkText("", { from: 0, to: 0 }, "notes/Same name.md").insert, "[[/notes/Same%20name.md]]");
|
||||
const edit = workspaceLinkText("before visible\nlabel after", { from: 7, to: 20 }, "nested/target.md");
|
||||
assert.equal(edit.insert, "[[/nested/target.md|visible label]]");
|
||||
assert.equal(edit.anchor, 7);
|
||||
assert.equal(edit.head, 7 + edit.insert.length);
|
||||
});
|
||||
|
||||
test("workspace link paths preserve spaces, brackets, hashes and literal percent signs", () => {
|
||||
const path = "notes/Nested/[A] #50%.md";
|
||||
const edit = workspaceLinkText("", { from: 0, to: 0 }, path);
|
||||
const target = edit.insert.slice(2, -2);
|
||||
assert.equal(target, "/notes/Nested/%5BA%5D%20%2350%25.md");
|
||||
assert.deepEqual(linkCandidates("notes/current.md", target, "wiki"), [path]);
|
||||
});
|
||||
@@ -0,0 +1,37 @@
|
||||
import assert from "node:assert/strict";
|
||||
import test from "node:test";
|
||||
import { findMarkdownLinks, wikiCandidates } from "../../../src/lib/workspace/markdownLinks.ts";
|
||||
|
||||
test("markdown links skip image embeds", () => {
|
||||
const links = findMarkdownLinks("See [alpha](notes/a.md) and ");
|
||||
assert.deepEqual(links, [
|
||||
{ kind: "md", from: 4, to: 23, label: "alpha", target: "notes/a.md" },
|
||||
]);
|
||||
});
|
||||
|
||||
test("wikilinks skip image embeds", () => {
|
||||
const links = findMarkdownLinks("Go [[projects/alpha|Alpha]] and ![[screenshot.png]]");
|
||||
assert.deepEqual(links, [
|
||||
{
|
||||
kind: "wiki",
|
||||
from: 3,
|
||||
to: 27,
|
||||
label: "Alpha",
|
||||
target: "projects/alpha",
|
||||
},
|
||||
]);
|
||||
});
|
||||
|
||||
test("wikiCandidates add .md for a bare name", () => {
|
||||
assert.deepEqual(wikiCandidates("alpha"), ["alpha.md", "notes/alpha.md", "alpha"]);
|
||||
});
|
||||
|
||||
|
||||
import { linkCandidates } from "../../../src/lib/workspace/markdownLinks.ts";
|
||||
|
||||
test("links resolve relative to notes, including parent paths and encoded spaces", () => {
|
||||
assert.deepEqual(linkCandidates("notes/project/inbox.md", "../other%20note.md", "md"), ["notes/other note.md"]);
|
||||
assert.deepEqual(linkCandidates("notes/inbox.md", "ideas", "wiki"), ["notes/ideas.md", "notes/ideas", "ideas.md", "ideas"]);
|
||||
assert.deepEqual(linkCandidates("notes/inbox.md", "../../secret", "md"), []);
|
||||
assert.deepEqual(linkCandidates("notes/inbox.md", "javascript:alert(1)", "md"), []);
|
||||
});
|
||||
@@ -0,0 +1,30 @@
|
||||
import { test } from "node:test";
|
||||
import assert from "node:assert/strict";
|
||||
import { documentLinks } from "../../../src/lib/editor/documentLinks.ts";
|
||||
import { tableLinkLabelPosition } from "../../../src/lib/editor/tableLinkSource.ts";
|
||||
|
||||
test("table link reveal retains the clicked character through Markdown label marks", () => {
|
||||
for (const [source, offset, prefix] of [
|
||||
["[Roadmap](docs/roadmap.md)", 5, "[Roadm"],
|
||||
['**Prefix** [One](same.md) + [Sec**ond**](same.md "Title")', 4, '**Prefix** [One](same.md) + [Sec**o'],
|
||||
["[A \\*star](note.md)", 3, "[A \\*"],
|
||||
["[Use `code`](note.md)", 5, "[Use `c"],
|
||||
["<https://example.org>", 8, "<https://"],
|
||||
] as const) {
|
||||
const link = documentLinks(source).at(-1)!;
|
||||
assert.equal(source.slice(0, tableLinkLabelPosition(source, link, offset)), prefix);
|
||||
}
|
||||
});
|
||||
|
||||
test("table wiki links retain literal label text, aliases, spaces, and escaped pipes", () => {
|
||||
for (const [source, offset, prefix] of [
|
||||
["[[guide\\|Guide]]", 3, "[[guide\\|Gui"],
|
||||
["[[guide\\|**Alias**]]", 2, "[[guide\\|**"],
|
||||
["[[ Guide ]]", 3, "[[ G"],
|
||||
["[[Guide\\|]]", 2, "[[Gu"],
|
||||
["[[guide\\|A\\|B]]", 2, "[[guide\\|A\\|"],
|
||||
] as const) {
|
||||
const link = documentLinks(source)[0];
|
||||
assert.equal(source.slice(0, tableLinkLabelPosition(source, link, offset)), prefix);
|
||||
}
|
||||
});
|
||||
@@ -0,0 +1,16 @@
|
||||
import test from "node:test";
|
||||
import assert from "node:assert/strict";
|
||||
import { workspaceFileLink } from "../../../src/lib/editor/workspaceFileLink.ts";
|
||||
import { wordAt } from "../../../src/lib/editor/spellingWord.ts";
|
||||
|
||||
test("file links resolve across nested folders and escape Markdown punctuation", () => {
|
||||
assert.equal(workspaceFileLink("notes/deep/source.md", "docs/a [draft](1).pdf"), "[a \\[draft\\](1).pdf](../../docs/a%20%5Bdraft%5D%281%29.pdf)");
|
||||
assert.equal(workspaceFileLink("notes/source.md", "notes/target.md"), "[target.md](target.md)");
|
||||
assert.equal(workspaceFileLink("notes/source.md", "assets/pic.png"), "");
|
||||
});
|
||||
|
||||
test("spelling finds Unicode words and apostrophes without including punctuation", () => {
|
||||
assert.deepEqual(wordAt("A naïve word.", 5), { word: "naïve", from: 2, to: 7 });
|
||||
assert.equal(wordAt("Don't stop", 3)?.word, "Don't");
|
||||
assert.equal(wordAt("word next", 5), null);
|
||||
});
|
||||
Reference in New Issue
Block a user