shorten tests using Either operations
This commit is contained in:
parent
dd49bc50fa
commit
36eeea6bef
@ -10,6 +10,7 @@ import qualified System.Exit as Exit
|
|||||||
import Control.Exception
|
import Control.Exception
|
||||||
import Debug.Trace (trace, traceShow)
|
import Debug.Trace (trace, traceShow)
|
||||||
import qualified Data.Time
|
import qualified Data.Time
|
||||||
|
import Data.Either
|
||||||
|
|
||||||
preamble = [r|
|
preamble = [r|
|
||||||
<?xml version="1.0" encoding="UTF-8"?>
|
<?xml version="1.0" encoding="UTF-8"?>
|
||||||
@ -55,25 +56,26 @@ onepointWithAttrs = wrap [r|
|
|||||||
|]
|
|]
|
||||||
|
|
||||||
test1 = TestCase $
|
test1 = TestCase $
|
||||||
case Track.parse (wrap "") of
|
either
|
||||||
Left err -> assertFailure (displayException err)
|
(assertFailure . displayException)
|
||||||
Right t -> assertEqual "empty track has no elements"
|
(\ t -> assertEqual "empty track has no elements"
|
||||||
0 (Track.length t)
|
0 (Track.length t))
|
||||||
|
(Track.parse (wrap ""))
|
||||||
|
|
||||||
testMalformed = TestCase $
|
testMalformed = TestCase $
|
||||||
case Track.parse (wrap "<dgdsfg>>") of
|
let trk = Track.parse (wrap "<dgdsfg>>")
|
||||||
Left err -> assertBool "syntax error" True
|
in assertBool "catches syntax error" (isLeft trk)
|
||||||
Right _ -> assertFailure "no error message parsing bad xml"
|
|
||||||
|
|
||||||
test2 = TestCase $
|
test2 = TestCase $
|
||||||
case Track.parse onepoint
|
either
|
||||||
of
|
(assertFailure . displayException)
|
||||||
Left err -> assertFailure (displayException err)
|
(\ trk -> case trk of
|
||||||
Right (p:ps) ->
|
p:_ ->
|
||||||
assertEqual "matches lat/lon"
|
assertEqual "matches lat/lon"
|
||||||
(Track.Pos 51.0 (-0.1))
|
(Track.Pos 51.0 (-0.1))
|
||||||
(Track.pos p)
|
(Track.pos p)
|
||||||
Right [] -> assertFailure "no points"
|
[] -> assertFailure "no points")
|
||||||
|
(Track.parse onepoint)
|
||||||
|
|
||||||
test3 = TestCase $
|
test3 = TestCase $
|
||||||
case Track.parse onepoint
|
case Track.parse onepoint
|
||||||
|
Loading…
Reference in New Issue
Block a user