Skip to content

Commit

Permalink
command-line.parser: adding test for cannot-convert-value
Browse files Browse the repository at this point in the history
  • Loading branch information
mrjbq7 committed May 22, 2024
1 parent 7a443df commit dbf4630
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 3 deletions.
7 changes: 7 additions & 0 deletions extra/command-line/parser/parser-tests.factor
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,13 @@ math.parser namespaces sequences tools.test ;

IN: command-line.parser.tests

TUPLE: foo ;

[
{ T{ option { name "--foo" } { type foo } } }
{ "--foo" "abcd" } (parse-options)
] [ cannot-convert-value? ] must-fail-with

[
{ T{ option { name "--foo" } { required? t } } }
{ } (parse-options)
Expand Down
6 changes: 3 additions & 3 deletions extra/command-line/parser/parser.factor
Original file line number Diff line number Diff line change
Expand Up @@ -32,9 +32,8 @@ TUPLE: option name type help variable default convert validate

: option-name ( option -- name )
{
[ name>> [ CHAR: - = ] trim-head ]
[ variable>> dup string? [ name>> ] unless ]
} 1|| ;
[ name>> ] [ variable>> dup string? [ name>> ] unless ]
} 1|| [ CHAR: - = ] trim-head ;

:: option-#args ( option -- #args )
option #args>> [ option const>> 1 xor ] unless* ;
Expand Down Expand Up @@ -107,6 +106,7 @@ M: cannot-convert-value error.
dup quotation? [ call( str -- val ) ] [
{
{ f [ ] }
{ string [ ] }
{ object [ [ 1array <lexer> [ scan-object ] with-lexer ] with-manifest ] }
{ boolean [ {
{ [ dup >lower { "t" "true" "1" "on" "y" "yes" } member? ] [ drop t ] }
Expand Down

0 comments on commit dbf4630

Please sign in to comment.