{-# LANGUAGE QuasiQuotes #-}
module Main where
import qualified Track
import Text.RawString.QQ(r)
import Test.HUnit
import qualified System.Exit as Exit
import Control.Exception
import Debug.Trace (trace, traceShow)
import qualified Data.Time
preamble = [r|
|]
wrap x = preamble ++ x ++ ""
onepoint = wrap [r|
|]
onepointWithAttrs = wrap [r|
25.2
2.4
128
55
3.21610.675
32.025
|]
test1 = TestCase $
case Track.parse (wrap "") of
Left err -> assertFailure (displayException err)
Right t -> assertEqual "empty track has no elements"
0 (Track.length t)
testMalformed = TestCase $
case Track.parse (wrap ">") 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 attributes"
(Nothing, Nothing) (Track.elevation p, Track.cadence p)
Right [] -> assertFailure "no points"
test4 = TestCase $
case Track.parse onepointWithAttrs
of
Left err -> assertFailure (displayException err)
Right (p:ps) ->
assertEqual "matches attributes"
(Just 25.2, Just 128, Just 55, Data.Time.UTCTime (toEnum 60606) 27299.779)
(Track.elevation p, Track.cadence p, Track.power p, Track.time 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