From 79aceaec17b469dc6533470ea6c807f23eb7fe3e Mon Sep 17 00:00:00 2001 From: Griffin Smith Date: Sun, 10 Apr 2022 11:06:53 -0400 Subject: feat(grfn/xanthous): Load keybindings from a data file Change-Id: I62ac54543da5c855c86d39956e611fd44515e9a9 Reviewed-on: https://cl.tvl.fyi/c/depot/+/5443 Autosubmit: grfn Reviewed-by: grfn Tested-by: BuildkiteCI --- users/grfn/xanthous/test/Spec.hs | 4 ++- users/grfn/xanthous/test/Xanthous/CommandSpec.hs | 40 ++++++++++++++++++++++++ 2 files changed, 43 insertions(+), 1 deletion(-) create mode 100644 users/grfn/xanthous/test/Xanthous/CommandSpec.hs (limited to 'users/grfn/xanthous/test') diff --git a/users/grfn/xanthous/test/Spec.hs b/users/grfn/xanthous/test/Spec.hs index 64c10cf21e..51758d6a25 100644 --- a/users/grfn/xanthous/test/Spec.hs +++ b/users/grfn/xanthous/test/Spec.hs @@ -1,6 +1,7 @@ -------------------------------------------------------------------------------- import Test.Prelude -------------------------------------------------------------------------------- +import qualified Xanthous.CommandSpec import qualified Xanthous.Data.EntitiesSpec import qualified Xanthous.Data.EntityCharSpec import qualified Xanthous.Data.EntityMap.GraphicsSpec @@ -32,7 +33,8 @@ main = defaultMainWithRerun test test :: TestTree test = testGroup "Xanthous" - [ Xanthous.Data.EntitiesSpec.test + [ Xanthous.CommandSpec.test + , Xanthous.Data.EntitiesSpec.test , Xanthous.Data.EntityMap.GraphicsSpec.test , Xanthous.Data.EntityMapSpec.test , Xanthous.Data.LevelsSpec.test diff --git a/users/grfn/xanthous/test/Xanthous/CommandSpec.hs b/users/grfn/xanthous/test/Xanthous/CommandSpec.hs new file mode 100644 index 0000000000..13f69a808d --- /dev/null +++ b/users/grfn/xanthous/test/Xanthous/CommandSpec.hs @@ -0,0 +1,40 @@ +-------------------------------------------------------------------------------- +module Xanthous.CommandSpec (main, test) where +-------------------------------------------------------------------------------- +import Test.Prelude +-------------------------------------------------------------------------------- +import Xanthous.Command +-------------------------------------------------------------------------------- +import Data.Aeson (fromJSON, Value(String)) +import qualified Data.Aeson as A +import Graphics.Vty.Input (Key(..), Modifier(..)) +-------------------------------------------------------------------------------- + +main :: IO () +main = defaultMain test + +test :: TestTree +test = testGroup "Xanthous.CommandSpec" + [ testGroup "keybindings" + [ testCase "all are valid" $ keybindings `deepseq` pure () + , testProperty "all non-move commands are bound" $ \cmd -> + let isn'tMove = case cmd of + Move _ -> False + StartAutoMove _ -> False + _ -> True + in isn'tMove ==> member cmd commands + ] + , testGroup "instance FromJSON Keybinding" $ + [ ("q", Keybinding (KChar 'q') []) + , ("", Keybinding KUp []) + , ("", Keybinding KLeft []) + , ("", Keybinding KRight []) + , ("", Keybinding KDown []) + , ("S-q", Keybinding (KChar 'q') [MShift]) + , ("C-S-q", Keybinding (KChar 'q') [MCtrl, MShift]) + , ("m-", Keybinding KUp [MMeta]) + , ("S", Keybinding (KChar 'S') []) + ] <&> \(s, kb) -> + testCase (fromString $ unpack s <> " -> " <> show kb) + $ fromJSON (String s) @?= A.Success kb + ] -- cgit 1.4.1