diff --git a/src/Mtlstats/Report.hs b/src/Mtlstats/Report.hs
index cf93da5..0121141 100644
--- a/src/Mtlstats/Report.hs
+++ b/src/Mtlstats/Report.hs
@@ -19,7 +19,7 @@ along with this program. If not, see .
-}
-module Mtlstats.Report (report) where
+module Mtlstats.Report (report, date) where
import Data.Maybe (fromMaybe)
import Lens.Micro ((^.))
@@ -40,6 +40,7 @@ report width s = unlines $ fromMaybe [] $ do
db = s^.database
gs = s^.progMode.gameStateL
gNum = db^.dbGames
+ gDate = date gs
hTeam = homeTeam gs
aTeam = awayTeam gs
hStats = db^.dbHomeGameStats
@@ -47,17 +48,13 @@ report width s = unlines $ fromMaybe [] $ do
tStats = addGameStats hStats aStats
hScore <- gs^.homeScore
aScore <- gs^.awayScore
- month <- month <$> gs^.gameMonth
- day <- padNum 2 <$> gs^.gameDay
- year <- show <$> gs^.gameYear
- let date = month ++ " " ++ day ++ " " ++ year
Just
[ overlay
("GAME NUMBER " ++ padNum 2 gNum)
(centre width
$ aTeam ++ " " ++ show aScore ++ " AT "
++ hTeam ++ " " ++ show hScore)
- , date
+ , gDate
, centre width "STANDINGS"
, ""
, centre width
@@ -81,6 +78,13 @@ report width s = unlines $ fromMaybe [] $ do
++ showStats tStats
]
+date :: GameState -> String
+date gs = fromMaybe "" $ do
+ year <- show <$> gs^.gameYear
+ month <- month <$> gs^.gameMonth
+ day <- padNum 2 <$> gs^.gameDay
+ Just $ month ++ " " ++ day ++ " " ++ year
+
showStats :: GameStats -> String
showStats gs
= right 2 (show $ gmsGames gs)
diff --git a/test/ReportSpec.hs b/test/ReportSpec.hs
new file mode 100644
index 0000000..c33dad5
--- /dev/null
+++ b/test/ReportSpec.hs
@@ -0,0 +1,47 @@
+{-
+
+mtlstats
+Copyright (C) 2019 Rhéal Lamothe
+
+
+This program is free software: you can redistribute it and/or modify
+it under the terms of the GNU General Public License as published by
+the Free Software Foundation, either version 3 of the License, or (at
+your option) any later version.
+
+This program is distributed in the hope that it will be useful, but
+WITHOUT ANY WARRANTY; without even the implied warranty of
+MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+General Public License for more details.
+
+You should have received a copy of the GNU General Public License
+along with this program. If not, see .
+
+-}
+
+module ReportSpec (spec) where
+
+import Lens.Micro ((&), (?~), (%~))
+import Test.Hspec (Spec, context, describe, it, shouldBe)
+
+import Mtlstats.Report
+import Mtlstats.Types
+
+spec :: Spec
+spec = describe "Mtlstats.Report"
+ dateSpec
+
+dateSpec :: Spec
+dateSpec = describe "date" $ do
+
+ context "valid date" $
+ it "should format the date" $ let
+ gs = newGameState
+ & gameYear ?~ 1980
+ & gameMonth ?~ 6
+ & gameDay ?~ 25
+ in date gs `shouldBe` "JUN 25 1980"
+
+ context "invalid date" $
+ it "should return an empty string" $
+ date newGameState `shouldBe` ""
diff --git a/test/Spec.hs b/test/Spec.hs
index 54c9e24..a3db0ba 100644
--- a/test/Spec.hs
+++ b/test/Spec.hs
@@ -24,6 +24,7 @@ import Test.Hspec (hspec)
import qualified ActionsSpec as Actions
import qualified FormatSpec as Format
import qualified HandlersSpec as Handlers
+import qualified ReportSpec as Report
import qualified TypesSpec as Types
main :: IO ()
@@ -32,3 +33,4 @@ main = hspec $ do
Actions.spec
Format.spec
Handlers.spec
+ Report.spec