( Options(..)
, OptType
, parseOpts
+ , parseYesNo
, parseISpecString
, shTemplate
, defaultLuxiSocket
-- * Functions
-- | Helper for parsing a yes\/no command line flag.
-parseYesNo :: Bool -- ^ Default whalue (when we get a @Nothing@)
+parseYesNo :: Bool -- ^ Default value (when we get a @Nothing@)
-> Maybe String -- ^ Parameter value
-> Result Bool -- ^ Resulting boolean value
parseYesNo v Nothing = return v
parseYesNo _ (Just "yes") = return True
parseYesNo _ (Just "no") = return False
-parseYesNo _ (Just s) = fail $ "Invalid choice '" ++ s ++
- "', pass one of 'yes' or 'no'"
+parseYesNo _ (Just s) = fail ("Invalid choice '" ++ s ++
+ "', pass one of 'yes' or 'no'")
-- | Usage info.
usageHelp :: String -> [OptType] -> String
Types.Ok v -> failTest $ "Expected failure, got " ++ show v
_ -> property True
+-- | Test parseYesNo.
+prop_CLI_parseYesNo def testval val =
+ forAll (elements [val, "yes", "no"]) $ \actual_val ->
+ if testval
+ then CLI.parseYesNo def Nothing ==? Types.Ok def
+ else let result = CLI.parseYesNo def (Just actual_val)
+ in if actual_val `elem` ["yes", "no"]
+ then result ==? Types.Ok (actual_val == "yes")
+ else property $ Types.isBad result
+
testSuite "CLI"
[ 'prop_CLI_parseISpec
, 'prop_CLI_parseISpecFail
+ , 'prop_CLI_parseYesNo
]