/* eslint-disable no-irregular-whitespace */ import { describe, expect, test } from "@jest/globals"; import { unescape } from "lodash-es"; import { marked } from "."; describe("test marked parser", () => { test("horizontal rule", () => { const tests = [ { markdown: `To create a horizontal rule, use three or more asterisks (***), dashes (---), or underscores (___) on a line by themselves. --- This is some text after the horizontal rule. ___ This is some text after the horizontal rule. *** This is some text after the horizontal rule.`, want: `

To create a horizontal rule, use three or more asterisks (*), dashes (---), or underscores (___) on a line by themselves.


This is some text after the horizontal rule.


This is some text after the horizontal rule.


This is some text after the horizontal rule.

`, }, ]; for (const t of tests) { expect(unescape(marked(t.markdown))).toBe(t.want); } }); test("parse code block", () => { const tests = [ { markdown: `\`\`\` hello world! \`\`\``, want: `
hello world!
`, }, { markdown: `test code block \`\`\`js console.log("hello world!") \`\`\``, want: `

test code block

console.log("hello world!")
`, }, ]; for (const t of tests) { expect(unescape(marked(t.markdown))).toBe(t.want); } }); test("parse todo list block", () => { const tests = [ { markdown: `My task: - [ ] finish my homework - [x] yahaha`, want: `

My task:

finish my homework

yahaha

`, }, ]; for (const t of tests) { expect(unescape(marked(t.markdown))).toBe(t.want); } }); test("parse list block", () => { const tests = [ { markdown: `This is a list * list 123 1. 123123`, want: `

This is a list

list 123

1.123123

`, }, ]; for (const t of tests) { expect(unescape(marked(t.markdown))).toBe(t.want); } }); test("parse inline element", () => { const tests = [ { markdown: `Link: [baidu](https://baidu.com)`, want: `

Link: baidu

`, }, ]; for (const t of tests) { expect(unescape(marked(t.markdown))).toBe(t.want); } }); test("parse inline code within inline element", () => { const tests = [ { markdown: `Link: [\`baidu\`](https://baidu.com)`, want: `

Link: baidu

`, }, ]; for (const t of tests) { expect(unescape(marked(t.markdown))).toBe(t.want); } }); test("parse plain link", () => { const tests = [ { markdown: `Link:https://baidu.com`, want: `

Link:https://baidu.com

`, }, ]; for (const t of tests) { expect(unescape(marked(t.markdown))).toBe(t.want); } }); test("parse inline code", () => { const tests = [ { markdown: `Code: \`console.log("Hello world!")\``, want: `

Code: console.log("Hello world!")

`, }, ]; for (const t of tests) { expect(unescape(marked(t.markdown))).toBe(t.want); } }); test("parse bold and em text", () => { const tests = [ { markdown: `Important: **Minecraft**`, want: `

Important: Minecraft

`, }, { markdown: `Em: *Minecraft*`, want: `

Em: Minecraft

`, }, { markdown: `Important: ***Minecraft/123***`, want: `

Important: Minecraft/123

`, }, { markdown: `Important: ***[baidu](https://baidu.com)***`, want: `

Important: baidu

`, }, ]; for (const t of tests) { expect(unescape(marked(t.markdown))).toBe(t.want); } }); test("parse full width space", () => { const tests = [ { markdown: `  line1   line2`, want: `

  line1

  line2

`, }, ]; for (const t of tests) { expect(unescape(marked(t.markdown))).toBe(t.want); } }); });