-
-
Notifications
You must be signed in to change notification settings - Fork 276
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add very basic unit tests for EZConfig to see if it can parse all of the keys (and key combinations) that it promises to parse. The long-term goal here should be to write a pretty-printer for EZConfig and to check whether that's a proper inverse (either in the normal sense or in the inverse semigroup sense), as the tests for X.P.OrgMode do.
- Loading branch information
Showing
4 changed files
with
51 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
module EZConfig (spec) where | ||
|
||
import Control.Arrow (first) | ||
import Test.Hspec | ||
import XMonad | ||
import XMonad.Prelude | ||
import XMonad.Util.EZConfig | ||
import XMonad.Util.Parser | ||
|
||
spec :: Spec | ||
spec = do | ||
context "parseKey" $ do | ||
let prepare = unzip . map (first surround) | ||
testParseKey (ns, ks) = traverse (runParser parseKey) ns `shouldBe` Just ks | ||
it "parses all regular keys" $ testParseKey regularKeys | ||
it "parses all function keys" $ testParseKey (prepare functionKeys ) | ||
it "parses all special keys" $ testParseKey (prepare specialKeys ) | ||
it "parses all multimedia keys" $ testParseKey (prepare multimediaKeys) | ||
context "parseModifier" $ do | ||
it "parses all combinations of modifiers" $ | ||
nub . map sort <$> traverse (runParser (many $ parseModifier def)) | ||
modifiers | ||
`shouldBe` Just [[ shiftMask, controlMask | ||
, mod1Mask, mod1Mask -- def M and M1 | ||
, mod2Mask, mod3Mask, mod4Mask, mod5Mask | ||
]] | ||
|
||
regularKeys :: ([String], [KeySym]) | ||
regularKeys = unzip . map (first (: "")) | ||
$ zip ['!' .. '~' ] [xK_exclam .. xK_asciitilde] | ||
++ zip ['\xa0' .. '\xff'] [xK_nobreakspace .. xK_ydiaeresis] | ||
|
||
-- | QuickCheck can handle the 8! combinations just fine. | ||
modifiers :: [String] | ||
modifiers = map concat $ | ||
permutations ["M-", "C-", "S-", "M1-", "M2-", "M3-", "M4-", "M5-"] | ||
|
||
surround :: String -> String | ||
surround s = "<" <> s <> ">" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters