From 7437a181888f3e8938a943ae22962f21b1c03b1e Mon Sep 17 00:00:00 2001 From: Griffin Smith Date: Sun, 20 Jun 2021 16:44:12 -0400 Subject: fix(xanthous): Only use alphabetic chars for menu items Previously, we were using `smallestNotIn` for selecting new characters for menu items with duplicate chatacters - this uses the 'Bounded' instance for the type, which for Char meant the first character we would always select was \NUL - making it look like the menu item had no character, and making it impossible to actually select the menu item. This introduces an AlphaChar newtype, which is a wrapper around Char whose Bounded and Enum instances only use alphabetic characters (a-ZA-Z) and uses that for menu characters instead. Change-Id: If34ed9e9ce84f2bcb1cb87432cc6273f40b69f72 Reviewed-on: https://cl.tvl.fyi/c/depot/+/3229 Reviewed-by: grfn Tested-by: BuildkiteCI --- users/grfn/xanthous/test/Spec.hs | 2 ++ users/grfn/xanthous/test/Xanthous/Game/PromptSpec.hs | 19 +++++++++++++++++++ users/grfn/xanthous/test/Xanthous/UtilSpec.hs | 3 +++ 3 files changed, 24 insertions(+) create mode 100644 users/grfn/xanthous/test/Xanthous/Game/PromptSpec.hs (limited to 'users/grfn/xanthous/test') diff --git a/users/grfn/xanthous/test/Spec.hs b/users/grfn/xanthous/test/Spec.hs index 85f49fd07c91..dfecfbdd21c5 100644 --- a/users/grfn/xanthous/test/Spec.hs +++ b/users/grfn/xanthous/test/Spec.hs @@ -13,6 +13,7 @@ import qualified Xanthous.Entities.RawsSpec import qualified Xanthous.Entities.CharacterSpec import qualified Xanthous.GameSpec import qualified Xanthous.Game.StateSpec +import qualified Xanthous.Game.PromptSpec import qualified Xanthous.Generators.Level.UtilSpec import qualified Xanthous.MessageSpec import qualified Xanthous.Messages.TemplateSpec @@ -40,6 +41,7 @@ test = testGroup "Xanthous" , Xanthous.Entities.CharacterSpec.test , Xanthous.GameSpec.test , Xanthous.Game.StateSpec.test + , Xanthous.Game.PromptSpec.test , Xanthous.Generators.Level.UtilSpec.test , Xanthous.MessageSpec.test , Xanthous.Messages.TemplateSpec.test diff --git a/users/grfn/xanthous/test/Xanthous/Game/PromptSpec.hs b/users/grfn/xanthous/test/Xanthous/Game/PromptSpec.hs new file mode 100644 index 000000000000..d7a3df4acafa --- /dev/null +++ b/users/grfn/xanthous/test/Xanthous/Game/PromptSpec.hs @@ -0,0 +1,19 @@ +-------------------------------------------------------------------------------- +module Xanthous.Game.PromptSpec (main, test) where +-------------------------------------------------------------------------------- +import Test.Prelude +-------------------------------------------------------------------------------- +import Xanthous.Game.Prompt +-------------------------------------------------------------------------------- + +main :: IO () +main = defaultMain test + +test :: TestTree +test = testGroup "Xanthous.Game.PromptSpec" + [ testGroup "mkMenuItems" + [ testCase "with duplicate items" + $ mkMenuItems @[_] [('a', MenuOption @Int "a" 1), ('a', MenuOption "a" 2)] + @?= mapFromList [('a', MenuOption "a" 1), ('b', MenuOption "a" 2)] + ] + ] diff --git a/users/grfn/xanthous/test/Xanthous/UtilSpec.hs b/users/grfn/xanthous/test/Xanthous/UtilSpec.hs index 0d6b718bc351..684a03b2c7a0 100644 --- a/users/grfn/xanthous/test/Xanthous/UtilSpec.hs +++ b/users/grfn/xanthous/test/Xanthous/UtilSpec.hs @@ -40,4 +40,7 @@ test = testGroup "Xanthous.Util" , testProperty "the result is the right length" $ \(xs :: [Int]) p -> length (removeFirst p xs) `elem` [length xs, length xs - 1] ] + , testGroup "AlphaChar" + [ testCase "succ 'z'" $ succ (AlphaChar 'z') @?= AlphaChar 'A' + ] ] -- cgit 1.4.1