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 = TestCase $ case Track.parse "" of Left err -> assertFailure (displayException err) Right t -> assertEqual "empty track has no elements" 0 (Track.length t) testMalformed = TestCase $ case Track.parse ">" of Left err -> assertBool "syntax error" True Right _ -> 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) Right [] -> assertFailure "no points" test3 = TestCase $ case Track.parse onepoint of Left err -> assertFailure (displayException err) Right (p:ps) -> assertEqual "matches elevation" Nothing (Track.elevation p) Right [] -> assertFailure "no points" test4 = TestCase $ case Track.parse onepointEle of Left err -> assertFailure (displayException err) Right (p:ps) -> assertEqual "matches elevation" (Just 25.2) (Track.elevation p) Right [] -> assertFailure "no points" tests :: Test tests = TestList [ test1, testMalformed, test2, test3, test4 ] main :: IO () main = do result <- runTestTT tests if failures result > 0 then Exit.exitFailure else Exit.exitSuccess