# -*- 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?"} } 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:noleadingdash 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?"} # # For the "unknown args problem: It would be staightforward to # provide an nsf-proc somewhat similar to NsfArgumentError () which # gets the object passed if applicable (methodParameter) # # nsf::proc argumentError {cause arg -expected -msg -cmd -object -methodName} { # # } # # pros: # - we could build the syntax from tcl... # - an unknown handler for nonpos args could fit in, for method and object parameters # - it should be possible to switch to a raw mode to make life easier when error # messages change. # - it should be feasible to output message to tk. # - one could even think about nationalizing, etc... # - maybe we could fit even the unknown object handling in (::nsf::object::unknown) # # contras: # - not sure, we can hide the context on the error stack # - not exactly the tcl-way # - most errors are thrown in hopeless situations (not enough args), # some errors could recover (e.g. unknown handler). we have to # signal these situations from the C code. }