chore: update marked tests

This commit is contained in:
Steven 2022-10-15 21:57:56 +08:00
parent 26aae0e637
commit 749486ba3c

View File

@ -3,44 +3,6 @@ import { unescape } from "lodash-es";
import { marked } from "."; import { marked } from ".";
describe("test marked parser", () => { 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: `<p>text above the table</p>
<table>
<thead>
<tr>
<th>a</th><th>b</th><th>c</th>
</tr>
</thead>
<tbody>
<tr><td>1</td><td>2</td><td>3</td></tr><tr><td>4</td><td>5</td><td>6</td></tr>
</tbody>
</table>
<p>text below the table</p>
`,
},
{
markdown: `| a | b | c |
| 1 | 2 | 3 |
| 4 | 5 | 6 |`,
want: `<p>| a | b | c |</p>
<p>| 1 | 2 | 3 |</p>
<p>| 4 | 5 | 6 |</p>`,
},
];
for (const t of tests) {
expect(unescape(marked(t.markdown))).toBe(t.want);
}
});
test("parse code block", () => { test("parse code block", () => {
const tests = [ const tests = [
{ {
@ -159,4 +121,41 @@ console.log("hello world!")
expect(unescape(marked(t.markdown))).toBe(t.want); expect(unescape(marked(t.markdown))).toBe(t.want);
} }
}); });
test("parse table", () => {
const tests = [
{
markdown: `text above the table
| a | b | c |
|---|---|---|
| 1 | 2 | 3 |
| 4 | 5 | 6 |
text below the table
`,
want: `<p>text above the table</p>
<table>
<thead>
<tr>
<th>a</th><th>b</th><th>c</th>
</tr>
</thead>
<tbody>
<tr><td>1</td><td>2</td><td>3</td></tr><tr><td>4</td><td>5</td><td>6</td></tr>
</tbody>
</table>
<p>text below the table</p>
`,
},
{
markdown: `| a | b | c |
| 1 | 2 | 3 |
| 4 | 5 | 6 |`,
want: `<p>| a | b | c |</p>
<p>| 1 | 2 | 3 |</p>
<p>| 4 | 5 | 6 |</p>`,
},
];
for (const t of tests) {
expect(unescape(marked(t.markdown))).toBe(t.want);
}
});
}); });