package require tcltest namespace eval ::testspace { namespace import ::tcltest::* variable common { set result "" } test parse_withdef_leaders_min_max {Test anonymous leaders with @leaders -min and -max}\ -setup $common -body { set argd [punk::args::parse {a b c d} withdef {@leaders -min 1 -max 3} ] lappend result [dict get $argd leaders] lappend result [dict get $argd values] }\ -cleanup { }\ -result [list\ {0 a 1 b 2 c} {3 d} ] test parse_withdef_leaders_ordering_defaults {Test ordering of leaders when some have defaults}\ -setup $common -body { set argd [punk::args::parse {a b} withdef @leaders x {y -default 1}] set vals [dict get $argd leaders] set result $vals }\ -cleanup { }\ -result [list\ x a y b ] test parse_withdef_option_ordering_defaults {Test ordering of options when some have defaults}\ -setup $common -body { #for consistency with leaders and values dicts - try to maintain definition order for options too set argd [punk::args::parse {-x a -y b} withdef @opts -x {-y -default 1}] set vals [dict get $argd opts] set result $vals }\ -cleanup { }\ -result [list\ -x a -y b ] test parse_withdef_option_ordering_defaults2 {Test ordering of options when some have defaults and -any is true}\ -setup $common -body { #for consistency with leaders and values dicts - try to maintain definition order for options too set argd [punk::args::parse {-blah etc -x a -y b -solo -z c} withdef {@opts -any 1} -x {-y -default 1} {-solo -type none} -z] set vals [dict get $argd opts] set result $vals }\ -cleanup { }\ -result [list\ -x a -y b -solo 1 -z c -blah etc ] test parse_withdef_values_ordering_defaults {Test ordering of values when some have defaults}\ -setup $common -body { set argd [punk::args::parse {a b} withdef @values x {y -default 1}] set vals [dict get $argd values] set result $vals }\ -cleanup { }\ -result [list\ x a y b ] test parse_withdef_leader_multiple {Test named leader with -multiple true}\ -setup $common -body { #should not error set argd [punk::args::parse {a b c} withdef {@leaders -min 0} {L -multiple 1} {@values -min 1 -max 1} V] lappend result [dict get $argd leaders] lappend result [dict get $argd values] }\ -cleanup { }\ -result [list\ {L {a b}} {V c} ] test parse_withdef_leader_min_max {Test unnamed leaders with -min and -max}\ -setup $common -body { #should not error - should allocate d to values set argd [punk::args::parse {a b c d} withdef {@leaders -min 1 -max 4} {@values -min 1 -max 1}] lappend result [dict get $argd leaders] lappend result [dict get $argd values] }\ -cleanup { }\ -result [list\ {0 a 1 b 2 c} {3 d} ] test parse_withdef_leader_stride {Test stride leaders}\ -setup $common -body { #see for example ::tcl::dict::create which has a stride of 2 set argd [punk::args::parse {k v e k1 v1 k2 v2} withdef {@leaders} {"key val etc" -multiple 0} {"key val" -multiple 1} {@values -min 0 -max 0}] lappend result [dict get $argd leaders] }\ -cleanup { }\ -result [list\ {{key val etc} {k v e} {key val} {{k1 v1} {k2 v2}}} ] test parse_withdef_value_stride {Test stride values}\ -setup $common -body { #see for example ::tcl::dict::create which has a stride of 2 set argd [punk::args::parse {k v e k1 v1 k2 v2} withdef {@values} {"key val etc" -multiple 0} {"key val" -multiple 1}] lappend result [dict get $argd values] }\ -cleanup { }\ -result [list\ {{key val etc} {k v e} {key val} {{k1 v1} {k2 v2}}} ] test parse_withdef_value_stride_error {Test stride values with error due to not enough args for stride}\ -setup $common -body { #see for example ::tcl::dict::create which has a stride of 2 if {[catch {punk::args::parse {k v} withdef {@values} {"key val etc" -multiple 0}} emsg eopts]} { set expected [dict get $eopts -errorcode] if {[lindex $expected 0] eq "PUNKARGS" && [lindex $expected 1] eq "VALIDATION" && [lindex $expected 2 0] eq "stridevaluecount"} { lappend result "RECEIVED_EXPECTED_ERROR" } else { lappend result "WRONG_ERROR_RECEIVED - $expected (expected PUNKARGS VALIDATION {stridevaluecount ...} ..." } } else { lappend result "MISSING_REQUIRED_ERROR" } }\ -cleanup { }\ -result [list\ "RECEIVED_EXPECTED_ERROR" ] }