Archived
1
0
Fork 0
This repository has been archived on 2024-07-25. You can view files and clone it, but cannot push or open issues or pull requests.
paren/par/md.test.ts

89 lines
2.7 KiB
TypeScript
Raw Normal View History

2022-06-11 22:07:22 +03:00
import { assertEquals } from "testing/asserts.ts";
import { HtmlStrRenderer } from "../ren/html_str.ts";
import { MarkdownParser } from "./md.ts";
const ren = new HtmlStrRenderer();
Deno.test({
name: "should skip new line character",
fn: () => {
const par = new MarkdownParser();
assertEquals(ren.render(par.parse("\n")), "");
assertEquals(ren.render(par.parse("\r\n")), "");
assertEquals(ren.render(par.parse("\n\r\n")), "");
},
});
2022-06-11 22:07:22 +03:00
Deno.test({
name: "should parse empty ATX header",
2022-06-11 22:07:22 +03:00
fn: () => {
const par = new MarkdownParser();
const res = par.parse("#");
assertEquals(ren.render(res), "<h1></h1>");
},
});
Deno.test({
name: "should parse ATX header with text",
2022-06-11 22:07:22 +03:00
fn: () => {
const par = new MarkdownParser();
assertEquals(ren.render(par.parse("# hello")), "<h1>hello</h1>");
assertEquals(ren.render(par.parse("# hello#")), "<h1>hello#</h1>");
2022-06-11 22:07:22 +03:00
},
});
2022-06-11 22:13:28 +03:00
Deno.test({
name: "should parse ATX header with specific level",
2022-06-11 22:13:28 +03:00
fn: () => {
const par = new MarkdownParser();
assertEquals(ren.render(par.parse("# hello")), "<h1>hello</h1>");
assertEquals(ren.render(par.parse("## hello")), "<h2>hello</h2>");
assertEquals(ren.render(par.parse("### hello")), "<h3>hello</h3>");
assertEquals(ren.render(par.parse("#### hello")), "<h4>hello</h4>");
assertEquals(ren.render(par.parse("##### hello")), "<h5>hello</h5>");
assertEquals(ren.render(par.parse("###### hello")), "<h6>hello</h6>");
},
});
Deno.test({
name: "should parse ATX header if line contains additional spaces",
2022-06-11 22:13:28 +03:00
fn: () => {
const par = new MarkdownParser();
assertEquals(ren.render(par.parse(" # hello")), "<h1>hello</h1>");
assertEquals(ren.render(par.parse(" # hello")), "<h1>hello</h1>");
assertEquals(ren.render(par.parse(" # hello")), "<h1>hello</h1>");
assertEquals(ren.render(par.parse("\n # hello")), "<h1>hello</h1>");
assertEquals(ren.render(par.parse("\r\n # hello")), "<h1>hello</h1>");
2022-06-11 22:13:28 +03:00
},
});
Deno.test({
name: "should parse ATX header with closing sequence",
fn: () => {
const par = new MarkdownParser();
assertEquals(ren.render(par.parse("# #")), "<h1></h1>");
assertEquals(ren.render(par.parse("# hello #")), "<h1>hello</h1>");
assertEquals(ren.render(par.parse("# hello #########")), "<h1>hello</h1>");
assertEquals(ren.render(par.parse("# hello # ")), "<h1>hello</h1>");
assertEquals(ren.render(par.parse("###### hello #")), "<h6>hello</h6>");
},
});
Deno.test({
name: "should parse many headers with text",
fn: () => {
const par = new MarkdownParser();
const input = `\
# hello
## world
### this is
#### my world!`;
assertEquals(
ren.render(par.parse(input)),
"<h1>hello</h1><h2>world</h2><h3>this is</h3><h4>my world!</h4>",
);
},
});