diff --git a/src/Mtlstats/Helpers/Goalie.hs b/src/Mtlstats/Helpers/Goalie.hs index 38a777c..fb5818d 100644 --- a/src/Mtlstats/Helpers/Goalie.hs +++ b/src/Mtlstats/Helpers/Goalie.hs @@ -19,7 +19,7 @@ along with this program. If not, see . -} -module Mtlstats.Helpers.Goalie (goalieDetails) where +module Mtlstats.Helpers.Goalie (goalieDetails, goalieName) where import Lens.Micro ((^.)) @@ -46,3 +46,13 @@ goalieDetails g = let ] in header ++ "\n" ++ body + +-- | Returns the goalie name, modified if they are a rookie +goalieName :: Goalie -> String +goalieName g = let + + suffix = if g^.gRookie + then "*" + else "" + + in g^.gName ++ suffix diff --git a/test/Helpers/GoalieSpec.hs b/test/Helpers/GoalieSpec.hs index 2c8ca25..5c784f1 100644 --- a/test/Helpers/GoalieSpec.hs +++ b/test/Helpers/GoalieSpec.hs @@ -22,14 +22,15 @@ along with this program. If not, see . module Helpers.GoalieSpec (spec) where import Lens.Micro ((&), (.~), (%~)) -import Test.Hspec (Spec, describe, it, shouldBe) +import Test.Hspec (Spec, context, describe, it, shouldBe) import Mtlstats.Helpers.Goalie import Mtlstats.Types spec :: Spec -spec = describe "Goalie" +spec = describe "Goalie" $ do goalieDetailsSpec + goalieNameSpec goalieDetailsSpec :: Spec goalieDetailsSpec = describe "goalieDetails" $ let @@ -67,3 +68,17 @@ goalieDetailsSpec = describe "goalieDetails" $ let in it "should format the output correctly" $ goalieDetails input `shouldBe` expected + +goalieNameSpec :: Spec +goalieNameSpec = describe "goalieName" $ mapM_ + (\(label, g, expected) -> context label $ + it ("should be " ++ expected) $ + goalieName g `shouldBe` expected) + + -- label, goalie, expected + [ ( "rookie", goalie True, "foo*" ) + , ( "non-rookie", goalie False, "foo" ) + ] + + where + goalie r = newGoalie 1 "foo" & gRookie .~ r