added _otherTeam with its associated lenses
This commit is contained in:
parent
2a2189c7d1
commit
0f9f76ce4e
|
@ -41,10 +41,12 @@ module Mtlstats.Types (
|
|||
inputBuffer,
|
||||
-- ** GameState Lenses
|
||||
gameType,
|
||||
otherTeam,
|
||||
homeScore,
|
||||
awayScore,
|
||||
-- ** ProgMode Lenses
|
||||
gameTypeL,
|
||||
otherTeamL,
|
||||
homeScoreL,
|
||||
awayScoreL,
|
||||
-- ** Database Lenses
|
||||
|
@ -123,6 +125,8 @@ data ProgState = ProgState
|
|||
data GameState = GameState
|
||||
{ _gameType :: Maybe GameType
|
||||
-- ^ The type of game (home/away)
|
||||
, _otherTeam :: String
|
||||
-- ^ The name of the other team
|
||||
, _homeScore :: Maybe Int
|
||||
-- ^ The home team's score
|
||||
, _awayScore :: Maybe Int
|
||||
|
@ -341,6 +345,15 @@ gameTypeL = lens
|
|||
NewGame gs -> NewGame $ gs & gameType .~ gt
|
||||
_ -> NewGame $ newGameState & gameType .~ gt)
|
||||
|
||||
otherTeamL :: Lens' ProgMode String
|
||||
otherTeamL = lens
|
||||
(\case
|
||||
NewGame gs -> gs ^. otherTeam
|
||||
_ -> "")
|
||||
(\m ot -> case m of
|
||||
NewGame gs -> NewGame $ gs & otherTeam .~ ot
|
||||
_ -> NewGame $ newGameState & otherTeam .~ ot)
|
||||
|
||||
homeScoreL :: Lens' ProgMode (Maybe Int)
|
||||
homeScoreL = lens
|
||||
(\case
|
||||
|
@ -371,6 +384,7 @@ newProgState = ProgState
|
|||
newGameState :: GameState
|
||||
newGameState = GameState
|
||||
{ _gameType = Nothing
|
||||
, _otherTeam = ""
|
||||
, _homeScore = Nothing
|
||||
, _awayScore = Nothing
|
||||
}
|
||||
|
|
|
@ -39,6 +39,7 @@ spec = describe "Mtlstats.Types" $ do
|
|||
goalieSpec
|
||||
databaseSpec
|
||||
gameTypeLSpec
|
||||
otherTeamLSpec
|
||||
homeScoreLSpec
|
||||
awayScoreLSpec
|
||||
teamScoreSpec
|
||||
|
@ -130,6 +131,32 @@ gameTypeLSpec = describe "gameTypeL" $ do
|
|||
in m ^. gameTypeL `shouldBe` Just t)
|
||||
[HomeGame, AwayGame]
|
||||
|
||||
otherTeamLSpec :: Spec
|
||||
otherTeamLSpec = describe "otherTeamL" $ do
|
||||
|
||||
context "getter" $ do
|
||||
|
||||
context "unexpected mode" $
|
||||
it "should return an empty string" $
|
||||
MainMenu ^. otherTeamL `shouldBe` ""
|
||||
|
||||
context "expected mode" $
|
||||
it "should return \"foo\"" $ let
|
||||
m = NewGame $ newGameState & otherTeam .~ "foo"
|
||||
in m ^. otherTeamL `shouldBe` "foo"
|
||||
|
||||
context "setter" $ do
|
||||
|
||||
context "unexpected mode" $
|
||||
it "should set the value" $ let
|
||||
m = MainMenu & otherTeamL .~ "foo"
|
||||
in m ^. otherTeamL `shouldBe` "foo"
|
||||
|
||||
context "expected mode" $
|
||||
it "should set the value" $ let
|
||||
m = NewGame newGameState & otherTeamL .~ "foo"
|
||||
in m ^. otherTeamL `shouldBe` "foo"
|
||||
|
||||
homeScoreLSpec :: Spec
|
||||
homeScoreLSpec = describe "homeScoreL" $ do
|
||||
|
||||
|
|
Loading…
Reference in New Issue
Block a user