diff options
| author | Akshay Nair <phenax5@gmail.com> | 2024-12-25 22:49:41 +0530 |
|---|---|---|
| committer | Akshay Nair <phenax5@gmail.com> | 2024-12-25 23:48:32 +0530 |
| commit | d9b2256047669b5a5dbac4baec7140f18a5b6eff (patch) | |
| tree | b904df2f8b7c41481a2e8f30659474c97e998444 /specs/Specs/AppEventSpec.hs | |
| parent | 83e2570d3c8da9920d66a00c4bdf5650fe1b3336 (diff) | |
| download | chelleport-d9b2256047669b5a5dbac4baec7140f18a5b6eff.tar.gz chelleport-d9b2256047669b5a5dbac4baec7140f18a5b6eff.zip | |
Refactor state update + test fixes
Diffstat (limited to '')
| -rw-r--r-- | specs/Specs/AppEventSpec.hs | 38 |
1 files changed, 17 insertions, 21 deletions
diff --git a/specs/Specs/AppEventSpec.hs b/specs/Specs/AppEventSpec.hs index db292a7..e643958 100644 --- a/specs/Specs/AppEventSpec.hs +++ b/specs/Specs/AppEventSpec.hs @@ -9,7 +9,7 @@ import Unsafe.Coerce (unsafeCoerce) test :: SpecWith () test = do - describe "#eventHandler" $ do + describe "#eventHandler currentState" $ do let mkEvent payload = SDL.Event {SDL.eventTimestamp = 0, SDL.eventPayload = payload} let mkKeyboardEvent key motion modifier = mkEvent $ @@ -26,78 +26,74 @@ test = do SDL.keyboardEventKeyMotion = motion } let defaultMod = fromNumber 0 + let currentState = defaultAppState context "when window quit event is triggered" $ do it "shuts down app" $ do - let action = eventHandler $ mkEvent SDL.QuitEvent + let action = eventHandler currentState $ mkEvent SDL.QuitEvent action `shouldBe` Just ShutdownApp context "when escape key is pressed" $ do it "shuts down app" $ do - let action = eventHandler $ mkKeyboardEvent SDL.KeycodeEscape SDL.Pressed defaultMod + let action = eventHandler currentState $ mkKeyboardEvent SDL.KeycodeEscape SDL.Pressed defaultMod action `shouldBe` Just ShutdownApp context "when ctrl+v is pressed" $ do it "toggles dragging" $ do - let action = eventHandler $ mkKeyboardEvent SDL.KeycodeV SDL.Pressed (defaultMod {SDL.keyModifierLeftCtrl = True}) + let action = eventHandler currentState $ mkKeyboardEvent SDL.KeycodeV SDL.Pressed (defaultMod {SDL.keyModifierLeftCtrl = True}) action `shouldBe` Just MouseDragToggle context "when space key is pressed" $ do it "triggers left mouse button click" $ do - let action = eventHandler $ mkKeyboardEvent SDL.KeycodeSpace SDL.Pressed defaultMod + let action = eventHandler currentState $ mkKeyboardEvent SDL.KeycodeSpace SDL.Pressed defaultMod action `shouldBe` Just (TriggerMouseClick LeftClick) context "when pressed with right shift" $ do it "chains left mouse button click" $ do - let action = eventHandler $ mkKeyboardEvent SDL.KeycodeSpace SDL.Pressed (defaultMod {SDL.keyModifierRightShift = True}) + let action = eventHandler currentState $ mkKeyboardEvent SDL.KeycodeSpace SDL.Pressed (defaultMod {SDL.keyModifierRightShift = True}) action `shouldBe` Just (ChainMouseClick LeftClick) context "when pressed with left shift" $ do it "chains left mouse button click" $ do - let action = eventHandler $ mkKeyboardEvent SDL.KeycodeSpace SDL.Pressed (defaultMod {SDL.keyModifierLeftShift = True}) + let action = eventHandler currentState $ mkKeyboardEvent SDL.KeycodeSpace SDL.Pressed (defaultMod {SDL.keyModifierLeftShift = True}) action `shouldBe` Just (ChainMouseClick LeftClick) context "when minus key is pressed" $ do it "triggers left mouse button click" $ do - let action = eventHandler $ mkKeyboardEvent SDL.KeycodeMinus SDL.Pressed defaultMod + let action = eventHandler currentState $ mkKeyboardEvent SDL.KeycodeMinus SDL.Pressed defaultMod action `shouldBe` Just (TriggerMouseClick RightClick) context "when pressed with right shift" $ do it "chains right mouse button click" $ do - let action = eventHandler $ mkKeyboardEvent SDL.KeycodeMinus SDL.Pressed (defaultMod {SDL.keyModifierRightShift = True}) + let action = eventHandler currentState $ mkKeyboardEvent SDL.KeycodeMinus SDL.Pressed (defaultMod {SDL.keyModifierRightShift = True}) action `shouldBe` Just (ChainMouseClick RightClick) context "when pressed with left shift" $ do it "chains right mouse button click" $ do - let action = eventHandler $ mkKeyboardEvent SDL.KeycodeMinus SDL.Pressed (defaultMod {SDL.keyModifierLeftShift = True}) + let action = eventHandler currentState $ mkKeyboardEvent SDL.KeycodeMinus SDL.Pressed (defaultMod {SDL.keyModifierLeftShift = True}) action `shouldBe` Just (ChainMouseClick RightClick) - context "when tab key is pressed" $ do - it "resets key state" $ do - let action = eventHandler $ mkKeyboardEvent SDL.KeycodeTab SDL.Pressed defaultMod - action `shouldBe` Just ResetKeys - context "when backspace key is pressed" $ do it "resets key state" $ do - let action = eventHandler $ mkKeyboardEvent SDL.KeycodeBackspace SDL.Pressed defaultMod + let action = eventHandler currentState $ mkKeyboardEvent SDL.KeycodeBackspace SDL.Pressed defaultMod action `shouldBe` Just ResetKeys context "when an alphanumeric key (excluding Q) is pressed" $ do it "calls key input handler" $ do - eventHandler (mkKeyboardEvent SDL.KeycodeA SDL.Pressed defaultMod) `shouldBe` Just (HandleKeyInput SDL.KeycodeA) - eventHandler (mkKeyboardEvent SDL.KeycodeQ SDL.Pressed defaultMod) `shouldBe` Just (HandleKeyInput SDL.KeycodeQ) + eventHandler currentState (mkKeyboardEvent SDL.KeycodeA SDL.Pressed defaultMod) `shouldBe` Just (HandleKeyInput SDL.KeycodeA) + eventHandler currentState (mkKeyboardEvent SDL.KeycodeQ SDL.Pressed defaultMod) `shouldBe` Just (HandleKeyInput SDL.KeycodeQ) context "when shift key is pressed" $ do it "enables shift" $ do - let action = eventHandler $ mkKeyboardEvent SDL.KeycodeRShift SDL.Pressed defaultMod + let action = eventHandler currentState $ mkKeyboardEvent SDL.KeycodeRShift SDL.Pressed defaultMod action `shouldBe` Just (UpdateShiftState True) context "when shift key is released" $ do it "disabled shift" $ do - let action = eventHandler $ mkKeyboardEvent SDL.KeycodeRShift SDL.Released defaultMod + let action = eventHandler currentState $ mkKeyboardEvent SDL.KeycodeRShift SDL.Released defaultMod action `shouldBe` Just (UpdateShiftState False) context "when digit is pressed" $ do it "sets repetition count" $ do - let action = eventHandler $ mkKeyboardEvent SDL.Keycode9 SDL.Pressed defaultMod + let action = eventHandler currentState $ mkKeyboardEvent SDL.Keycode9 SDL.Pressed defaultMod action `shouldBe` Just (UpdateRepetition 9) |
