From 154c3979a55bf0720166da4d4a5a9853304acece Mon Sep 17 00:00:00 2001 From: Jonathan Lamothe Date: Mon, 9 Sep 2019 11:43:37 -0400 Subject: [PATCH] implemented createPlayerStateL --- src/Mtlstats/Types.hs | 8 ++++++++ test/TypesSpec.hs | 18 ++++++++++++++++++ 2 files changed, 26 insertions(+) diff --git a/src/Mtlstats/Types.hs b/src/Mtlstats/Types.hs index b5a0324..645a11e 100644 --- a/src/Mtlstats/Types.hs +++ b/src/Mtlstats/Types.hs @@ -44,6 +44,7 @@ module Mtlstats.Types ( inputBuffer, -- ** ProgMode Lenses gameStateL, + createPlayerStateL, -- ** GameState Lenses gameYear, gameMonth, @@ -443,6 +444,13 @@ gameStateL = lens _ -> newGameState) (\_ gs -> NewGame gs) +createPlayerStateL :: Lens' ProgMode CreatePlayerState +createPlayerStateL = lens + (\case + CreatePlayer cps -> cps + _ -> newCreatePlayerState) + (\_ cps -> CreatePlayer cps) + -- | Constructor for a 'ProgState' newProgState :: ProgState newProgState = ProgState diff --git a/test/TypesSpec.hs b/test/TypesSpec.hs index 724a28a..68a15d2 100644 --- a/test/TypesSpec.hs +++ b/test/TypesSpec.hs @@ -42,6 +42,7 @@ spec = describe "Mtlstats.Types" $ do gameStatsSpec databaseSpec gameStateLSpec + createPlayerStateLSpec teamScoreSpec otherScoreSpec homeTeamSpec @@ -81,6 +82,23 @@ gameStateLSpec = describe "gameStateL" $ lensSpec gameStateL ] where gs t = newGameState & gameType ?~ t +createPlayerStateLSpec :: Spec +createPlayerStateLSpec = describe "createPlayerStateL" $ + lensSpec createPlayerStateL + -- getters + [ ( MainMenu, newCreatePlayerState ) + , ( CreatePlayer $ cps 1 , cps 1 ) + ] + -- setters + [ ( MainMenu, cps 1 ) + , ( CreatePlayer $ cps 1, cps 2 ) + ] + where + cps n = newCreatePlayerState + & cpsNumber ?~ n + & cpsName .~ "foo" + & cpsPosition .~ "bar" + teamScoreSpec :: Spec teamScoreSpec = describe "teamScore" $ do let