#!/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 echo $line >> "$expected_output" 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. ---

This is a simple sentence.

EOF check <<-EOF This is a simple sentence. ---

This is a simple sentence.

EOF check <<-EOF First paragraph. Second paragraph. ---

First paragraph.

Second paragraph.

EOF check <<-EOF # Header body ---

Header

body

EOF check <<-EOF # Header1 ## Header2 ### Header3 ---

Header1

Header2

Header3

EOF check <<-EOF **bold** ---

bold

EOF check <<-EOF **bold multiline** ---

bold multiline

EOF check <<-EOF **bold ---

**bold

EOF check <<-"EOF" ``` first line of code second line of code ``` --- first line of code second line of code EOF check <<-"EOF" ``` first line of code second line of code ---

``` first line of code second line of code

EOF check <<-"EOF" asdf * foo * bar ---

asdf

EOF check <<-"EOF" asdf * foo * bar qux ---

asdf

EOF echo echo "All tests passed"