Something went wrong. Try again.
Making a new TUI editor maybe
Something went wrong. Try again.
12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849module GlyphTest.Key.Count where
----------------------------------------------------------------------------------------------------
import qualified Data.List as List
import Glyph.Key.Count ( Count (..) , canCount , pushDigit , settle )
import Graphics.Vty.Input.Events ( Key (..) )
import Test.Hspec ( Spec, describe, it, shouldBe )
----------------------------------------------------------------------------------------------------
test :: Spectest = describe "Glyph.Key.Count" <| do describe "canCount" <| do it "starts a count on a non-zero digit at rest" <| fmap (canCount NoCount []) [KChar '1', KChar '9', KChar '0'] `shouldBe` ([True, True, True] :: List Bool)
it "ignores non-digits in either state" <| fmap (canCount (Reading ['3']) []) [KChar 'j', KChar ' '] `shouldBe` ([False, False] :: List Bool)
describe "pushDigit" <| do it "opens a count when none is being read" <| pushDigit (KChar '4') NoCount `shouldBe` Reading ['4']
it "appends newest-last so digits read in typing order" <| List.foldl' (flip pushDigit) NoCount ([KChar '1', KChar '2', KChar '7'] :: List Key) `shouldBe` Reading ['1', '2', '7']
describe "settle" <| do it "treats an absent count as one" <| settle NoCount `shouldBe` 1
it "folds collected digits into their number" <| settle (Reading ['1', '2', '7']) `shouldBe` 127
it "passes a settled count through" <| settle (Counted 12) `shouldBe` 12