From d7dd682532272971ae7ca8d9da3e1840ed3d5824 Mon Sep 17 00:00:00 2001 From: Jonathan Lamothe Date: Wed, 28 Aug 2019 01:04:03 -0400 Subject: [PATCH] implemented gameStateL --- src/Mtlstats/Types.hs | 8 ++++++++ test/TypesSpec.hs | 14 ++++++++++++++ 2 files changed, 22 insertions(+) diff --git a/src/Mtlstats/Types.hs b/src/Mtlstats/Types.hs index fad8548..beeee04 100644 --- a/src/Mtlstats/Types.hs +++ b/src/Mtlstats/Types.hs @@ -41,6 +41,7 @@ module Mtlstats.Types ( progMode, inputBuffer, -- ** ProgMode Lenses + gameStateL, gameTypeL, otherTeamL, homeScoreL, @@ -383,6 +384,13 @@ makeLenses ''Goalie makeLenses ''GoalieStats makeLenses ''GameStats +gameStateL :: Lens' ProgMode GameState +gameStateL = lens + (\case + NewGame gs -> gs + _ -> newGameState) + (\_ gs -> NewGame gs) + gameTypeL :: Lens' ProgMode (Maybe GameType) gameTypeL = lens (\case diff --git a/test/TypesSpec.hs b/test/TypesSpec.hs index 598fe32..04cdeca 100644 --- a/test/TypesSpec.hs +++ b/test/TypesSpec.hs @@ -41,6 +41,7 @@ spec = describe "Mtlstats.Types" $ do gameStatsSpec databaseSpec pPointsSpec + gameStateLSpec gameTypeLSpec otherTeamLSpec homeScoreLSpec @@ -80,6 +81,19 @@ pPointsSpec = describe "pPoints" $ mapM_ , ( 2, 3, 5 ) ] +gameStateLSpec :: Spec +gameStateLSpec = describe "gameStateL" $ lensSpec gameStateL + -- getters + [ ( MainMenu, newGameState ) + , ( NewGame $ gs HomeGame, gs HomeGame ) + ] + -- setters + [ ( MainMenu, gs HomeGame ) + , ( NewGame $ gs HomeGame, gs AwayGame ) + , ( NewGame $ gs HomeGame, newGameState ) + ] + where gs t = newGameState & gameType ?~ t + gameTypeLSpec :: Spec gameTypeLSpec = describe "gameTypeL" $ lensSpec gameTypeL [ ( MainMenu, Nothing )