# -*- Tcl -*- package require nx package require nx::test nx::Test case method-params-0 { nsf::proc p0 {} {return 1} nsf::proc p1 {-x} {return [list [info exists x]]} ? {p0} 1 ;# the following error msg comes from Tcl ? {p0 -x} {wrong # args: should be "p0"} ? {p1} 0 ? {p1 -x} {value for parameter '-x' expected} ? {p1 -x 1} 1 ? {p1 -x 1 2} {invalid argument '2', maybe too many arguments; should be "p1 ?-x /value/?"} ? {p1 -x 1 -y} {invalid non-positional argument '-y', valid are : -x; should be "p1 ?-x /value/?"} ? {p1 a} {invalid argument 'a', maybe too many arguments; should be "p1 ?-x /value/?"} ? {p1 a -x} {invalid argument 'a', maybe too many arguments; should be "p1 ?-x /value/?"} ? {p1 --} 0 ? {p1 -y} {invalid non-positional argument '-y', valid are : -x; should be "p1 ?-x /value/?"} ? {p1 -y --} {invalid non-positional argument '-y', valid are : -x; should be "p1 ?-x /value/?"} # # should we really allow numeric nonpos arg names? # ? {nsf::proc p2 {1 -2 -3} {return [list ${1} [info exists 2] [info exists 3]]}} "" ? {p2 -4 -2 -3 -3 -2} "-4 1 1" ;# var 2 has value "-3", var 3 has value "-2" ? {p2 -4 -3 + -2 -1} "-4 1 1" ;# var 2 has value "-2", var 3 has value "+" ? {nsf::proc p3 {1 -2 -3 4} {return [list ${1} [info exists 2] [info exists 3] ${4}]}} "" ? {p3 -4 -3 -2 -1} "-4 0 1 -1" ;# var 1 has value "-4", var 4 has value "-1" } nx::Test case noleadingdash { nsf::proc p2a {-x args} {return [list [info exists x] $args]} nsf::proc p2b {-x args:noleadingdash} {return [list [info exists x] $args]} nsf::proc p2c {-x args:noleadingdash} {return [list [info exists x] $args]} ? {p2a -x -y} {1 {}} ;# "-y" is the value of "x" ? {p2b -x -y} {1 {}} ;# "-y" is the value of "x" ? {p2c -x -y} {1 {}} ;# "-y" is the value of "x"; TODO: noleadindash currently only for posargs ? {p2a -x 1 -y} {1 -y} ? {p2b -x 1 -y} {invalid non-positional argument '-y', valid are : -x; should be "p2b ?-x /value/? ?/arg .../?"} ? {p2c -x 1 -y} {invalid non-positional argument '-y', valid are : -x; should be "p2c ?-x /value/? ?/arg .../?"} nsf::proc p3a {a -x -y b:noleadingdash -z} {return [list $a [info exists x] [info exists y] $b]} ? {p3a 100 -x 1 -y 1 200} {100 1 1 200} ? {p3a 100 -xx 1 -y 1 200} {invalid non-positional argument '-xx', valid are : -x, -y; should be "p3a /a/ ?-x /value/? ?-y /value/? /b/ ?-z /value/?"} } nx::Test case unknown-handler { Class create C { :public method p1 {-x} {return [list [info exists x]]} :create c1 } ? {c1 p1 -x 1 -y} {invalid non-positional argument '-y', valid are : -x; should be "::c1 p1 ?-x /value/?"} proc ::nsf::argument::unknown {method arg args} { puts stderr "??? unknown nonpos-arg $arg in $method obj <$args>\n[info frame -1]\n" return "" } ? {c1 p1 -x 1 -y} {invalid non-positional argument '-y', valid are : -x; should be "::c1 p1 ?-x /value/?"} if {0} { proc ::nsf::argument::unknown {method arg args} { # nasty handler redefines method puts stderr "??? REDEFINE ::nsf::argument::unknown <$args> [info frame -1]" C public method p1 {-y} {return [list [info exists y]]} return "" } ? {c1 p1 -x 1 -y} {invalid non-positional argument '-y', valid are : -x; should be "::c1 p1 ?-x /value/?"} } }