2024-02-09 04:00:45 +08:00
|
|
|
import { encodePageRef, parsePageRef } from "./page_ref.ts";
|
2024-03-16 22:29:24 +08:00
|
|
|
import { assertEquals } from "$std/testing/asserts.ts";
|
2024-01-24 18:58:33 +08:00
|
|
|
|
|
|
|
Deno.test("Page utility functions", () => {
|
|
|
|
// Base cases
|
|
|
|
assertEquals(parsePageRef("foo"), { page: "foo" });
|
|
|
|
assertEquals(parsePageRef("[[foo]]"), { page: "foo" });
|
|
|
|
assertEquals(parsePageRef("foo@1"), { page: "foo", pos: 1 });
|
|
|
|
assertEquals(parsePageRef("foo$bar"), { page: "foo", anchor: "bar" });
|
2024-01-25 21:51:40 +08:00
|
|
|
assertEquals(parsePageRef("foo#My header"), {
|
|
|
|
page: "foo",
|
|
|
|
header: "My header",
|
|
|
|
});
|
2024-01-24 18:58:33 +08:00
|
|
|
assertEquals(parsePageRef("foo$bar@1"), {
|
|
|
|
page: "foo",
|
|
|
|
anchor: "bar",
|
|
|
|
pos: 1,
|
|
|
|
});
|
|
|
|
|
|
|
|
// Edge cases
|
|
|
|
assertEquals(parsePageRef(""), { page: "" });
|
|
|
|
assertEquals(parsePageRef("user@domain.com"), { page: "user@domain.com" });
|
|
|
|
|
|
|
|
// Encoding
|
|
|
|
assertEquals(encodePageRef({ page: "foo" }), "foo");
|
|
|
|
assertEquals(encodePageRef({ page: "foo", pos: 10 }), "foo@10");
|
|
|
|
assertEquals(encodePageRef({ page: "foo", anchor: "bar" }), "foo$bar");
|
2024-01-25 21:51:40 +08:00
|
|
|
assertEquals(encodePageRef({ page: "foo", header: "bar" }), "foo#bar");
|
2024-01-24 18:58:33 +08:00
|
|
|
});
|