Added more tests; fixed some existing tests by adding convenience functions

master
Aadhavan Srinivasan 6 days ago
parent 2b771256a1
commit 26adcbbc69

@ -3,29 +3,41 @@ module MdToHtmlTest where
import MdToHTML import MdToHTML
import Test.HUnit import Test.HUnit
check_equal expected actual check_equal :: String -> String -> String -> Test
check_equal desc expected actual = TestCase (assertEqual desc expected actual)
convert :: String -> String
convert md = show . fst $ leftmostLongestParse parseDocument md
headerTests = TestList headerTests = TestList
[ [
(TestCase (assertEqual "Should convert H1 heading" "<h1>Hello</h1>" (show . fst $ leftmostLongestParse parseLine "# Hello"))), check_equal "Should convert H1 heading" "<h1>Hello</h1>" (convert "# Hello"),
(TestCase (assertEqual "Should convert H2 heading" "<h2>Hello</h2>" (show . fst $ leftmostLongestParse parseLine "## Hello"))), check_equal "Should convert H2 heading" "<h2>Hello</h2>" (convert "## Hello"),
(TestCase (assertEqual "Should convert H3 heading" "<h3>Hello</h3>" (show . fst $ leftmostLongestParse parseLine "### Hello"))), check_equal "Should convert H3 heading" "<h3>Hello</h3>" (convert "### Hello"),
(TestCase (assertEqual "Should convert H4 heading" "<h4>Hello</h4>" (show . fst $ leftmostLongestParse parseLine "#### Hello"))), check_equal "Should convert H4 heading" "<h4>Hello</h4>" (convert "#### Hello"),
(TestCase (assertEqual "Should convert H5 heading" "<h5>Hello</h5>" (show . fst $ leftmostLongestParse parseLine "##### Hello"))), check_equal "Should convert H5 heading" "<h5>Hello</h5>" (convert "##### Hello"),
(TestCase (assertEqual "Should convert H6 heading" "<h6>Hello</h6>" (show . fst $ leftmostLongestParse parseLine "###### Hello"))) check_equal "Should convert H6 heading" "<h6>Hello</h6>" (convert "###### Hello")
] ]
boldTests = TestList boldTests = TestList
[ [
(TestCase (assertEqual "Should convert bold" "<b>Hello</b>" (show . fst $ leftmostLongestParse parseLine "__Hello__"))), check_equal "Should convert bold" "<p><b>Hello</b></p>" (convert "__Hello__"),
(TestCase (assertEqual "Should convert italic" "<i>Hello</i>" (show . fst $ leftmostLongestParse parseLine "_Hello_"))), check_equal "Should convert italic" "<p><i>Hello</i></p>" (convert "_Hello_"),
(TestCase (assertEqual "Should convert bold and italic in a sentence" "It <i>is</i> a <b>wonderful</b> day" (show . fst $ leftmostLongestParse parseLine "It _is_ a __wonderful__ day"))) check_equal "Should convert bold and italic in a sentence" "<p>It <i>is</i> a <b>wonderful</b> day</p>" (convert "It _is_ a __wonderful__ day")
] ]
integrationTests = TestList
[
check_equal "Integration 1" "<h1>Sample Markdown</h1><p>This is some basic, sample markdown.</p><h2><b>Second</b> <i>Heading</i></h2>" (convert "# Sample Markdown\n\n This is some basic, sample markdown.\n\n ## __Second__ _Heading_")
-- Add a test for single-newlines.
]
tests = TestList tests = TestList
[ [
headerTests, headerTests,
boldTests boldTests,
integrationTests
] ]
runTests = runTestTT tests runTests = runTestTT tests

Loading…
Cancel
Save