2021-07-10 13:29:16 +00:00
|
|
|
#!/bin/bash
|
|
|
|
|
|
|
|
set -e
|
|
|
|
|
|
|
|
check() {
|
|
|
|
input="$(mktemp)"
|
|
|
|
expected_output="$(mktemp)"
|
|
|
|
output="$(mktemp)"
|
|
|
|
|
|
|
|
current="input"
|
|
|
|
while IFS='$\n' read -r line; do
|
|
|
|
if [[ "$line" == "---" ]]; then
|
|
|
|
current="output"
|
|
|
|
elif [[ "$current" == "input" ]]; then
|
|
|
|
echo "$line" >> "$input"
|
|
|
|
else
|
2021-07-10 17:13:17 +00:00
|
|
|
echo "$line" >> "$expected_output"
|
2021-07-10 13:29:16 +00:00
|
|
|
fi
|
|
|
|
done
|
|
|
|
|
|
|
|
awk -f markdown.awk "$input" >> "$output"
|
|
|
|
|
|
|
|
result="success"
|
|
|
|
|
|
|
|
if ! cmp -s "$output" "$expected_output"; then
|
|
|
|
echo "FAIL"
|
|
|
|
echo "--- input"
|
|
|
|
cat "$input"
|
|
|
|
echo "--- expected"
|
|
|
|
cat "$expected_output"
|
|
|
|
echo "--- got"
|
|
|
|
cat "$output"
|
|
|
|
echo "---"
|
|
|
|
result="fail"
|
|
|
|
else
|
|
|
|
echo "SUCCESS"
|
|
|
|
fi
|
|
|
|
|
|
|
|
rm "$input"
|
|
|
|
rm "$expected_output"
|
|
|
|
rm "$output"
|
|
|
|
|
|
|
|
if [[ "$result" == "fail" ]]; then
|
|
|
|
exit 1
|
|
|
|
fi
|
|
|
|
}
|
|
|
|
|
|
|
|
check <<-EOF
|
|
|
|
This is a simple sentence.
|
|
|
|
---
|
|
|
|
<p>This is a simple sentence.</p>
|
|
|
|
EOF
|
|
|
|
|
|
|
|
|
|
|
|
check <<-EOF
|
|
|
|
This is a
|
|
|
|
simple sentence.
|
|
|
|
---
|
|
|
|
<p>This is a simple sentence.</p>
|
|
|
|
EOF
|
|
|
|
|
|
|
|
check <<-EOF
|
|
|
|
First paragraph.
|
|
|
|
|
|
|
|
Second paragraph.
|
|
|
|
---
|
|
|
|
<p>First paragraph.</p>
|
|
|
|
<p>Second paragraph.</p>
|
|
|
|
EOF
|
|
|
|
|
|
|
|
check <<-EOF
|
|
|
|
# Header
|
|
|
|
body
|
|
|
|
---
|
2021-07-10 22:47:07 +00:00
|
|
|
<h1>Header</h1>
|
2021-07-10 13:29:16 +00:00
|
|
|
<p>body</p>
|
|
|
|
EOF
|
|
|
|
|
|
|
|
check <<-EOF
|
|
|
|
# Header1
|
|
|
|
## Header2
|
|
|
|
### Header3
|
|
|
|
---
|
2021-07-10 22:47:07 +00:00
|
|
|
<h1>Header1</h1>
|
|
|
|
<h2>Header2</h2>
|
|
|
|
<h3>Header3</h3>
|
2021-07-10 13:29:16 +00:00
|
|
|
EOF
|
|
|
|
|
2021-07-10 22:45:07 +00:00
|
|
|
check <<-EOF
|
|
|
|
underlined header 1
|
|
|
|
===================
|
|
|
|
|
|
|
|
underlined header 2
|
|
|
|
-------------------
|
|
|
|
---
|
|
|
|
<h1>underlined header 1</h1>
|
|
|
|
<h2>underlined header 2</h2>
|
|
|
|
EOF
|
|
|
|
|
2021-07-10 13:29:16 +00:00
|
|
|
check <<-EOF
|
|
|
|
**bold**
|
|
|
|
---
|
|
|
|
<p><strong>bold</strong></p>
|
|
|
|
EOF
|
|
|
|
|
|
|
|
check <<-EOF
|
|
|
|
**bold
|
|
|
|
multiline**
|
|
|
|
---
|
|
|
|
<p><strong>bold multiline</strong></p>
|
|
|
|
EOF
|
|
|
|
|
|
|
|
check <<-EOF
|
|
|
|
**bold
|
|
|
|
---
|
|
|
|
<p>**bold</p>
|
|
|
|
EOF
|
|
|
|
|
|
|
|
check <<-"EOF"
|
|
|
|
```
|
|
|
|
first line of code
|
|
|
|
|
|
|
|
second line of code
|
|
|
|
```
|
|
|
|
---
|
2021-07-10 17:13:17 +00:00
|
|
|
<pre><code>
|
2021-07-10 13:29:16 +00:00
|
|
|
first line of code
|
|
|
|
|
2021-07-10 17:13:17 +00:00
|
|
|
second line of code</code></pre>
|
2021-07-10 13:29:16 +00:00
|
|
|
EOF
|
|
|
|
|
|
|
|
check <<-"EOF"
|
|
|
|
```
|
|
|
|
first line of code
|
|
|
|
|
|
|
|
second line of code
|
|
|
|
---
|
|
|
|
<p>``` first line of code second line of code</p>
|
|
|
|
EOF
|
|
|
|
|
2021-07-10 22:34:39 +00:00
|
|
|
check <<-"EOF"
|
|
|
|
code
|
|
|
|
indented by
|
|
|
|
spaces
|
|
|
|
---
|
|
|
|
<pre><code>code
|
|
|
|
indented by
|
|
|
|
spaces</code></pre>
|
|
|
|
EOF
|
|
|
|
|
2021-07-10 13:29:16 +00:00
|
|
|
check <<-"EOF"
|
|
|
|
asdf
|
|
|
|
|
|
|
|
* foo
|
|
|
|
* bar
|
|
|
|
---
|
|
|
|
<p>asdf</p>
|
|
|
|
<ul>
|
|
|
|
<li>foo</li>
|
|
|
|
<li>bar</li>
|
|
|
|
</ul>
|
|
|
|
EOF
|
|
|
|
|
|
|
|
check <<-"EOF"
|
|
|
|
asdf
|
|
|
|
|
2021-07-10 17:33:33 +00:00
|
|
|
* bullet 1
|
|
|
|
* bullet
|
|
|
|
2
|
2021-07-10 13:29:16 +00:00
|
|
|
---
|
|
|
|
<p>asdf</p>
|
|
|
|
<ul>
|
2021-07-10 17:33:33 +00:00
|
|
|
<li>bullet 1</li>
|
|
|
|
<li>bullet 2</li>
|
|
|
|
</ul>
|
|
|
|
EOF
|
|
|
|
|
|
|
|
check <<-"EOF"
|
|
|
|
asdf
|
|
|
|
|
|
|
|
1. number 1
|
|
|
|
2. number
|
|
|
|
2
|
|
|
|
---
|
|
|
|
<p>asdf</p>
|
|
|
|
<ol>
|
|
|
|
<li>number 1</li>
|
|
|
|
<li>number 2</li>
|
|
|
|
</ol>
|
|
|
|
EOF
|
|
|
|
|
|
|
|
check <<-"EOF"
|
|
|
|
* **basic formatting**
|
|
|
|
* ```in list```
|
|
|
|
---
|
|
|
|
<ul>
|
|
|
|
<li><strong>basic formatting</strong></li>
|
|
|
|
<li><code>in list</code></li>
|
2021-07-10 13:29:16 +00:00
|
|
|
</ul>
|
|
|
|
EOF
|
2021-07-10 17:13:17 +00:00
|
|
|
|
|
|
|
check <<-"EOF"
|
|
|
|
* first
|
|
|
|
level 1
|
|
|
|
* second
|
|
|
|
level 1
|
|
|
|
* second level 2
|
|
|
|
* third level
|
|
|
|
* first level
|
|
|
|
2
|
|
|
|
---
|
|
|
|
<ul>
|
|
|
|
<li>first level 1
|
|
|
|
<ul>
|
|
|
|
<li>second level 1</li>
|
|
|
|
<li>second level 2
|
|
|
|
<ul>
|
|
|
|
<li>third level</li>
|
|
|
|
</ul></li>
|
|
|
|
</ul></li>
|
|
|
|
<li>first level 2</li>
|
|
|
|
</ul>
|
|
|
|
EOF
|
|
|
|
|
2021-07-10 17:33:33 +00:00
|
|
|
check <<-"EOF"
|
|
|
|
* bullet1
|
|
|
|
1. number1
|
|
|
|
* bullet2
|
|
|
|
2. number2
|
|
|
|
---
|
|
|
|
<ul>
|
|
|
|
<li>bullet1</li>
|
|
|
|
</ul>
|
|
|
|
<ol>
|
|
|
|
<li>number1</li>
|
|
|
|
</ol>
|
|
|
|
<ul>
|
|
|
|
<li>bullet2</li>
|
|
|
|
</ul>
|
|
|
|
<ol>
|
|
|
|
<li>number2</li>
|
|
|
|
</ol>
|
|
|
|
EOF
|
|
|
|
|
2021-07-10 20:04:14 +00:00
|
|
|
check <<-"EOF"
|
|
|
|
> foo
|
|
|
|
> bar
|
|
|
|
---
|
|
|
|
<blockquote>
|
|
|
|
<p>foo bar</p>
|
|
|
|
</blockquote>
|
|
|
|
EOF
|
|
|
|
|
|
|
|
check <<-"EOF"
|
|
|
|
> foo
|
|
|
|
>
|
|
|
|
> > bar
|
|
|
|
> > baz
|
|
|
|
---
|
|
|
|
<blockquote>
|
|
|
|
<p>foo</p>
|
|
|
|
<blockquote>
|
|
|
|
<p>bar baz</p>
|
|
|
|
</blockquote>
|
|
|
|
</blockquote>
|
|
|
|
EOF
|
|
|
|
|
2021-07-25 15:57:32 +00:00
|
|
|
check <<-"EOF"
|
|
|
|
> foo
|
|
|
|
>
|
|
|
|
>> bar
|
|
|
|
>> baz
|
|
|
|
---
|
|
|
|
<blockquote>
|
|
|
|
<p>foo</p>
|
|
|
|
<blockquote>
|
|
|
|
<p>bar baz</p>
|
|
|
|
</blockquote>
|
|
|
|
</blockquote>
|
|
|
|
EOF
|
|
|
|
|
2021-07-10 22:50:54 +00:00
|
|
|
check <<-"EOF"
|
|
|
|
> code blocks
|
|
|
|
> in blockquotes
|
|
|
|
---
|
|
|
|
<blockquote>
|
|
|
|
<pre><code>code blocks
|
|
|
|
in blockquotes</code></pre>
|
|
|
|
</blockquote>
|
|
|
|
EOF
|
|
|
|
|
2021-07-25 15:57:32 +00:00
|
|
|
check <<-"EOF"
|
|
|
|
foo&bar
|
|
|
|
|
|
|
|
1 < 2
|
|
|
|
|
|
|
|
2 > 1
|
|
|
|
---
|
|
|
|
<p>foo&bar</p>
|
|
|
|
<p>1 < 2</p>
|
|
|
|
<p>2 > 1</p>
|
|
|
|
EOF
|
|
|
|
|
2021-07-25 16:48:52 +00:00
|
|
|
check <<-"EOF"
|
|
|
|
foo <a href="" ></a> bar
|
|
|
|
---
|
|
|
|
<p>foo <a href="" ></a> bar</p>
|
|
|
|
EOF
|
|
|
|
|
2021-07-10 13:29:16 +00:00
|
|
|
echo
|
|
|
|
echo "All tests passed"
|