import { describe, expect, test } from "@jest/globals"; import { unescape } from "lodash-es"; import { marked } from "."; describe("test marked parser", () => { test("test markdown table", () => { const tests = [ { markdown: `text above the table | a | b | c | |---|---|---| | 1 | 2 | 3 | | 4 | 5 | 6 | text below the table `, want: `

text above the table

abc
123
456

text below the table

`, }, { markdown: `| a | b | c | | 1 | 2 | 3 | | 4 | 5 | 6 |`, want: `

| a | b | c |

| 1 | 2 | 3 |

| 4 | 5 | 6 |

`, }, ]; 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 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); } }); });