module Main where import qualified Track import Test.HUnit import qualified System.Exit as Exit import Control.Exception import Debug.Trace (trace, traceShow) onepoint = " \n\ \ \n\ \ " onepointEle = " \n\ \ \n\ \ 25.2\n\ \ \n\ \ " test1 :: Test test1 = TestCase $ case Track.parse "" of Left err -> assertFailure (displayException err) Right t -> assertEqual "empty track has no elements" 0 (Track.length t) testMalformed :: Test testMalformed = TestCase $ case Track.parse ">" of Left err -> assertBool "syntax error" True Right t -> assertFailure "no error message parsing bad xml" test2 = TestCase $ case Track.parse onepoint of Left err -> assertFailure (displayException err) Right (p:ps) -> assertEqual "matches lat/lon" (Track.Pos 51.0 (-0.1)) (Track.pos p) test3 = TestCase $ case Track.parse onepoint of Left err -> assertFailure (displayException err) Right (p:ps) -> assertEqual "matches elevation" Nothing (Track.elevation p) test4 = TestCase $ case Track.parse onepointEle of Left err -> assertFailure (displayException err) Right (p:ps) -> assertEqual "matches elevation" (Just 25.2) (Track.elevation p) tests :: Test tests = TestList [ TestLabel "test1" test1, testMalformed, TestLabel "test2" test2, TestLabel "test3" test3, TestLabel "test4" test4 ] main :: IO () main = do result <- runTestTT tests if failures result > 0 then Exit.exitFailure else Exit.exitSuccess