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,
|
|
|
|
} = 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
|
|
|
)
|
|
|
|
})
|
|
|
|
})
|