17 changed files with 3536 additions and 1709 deletions
File diff suppressed because it is too large
Load Diff
File diff suppressed because it is too large
Load Diff
@ -0,0 +1,158 @@ |
|||||||
|
package require tcltest |
||||||
|
|
||||||
|
namespace eval ::testspace { |
||||||
|
namespace import ::tcltest::* |
||||||
|
variable common { |
||||||
|
set result "" |
||||||
|
} |
||||||
|
|
||||||
|
|
||||||
|
test choices_typeignored_when_choice_in_list {Test that -type is not validated for a value that matches a choice}\ |
||||||
|
-setup $common -body { |
||||||
|
#1 abbreviated choice |
||||||
|
set argd [punk::args::parse {li} withdef @values {frametype -type dict -choices {heavy light arc}}] |
||||||
|
lappend result [dict get $argd values] |
||||||
|
|
||||||
|
#2 exact match for a choice |
||||||
|
set argd [punk::args::parse {light} withdef @values {frametype -type dict -choices {heavy light arc}}] |
||||||
|
lappend result [dict get $argd values] |
||||||
|
}\ |
||||||
|
-cleanup { |
||||||
|
}\ |
||||||
|
-result [list\ |
||||||
|
{frametype light}\ |
||||||
|
{frametype light}\ |
||||||
|
] |
||||||
|
|
||||||
|
test choices_type_validation_choicerestricted1 {Test that -type is validated for value outside of choicelist based on -choicerestricted}\ |
||||||
|
-setup $common -body { |
||||||
|
|
||||||
|
set argd [punk::args::parse {11} withdef @values {frametype -type int -choicerestricted 0 -choices {heavy light arc}}] |
||||||
|
lappend result [dict get $argd values] |
||||||
|
|
||||||
|
if {[catch { |
||||||
|
punk::args::parse {z} withdef @values {frametype -type int -choicerestricted 0 -choices {heavy light arc}} |
||||||
|
}]} { |
||||||
|
lappend result "ok_got_expected_error1" |
||||||
|
} else { |
||||||
|
lappend result "missing_required_error_when_type_mismatch_for_choice_outside_list" |
||||||
|
} |
||||||
|
|
||||||
|
#when -choicerestricted - value matching -type still shouldn't pass |
||||||
|
if {[catch { |
||||||
|
set argd [punk::args::parse {11} withdef @values {frametype -type int -choicerestricted 1 -choices {heavy light arc}}] |
||||||
|
}]} { |
||||||
|
lappend result "ok_got_expected_error2" |
||||||
|
} else { |
||||||
|
lappend result "missing_required_error_when_choicerestricted_and_choice_outside_list" |
||||||
|
} |
||||||
|
}\ |
||||||
|
-cleanup { |
||||||
|
}\ |
||||||
|
-result [list\ |
||||||
|
{frametype 11}\ |
||||||
|
ok_got_expected_error1\ |
||||||
|
ok_got_expected_error2\ |
||||||
|
] |
||||||
|
|
||||||
|
test choices_type_validation_choicerestricted2 {Test that -type dict is validated for value outside of choicelist based on -choicerestricted}\ |
||||||
|
-setup $common -body { |
||||||
|
#same as choices_type_validation_choicrestricted1 - but with a more complex type 'dict' - tests list protection is correct |
||||||
|
set argd [punk::args::parse {{hl -}} withdef @values {frametype -type dict -choicerestricted 0 -choices {heavy light arc}}] |
||||||
|
lappend result [dict get $argd values] |
||||||
|
|
||||||
|
if {[catch { |
||||||
|
punk::args::parse {z} withdef @values {frametype -type dict -choicerestricted 0 -choices {heavy light arc}} |
||||||
|
}]} { |
||||||
|
lappend result "ok_got_expected_error1" |
||||||
|
} else { |
||||||
|
lappend result "missing_required_error_when_type_mismatch_for_choice_outside_list" |
||||||
|
} |
||||||
|
|
||||||
|
#when -choicerestricted - value matching -type dict still shouldn't pass |
||||||
|
if {[catch { |
||||||
|
set argd [punk::args::parse {{hl -}} withdef @values {frametype -type dict -choicerestricted 1 -choices {heavy light arc}}] |
||||||
|
}]} { |
||||||
|
lappend result "ok_got_expected_error2" |
||||||
|
} else { |
||||||
|
lappend result "missing_required_error_when_choicerestricted_and_choice_outside_list" |
||||||
|
} |
||||||
|
}\ |
||||||
|
-cleanup { |
||||||
|
}\ |
||||||
|
-result [list\ |
||||||
|
{frametype {hl -}}\ |
||||||
|
ok_got_expected_error1\ |
||||||
|
ok_got_expected_error2\ |
||||||
|
] |
||||||
|
|
||||||
|
test choice_multiple_multiple {test -choice with both -multiple and -choicemultiple}\ |
||||||
|
-setup $common -body { |
||||||
|
set argd [punk::args::parse {a {c a} {a b c}} withdef @values {X -type string -choices {aa bb cc} -multiple 1 -choicemultiple {1 3} -optional 1}] |
||||||
|
lappend result [dict get $argd values] |
||||||
|
}\ |
||||||
|
-cleanup { |
||||||
|
}\ |
||||||
|
-result [list\ |
||||||
|
{X {aa {cc aa} {aa bb cc}}} |
||||||
|
] |
||||||
|
#todo - decide on whether -choicemultiple should disallow duplicates in result by default |
||||||
|
|
||||||
|
|
||||||
|
test choice_multielement_clause {test -choice with a clause-length greater than 1}\ |
||||||
|
-setup $common -body { |
||||||
|
#The same -choices list always applies to each member of -type - which isn't always ideal for a multi-element clause |
||||||
|
#for a clause where each element has a different choiceset - we would need to introduce a more complex -typechoices option |
||||||
|
#(or use a -parsekey mechanism on leaders/values to group them) |
||||||
|
|
||||||
|
#test all combinations of prefix and complete for 2 entries |
||||||
|
set argd [punk::args::parse {light heavy} withdef @values {leftright -type {any any} -choices {light heavy} -choicerestricted 1}] |
||||||
|
lappend result [dict get $argd values] |
||||||
|
set argd [punk::args::parse {li heavy} withdef @values {leftright -type {any any} -choices {light heavy} -choicerestricted 1}] |
||||||
|
lappend result [dict get $argd values] |
||||||
|
set argd [punk::args::parse {li he} withdef @values {leftright -type {any any} -choices {light heavy} -choicerestricted 1}] |
||||||
|
lappend result [dict get $argd values] |
||||||
|
set argd [punk::args::parse {light he} withdef @values {leftright -type {any any} -choices {light heavy} -choicerestricted 1}] |
||||||
|
lappend result [dict get $argd values] |
||||||
|
}\ |
||||||
|
-cleanup { |
||||||
|
}\ |
||||||
|
-result [list\ |
||||||
|
{leftright {light heavy}}\ |
||||||
|
{leftright {light heavy}}\ |
||||||
|
{leftright {light heavy}}\ |
||||||
|
{leftright {light heavy}}\ |
||||||
|
] |
||||||
|
|
||||||
|
test choice_multielement_clause_unrestricted {test -choice with a clause-length greater than 1 and values outside of choicelist}\ |
||||||
|
-setup $common -body { |
||||||
|
#1 both values outside of -choices |
||||||
|
set argd [punk::args::parse {11 x} withdef @values {leftright -type {int char} -choices {light heavy arc} -choicerestricted 0}] |
||||||
|
lappend result [dict get $argd values] |
||||||
|
# |
||||||
|
set argd [punk::args::parse {11 arc} withdef @values {leftright -type {int char} -choices {light heavy arc} -choicerestricted 0}] |
||||||
|
lappend result [dict get $argd values] |
||||||
|
# |
||||||
|
set argd [punk::args::parse {11 a} withdef @values {leftright -type {int char} -choices {light heavy arc} -choicerestricted 0}] |
||||||
|
lappend result [dict get $argd values] |
||||||
|
# |
||||||
|
set argd [punk::args::parse {heavy x} withdef @values {leftright -type {int char} -choices {light heavy arc} -choicerestricted 0}] |
||||||
|
lappend result [dict get $argd values] |
||||||
|
# |
||||||
|
set argd [punk::args::parse {h x} withdef @values {leftright -type {int char} -choices {light heavy arc} -choicerestricted 0}] |
||||||
|
lappend result [dict get $argd values] |
||||||
|
# |
||||||
|
set argd [punk::args::parse {a h} withdef @values {leftright -type {int char} -choices {light heavy arc} -choicerestricted 0}] |
||||||
|
lappend result [dict get $argd values] |
||||||
|
}\ |
||||||
|
-cleanup { |
||||||
|
}\ |
||||||
|
-result [list\ |
||||||
|
{leftright {11 x}}\ |
||||||
|
{leftright {11 arc}}\ |
||||||
|
{leftright {11 arc}}\ |
||||||
|
{leftright {heavy x}}\ |
||||||
|
{leftright {heavy x}}\ |
||||||
|
{leftright {arc heavy}}\ |
||||||
|
] |
||||||
|
} |
@ -0,0 +1,76 @@ |
|||||||
|
|
||||||
|
package require tcltest |
||||||
|
|
||||||
|
namespace eval ::testspace { |
||||||
|
namespace import ::tcltest::* |
||||||
|
variable common { |
||||||
|
set result "" |
||||||
|
} |
||||||
|
|
||||||
|
|
||||||
|
test opts_longoptvalue {Test -alt|--longopt= can accept value as longopt}\ |
||||||
|
-setup $common -body { |
||||||
|
set argd [punk::args::parse {--filename=abc} withdef @opts {-f|--filename= -default spud -type string}] |
||||||
|
lappend result [dict get $argd opts];#name by default should be last flag alternative (stripped of =) ie "--filename" |
||||||
|
}\ |
||||||
|
-cleanup { |
||||||
|
}\ |
||||||
|
-result [list\ |
||||||
|
{--filename abc}\ |
||||||
|
] |
||||||
|
|
||||||
|
test opts_longoptvalue_alternative {Test -alt|--longopt= can accept value as spaced argument to given alternative}\ |
||||||
|
-setup $common -body { |
||||||
|
#test full name of alt flag |
||||||
|
set argd [punk::args::parse {-fx xyz} withdef @opts {-fx|--filename= -default spud -type string}] |
||||||
|
lappend result [dict get $argd opts] ;#name by default should be last flag alternative (stripped of =) ie "--filename" |
||||||
|
#test prefixed version of flag |
||||||
|
set argd [punk::args::parse {-f xyz} withdef @opts {-fx|--filename= -default spud -type string}] |
||||||
|
lappend result [dict get $argd opts] |
||||||
|
}\ |
||||||
|
-cleanup { |
||||||
|
}\ |
||||||
|
-result [list\ |
||||||
|
{--filename xyz}\ |
||||||
|
{--filename xyz}\ |
||||||
|
] |
||||||
|
|
||||||
|
test opts_longoptvalue_alternative_noninterference {Test -alt|--longopt= can accept longopt values as normal }\ |
||||||
|
-setup $common -body { |
||||||
|
#test full name of longopt |
||||||
|
set argd [punk::args::parse {--filename=xyz} withdef @opts {-fx|--filename= -default spud -type string}] |
||||||
|
lappend result [dict get $argd opts] ;#name by default should be last flag alternative (stripped of =) ie "--filename" |
||||||
|
#test prefixed version of longopt |
||||||
|
set argd [punk::args::parse {--file=xyz} withdef @opts {-fx|--filename= -default spud -type string}] |
||||||
|
lappend result [dict get $argd opts] |
||||||
|
}\ |
||||||
|
-cleanup { |
||||||
|
}\ |
||||||
|
-result [list\ |
||||||
|
{--filename xyz}\ |
||||||
|
{--filename xyz}\ |
||||||
|
] |
||||||
|
|
||||||
|
test opts_longoptvalue_choice {Test --longopt= works wiith -choices}\ |
||||||
|
-setup $common -body { |
||||||
|
#prefixed choice with and without prefixed flagname |
||||||
|
set argd [punk::args::parse {--filename=x} withdef @opts {--filename= -default spud -type string -choices {abc xyz}}] |
||||||
|
lappend opts [dict get $argd opts] |
||||||
|
set argd [punk::args::parse {--file=x} withdef @opts {--filename= -default spud -type string -choices {abc xyz}}] |
||||||
|
lappend opts [dict get $argd opts] |
||||||
|
#unprefixed choice with and without prefixed flagname |
||||||
|
set argd [punk::args::parse {--filename=xyz} withdef @opts {--filename= -default spud -type string -choices {abc xyz}}] |
||||||
|
lappend opts [dict get $argd opts] |
||||||
|
set argd [punk::args::parse {--file=xyz} withdef @opts {--filename= -default spud -type string -choices {abc xyz}}] |
||||||
|
lappend opts [dict get $argd opts] |
||||||
|
|
||||||
|
}\ |
||||||
|
-cleanup { |
||||||
|
}\ |
||||||
|
-result [list\ |
||||||
|
{--filename xyz}\ |
||||||
|
{--filename xyz}\ |
||||||
|
{--filename xyz}\ |
||||||
|
{--filename xyz}\ |
||||||
|
] |
||||||
|
} |
Loading…
Reference in new issue