test cursor location

This commit is contained in:
Jonathan Lamothe 2024-08-01 16:16:22 -04:00
parent 0c74a4ba61
commit f949a65281

View File

@ -21,8 +21,8 @@ License along with this program. If not, see
module Hamming.App.Widgets.InternalSpec (spec) where
import Brick.Types (Location (..))
import Lens.Micro ((&), (.~))
import Test.Hspec (Spec, context, describe, it, shouldBe)
import Hamming.App
@ -35,11 +35,14 @@ spec = describe "Internal"
hammingW'Spec :: Spec
hammingW'Spec = describe "hammingW'" $ mapM_
( \(desc, state, expRes) -> context desc $ do
( \(desc, state, expRes, expLoc) -> context desc $ do
let
(actRes, _) = hammingW' state
(actRes, actLoc) = hammingW' state
numActRows = length actRes
numExpRows = length expRes
context "location" $
it ("should be " ++ show expLoc) $
actLoc `shouldBe` expLoc
context "number of rows" $
it ("should be " ++ show numExpRows) $
numActRows `shouldBe` numExpRows
@ -59,11 +62,14 @@ hammingW'Spec = describe "hammingW'" $ mapM_
) $ zip3 [(0 :: Int)..] actRow expRow
) $ zip3 [(0 :: Int)..] actRes expRes
)
[ ( "all zero", mkState 0, allZero )
, ( "all one", mkState 0xffff, allOne )
, ( "arbitrary", mkState 0x3c5a, arbitrary )
[ ( "all zero", mkState 0, allZero, Nothing )
, ( "all one", mkState 0xffff, allOne, Nothing )
, ( "arbitrary", mkState 0x3c5a, arbitrary, Nothing )
, ( "edit", es, allZero, Just eLoc )
] where
mkState c = initialState & hammingCode .~ c
es = mkState 0 & appMode .~ EditMode initialEditor
eLoc = Location (1, 1)
allZero =
[ [ ( hammingAttr, ' ' )
, ( marginAttr, '0' )