From 36eeea6befec4cd5f13cf399f4b25850170747a6 Mon Sep 17 00:00:00 2001 From: Daniel Barlow Date: Wed, 30 Oct 2024 20:27:57 +0000 Subject: [PATCH] shorten tests using Either operations --- tests/UnitTest.hs | 26 ++++++++++++++------------ 1 file changed, 14 insertions(+), 12 deletions(-) diff --git a/tests/UnitTest.hs b/tests/UnitTest.hs index 740fc90..00414ec 100644 --- a/tests/UnitTest.hs +++ b/tests/UnitTest.hs @@ -10,6 +10,7 @@ import qualified System.Exit as Exit import Control.Exception import Debug.Trace (trace, traceShow) import qualified Data.Time +import Data.Either preamble = [r| @@ -55,25 +56,26 @@ onepointWithAttrs = wrap [r| |] test1 = TestCase $ - case Track.parse (wrap "") of - Left err -> assertFailure (displayException err) - Right t -> assertEqual "empty track has no elements" - 0 (Track.length t) + either + (assertFailure . displayException) + (\ t -> assertEqual "empty track has no elements" + 0 (Track.length t)) + (Track.parse (wrap "")) testMalformed = TestCase $ - case Track.parse (wrap ">") of - Left err -> assertBool "syntax error" True - Right _ -> assertFailure "no error message parsing bad xml" + let trk = Track.parse (wrap ">") + in assertBool "catches syntax error" (isLeft trk) test2 = TestCase $ - case Track.parse onepoint - of - Left err -> assertFailure (displayException err) - Right (p:ps) -> + either + (assertFailure . displayException) + (\ trk -> case trk of + p:_ -> assertEqual "matches lat/lon" (Track.Pos 51.0 (-0.1)) (Track.pos p) - Right [] -> assertFailure "no points" + [] -> assertFailure "no points") + (Track.parse onepoint) test3 = TestCase $ case Track.parse onepoint