-
-
Notifications
You must be signed in to change notification settings - Fork 1.7k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Throw for unsupported option flag setup (#2270)
- Loading branch information
1 parent
2c9051a
commit 966720a
Showing
3 changed files
with
62 additions
and
13 deletions.
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,34 @@ | ||
const { Option } = require('../'); | ||
|
||
// Check that unsupported flags throw. | ||
test.each([ | ||
{ flags: '-a, -b' }, // too many short flags | ||
{ flags: '-a, -b <value>' }, | ||
{ flags: '-a, -b, --long' }, | ||
{ flags: '--one, --two' }, // too many long flags | ||
{ flags: '--one, --two [value]' }, | ||
{ flags: '-ws' }, // short flag with more than one character | ||
{ flags: 'sdkjhskjh' }, // oops, no flags | ||
{ flags: '-a,-b' }, // try all the separators | ||
{ flags: '-a|-b' }, | ||
{ flags: '-a -b' }, | ||
])('when construct Option with flags %p then throw', ({ flags }) => { | ||
expect(() => { | ||
new Option(flags); | ||
}).toThrow(/^invalid Option flags/); | ||
}); | ||
|
||
// Check that supported flags do not throw. | ||
test.each([ | ||
{ flags: '-s' }, // single short | ||
{ flags: '--long' }, // single long | ||
{ flags: '-b, --both' }, // short and long | ||
{ flags: '-b,--both <comma>' }, | ||
{ flags: '-b|--both <bar>' }, | ||
{ flags: '-b --both [space]' }, | ||
{ flags: '-v, --variadic <files...>' }, | ||
])('when construct Option with flags %p then do not throw', ({ flags }) => { | ||
expect(() => { | ||
new Option(flags); | ||
}).not.toThrow(); | ||
}); |
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