use mdka::from_html;
#[test]
fn heading() {
let cases = vec![
("
1
", "# 1\n\n"),
("2
", "## 2\n\n"),
("3
", "### 3\n\n"),
("4
", "#### 4\n\n"),
("5
", "##### 5\n\n"),
("6
", "###### 6\n\n"),
(
"1
\n2
\n3
",
"# 1\n\n## 2\n\n### 3\n\n",
),
(
"1
\n\n\n2
\n\n\n3
",
"# 1\n\n## 2\n\n### 3\n\n",
),
];
assert(cases);
}
#[test]
fn block() {
let cases = vec![
("12", "12"),
("1
2
", "1\n2\n"),
("1
2
", "1\n\n2\n\n"),
];
assert(cases);
}
#[test]
fn bold() {
let cases = vec![("1", " **1** "), ("2", " **2** ")];
assert(cases);
}
#[test]
fn italic() {
let cases = vec![("1", " *1* "), ("2", " *2* ")];
assert(cases);
}
#[test]
fn list() {
let cases = vec![
("", "- 1\n- 2\n\n"),
("", "- 1\n- 2\n\n"),
("- 1
- 2
", "1. 1\n1. 2\n\n"),
("- 1
- 2
", "1. 1\n1. 2\n\n"),
(
"",
"- 1\n - 1-1\n - 1-2\n- 2\n\n",
),
(
"",
"- 1\n - 1-1\n - 1-1-1\n - 1-1-2\n - 1-2\n- 2\n\n",
),
(
"",
"- \n - \n - 1-1-1\n - 1-1-2\n - 1-2\n- 2\n\n",
),
(
"",
"- 1\n 1. 1-1\n 1. 1-2\n- 2\n\n",
),
(
"- 1
- 2
",
"1. 1\n - 1-1\n - 1-2\n1. 2\n\n",
),
];
assert(cases);
}
// more test: variety
#[test]
fn table() {
let cases = vec![
(r#"
h1 |
h2 |
d1-1 |
d1-2 |
d2-1 |
d2-2 |
"#, "| h1 | h2 |\n| --- | --- |\n| d1-1 | d1-2 |\n| d2-1 | d2-2 |\n\n\n"),
(r#"
"#,
"| h1 | h2 | h3 |\n|:--- | --- | ---:|\n| d1 | d2 | d3 |\n\n"),
(r#"
"#,
"| h1 | h2 | h3 |\n|:--- | --- | ---:|\n| d1 | d2 | d3 |\n\n"),
(r#" | another column |
| first row |
| second row |
"#,
"| ![alt-text](image1.png) | another column |\n| --- | --- |\n| ![](image2.jpg) | first row |\n| ![alt-text](image3.gif) | second row |\n\n")
];
assert(cases);
}
#[test]
fn preformatted() {
let cases = vec![
("1
", "```\n1\n```\n\n"),
("1
", " `1` "),
("1
", "```\n1\n```\n\n"),
("1
", "```rust\n1\n```\n\n"),
("1
", "```\n1
\n```\n\n"),
("1
", " `1
` "),
("start
a
end", "start\n\n```\na
\n```\n\nend"),
("start a
end
", "start\n\n `a` \nend"),
(r#"
"#, "- a\n 1. \n ```\n 1
2\n ```\n \n \n- b\n\n\n "),
];
assert(cases);
}
// more test: nested elements
#[test]
fn blockquote() {
let cases = vec![
(
"a\nbc\ndef
",
"> a\n> bc\n> def\n\n",
),
(
"a
bc
def
",
"> a \n> bc \n> def\n\n",
),
(
"a\nbc
\ndef
",
"> a\n> bc \n> def\n> ---\n> \n\n",
),
(
r#"
"#,
"- due to it: \n > lorem\n- ipsum\n\n\n",
),
];
assert(cases);
}
#[test]
fn link() {
let cases = vec![
("Click me", " [Click me](https://some-fqdn/some-dir/some-point) "),
("no link", " [no link]() "),
("This is some link:link1and also:link2.
", "This is some link: [link1](somewhere1) and also: [link2](somewhere2) .\n\n"),
];
assert(cases);
}
#[test]
fn media() {
let cases = vec![
(
"",
"![](/some-dir/some-file.ext)\n",
),
("", "![awesome image]()\n"),
(
"",
"![awesome image](/some-dir/some-file.ext)\n",
),
(
"",
"![awesome image](/some-dir/some-file.ext1)\n",
),
(
"