Add new test cases for optional pair of arguments

This commit is contained in:
Ben Selfridge 2019-03-08 16:30:20 -08:00 committed by Huw Campbell
parent e34d4105c7
commit 0f2c15ac7e
4 changed files with 46 additions and 0 deletions

View File

@ -36,6 +36,8 @@ extra-source-files: CHANGELOG.md
tests/helponemptysub.err.txt
tests/formatting.err.txt
tests/nested.err.txt
tests/optional.err.txt
tests/nested_optional.err.txt
tests/subparsers.err.txt
homepage: https://github.com/pcapriotti/optparse-applicative

View File

@ -0,0 +1,7 @@
Usage: nested_optional --a A [--b0 B0 [--b1 B1]]
Available options:
--a A value a
--b0 B0 value b0
--b1 B1 value b1
-h,--help Show this help text

6
tests/optional.err.txt Normal file
View File

@ -0,0 +1,6 @@
Usage: optional [--a A --b B]
Available options:
--a A value a
--b B value b
-h,--help Show this help text

View File

@ -146,6 +146,37 @@ prop_alt_help = once $
i = info (p <**> helper) idm
in checkHelpText "alt" i ["--help"]
prop_optional_help :: Property
prop_optional_help = once $
let p :: Parser (Maybe (String, String))
p = optional ((,)
<$> strOption ( long "a"
<> metavar "A"
<> help "value a" )
<*> strOption ( long "b"
<> metavar "B"
<> help "value b" ) )
i = info (p <**> helper) idm
in checkHelpText "optional" i ["--help"]
prop_nested_optional_help :: Property
prop_nested_optional_help = once $
let p :: Parser (String, Maybe (String, Maybe String))
p = (,) <$>
(strOption ( long "a"
<> metavar "A"
<> help "value a" ) ) <*>
(optional
((,) <$>
(strOption ( long "b0"
<> metavar "B0"
<> help "value b0" ) ) <*>
(optional (strOption ( long "b1"
<> metavar "B1"
<> help "value b1" )))))
i = info (p <**> helper) idm
in checkHelpText "nested_optional" i ["--help"]
prop_nested_commands :: Property
prop_nested_commands = once $
let p3 :: Parser String