commit 36eeea6befec4cd5f13cf399f4b25850170747a6 parent dd49bc50fa81e7f166e47641840af73a338e0d35 Author: Daniel Barlow <dan@telent.net> Date: Wed, 30 Oct 2024 20:27:57 +0000 shorten tests using Either operations Diffstat:
| M | tests/UnitTest.hs | | | 26 | ++++++++++++++------------ |
1 file changed, 14 insertions(+), 12 deletions(-)
diff --git 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| <?xml version="1.0" encoding="UTF-8"?> @@ -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 "<dgdsfg>>") of - Left err -> assertBool "syntax error" True - Right _ -> assertFailure "no error message parsing bad xml" + let trk = Track.parse (wrap "<dgdsfg>>") + 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