diff --git a/src/Mtlstats/Actions.hs b/src/Mtlstats/Actions.hs index d66f312..106791f 100644 --- a/src/Mtlstats/Actions.hs +++ b/src/Mtlstats/Actions.hs @@ -19,6 +19,8 @@ along with this program. If not, see . -} +{-# LANGUAGE LambdaCase #-} + module Mtlstats.Actions ( startNewSeason , resetYtd @@ -49,8 +51,10 @@ startNewGame -- | Adds a character to the input buffer addChar :: Char -> ProgState -> ProgState -addChar = undefined +addChar c = inputBuffer %~ (++[c]) -- | Removes a character from the input buffer (if possible) removeChar :: ProgState -> ProgState -removeChar = undefined +removeChar = inputBuffer %~ \case + "" -> "" + str -> init str diff --git a/test/ActionsSpec.hs b/test/ActionsSpec.hs index c046718..f1d513e 100644 --- a/test/ActionsSpec.hs +++ b/test/ActionsSpec.hs @@ -34,6 +34,8 @@ spec = describe "Mtlstats.Actions" $ do startNewSeasonSpec startNewGameSpec resetYtdSpec + addCharSpec + removeCharSpec startNewSeasonSpec :: Spec startNewSeasonSpec = describe "startNewSeason" $ do @@ -101,6 +103,29 @@ resetYtdSpec = describe "resetYtd" $ lt ^. gsTies `shouldNotBe` 0) $ s ^. database . dbGoalies +addCharSpec :: Spec +addCharSpec = describe "addChar" $ + it "should add the character to the input buffer" $ let + s = newProgState + & inputBuffer .~ "foo" + & addChar 'd' + in s ^. inputBuffer `shouldBe` "food" + +removeCharSpec :: Spec +removeCharSpec = describe "removeChar" $ do + + context "empty" $ + it "should remove the character from the input buffer" $ let + s = removeChar newProgState + in s ^. inputBuffer `shouldBe` "" + + context "not empty" $ + it "should remove the character from the input buffer" $ let + s = newProgState + & inputBuffer .~ "foo" + & removeChar + in s ^. inputBuffer `shouldBe` "fo" + makePlayer :: IO Player makePlayer = Player <$> makeNum