2024-01-09 23:20:17 +01:00
|
|
|
const { test } = require("node:test")
|
2023-10-23 23:11:41 +02:00
|
|
|
const assert = require("node:assert/strict")
|
2023-06-24 11:42:09 +02:00
|
|
|
|
|
|
|
const {
|
|
|
|
convertHeadingToHTMLFragment,
|
2023-10-23 23:11:41 +02:00
|
|
|
getMarkdownHeadings,
|
2024-01-12 00:43:45 +01:00
|
|
|
getMarkdownIdOrAnchorNameFragments,
|
2023-10-23 23:11:41 +02:00
|
|
|
} = require("../src/utils.js")
|
2023-06-24 11:42:09 +02:00
|
|
|
|
2023-10-23 23:11:41 +02:00
|
|
|
test("utils", async (t) => {
|
|
|
|
await t.test("convertHeadingToHTMLFragment", async () => {
|
2023-06-24 11:42:09 +02:00
|
|
|
assert.strictEqual(
|
2023-10-23 23:11:41 +02:00
|
|
|
convertHeadingToHTMLFragment("Valid Fragments"),
|
|
|
|
"#valid-fragments",
|
2023-06-24 11:42:09 +02:00
|
|
|
)
|
|
|
|
assert.strictEqual(
|
2023-10-23 23:11:41 +02:00
|
|
|
convertHeadingToHTMLFragment("Valid Heading With Underscores _"),
|
|
|
|
"#valid-heading-with-underscores-_",
|
2023-06-24 11:42:09 +02:00
|
|
|
)
|
|
|
|
assert.strictEqual(
|
|
|
|
convertHeadingToHTMLFragment(
|
2023-10-23 23:11:41 +02:00
|
|
|
`Valid Heading With Quotes ' And Double Quotes "`,
|
2023-06-24 11:42:09 +02:00
|
|
|
),
|
2023-10-23 23:11:41 +02:00
|
|
|
"#valid-heading-with-quotes--and-double-quotes-",
|
2023-06-24 11:42:09 +02:00
|
|
|
)
|
|
|
|
assert.strictEqual(
|
2023-10-23 23:11:41 +02:00
|
|
|
convertHeadingToHTMLFragment("🚀 Valid Heading With Emoji"),
|
|
|
|
"#-valid-heading-with-emoji",
|
2023-06-24 11:42:09 +02:00
|
|
|
)
|
|
|
|
})
|
|
|
|
|
2023-10-23 23:11:41 +02:00
|
|
|
await t.test("getMarkdownHeadings", async () => {
|
2023-06-24 11:42:09 +02:00
|
|
|
assert.deepStrictEqual(
|
2023-10-23 23:11:41 +02:00
|
|
|
getMarkdownHeadings("# Hello\n\n## World\n\n## Hello, world!\n"),
|
|
|
|
["Hello", "World", "Hello, world!"],
|
2023-06-24 11:42:09 +02:00
|
|
|
)
|
|
|
|
})
|
2024-01-11 14:42:34 +01:00
|
|
|
|
2024-01-12 00:43:45 +01:00
|
|
|
await t.test("getMarkdownIdOrAnchorNameFragments", async () => {
|
2024-01-11 14:42:34 +01:00
|
|
|
assert.deepStrictEqual(
|
2024-01-12 00:43:45 +01:00
|
|
|
getMarkdownIdOrAnchorNameFragments(
|
2024-01-12 00:33:05 +01:00
|
|
|
'<a name="anchorName" id="anchorId">Link</a>',
|
|
|
|
),
|
2024-01-11 14:42:34 +01:00
|
|
|
["#anchorId"],
|
|
|
|
)
|
|
|
|
assert.deepStrictEqual(
|
2024-01-12 00:43:45 +01:00
|
|
|
getMarkdownIdOrAnchorNameFragments('<a name="anchorName">Link</a>'),
|
2024-01-11 14:42:34 +01:00
|
|
|
["#anchorName"],
|
|
|
|
)
|
2024-01-12 00:43:45 +01:00
|
|
|
assert.deepStrictEqual(
|
|
|
|
getMarkdownIdOrAnchorNameFragments("<a>Link</a>"),
|
|
|
|
[],
|
|
|
|
)
|
|
|
|
assert.deepStrictEqual(getMarkdownIdOrAnchorNameFragments("<a>"), [])
|
|
|
|
assert.deepStrictEqual(getMarkdownIdOrAnchorNameFragments("<a id=>"), [])
|
2024-01-11 14:42:34 +01:00
|
|
|
})
|
2023-06-24 11:42:09 +02:00
|
|
|
})
|