souplesse/tests/UnitTest.hs
Daniel Barlow a65c7fb8a9 remove TestLabels
they were only there because we cargo-culted them
2024-10-29 21:47:36 +00:00

69 lines
1.8 KiB
Haskell

module Main where
import qualified Track
import Test.HUnit
import qualified System.Exit as Exit
import Control.Exception
import Debug.Trace (trace, traceShow)
onepoint =
"<gpx> <trk> <trkseg> \n\
\<trkpt lat=\"51\" lon=\"-0.1\"> </trkpt> \n\
\</trkseg> </trk> </gpx>"
onepointEle =
"<gpx> <trk> <trkseg> \n\
\<trkpt lat=\"51\" lon=\"-0.1\"> \n\
\ <ele>25.2</ele>\n\
\</trkpt> \n\
\</trkseg> </trk> </gpx>"
test1 = TestCase $
case Track.parse "<gpx></gpx>" of
Left err -> assertFailure (displayException err)
Right t -> assertEqual "empty track has no elements"
0 (Track.length t)
testMalformed = TestCase $
case Track.parse "<gpx><dgdsfg>></gpx>" 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 [
test1,
testMalformed,
test2,
test3,
test4
]
main :: IO ()
main = do
result <- runTestTT tests
if failures result > 0 then Exit.exitFailure else Exit.exitSuccess