comparison scripts/general/nargchk.m @ 9204:1f47a9404d93

nargchk.m: don't generate error if output is struct
author John W. Eaton <jwe@octave.org>
date Fri, 15 May 2009 11:46:10 -0400
parents eb63fbe60fab
children be55736a0783
comparison
equal deleted inserted replaced
9203:a542fc158175 9204:1f47a9404d93
36 print_usage (); 36 print_usage ();
37 elseif (mina > maxa) 37 elseif (mina > maxa)
38 error ("nargchk: minargs must be <= maxargs"); 38 error ("nargchk: minargs must be <= maxargs");
39 elseif (nargin == 3) 39 elseif (nargin == 3)
40 outtype = "string"; 40 outtype = "string";
41 elseif (! any (strcmpi (outtype, {"string" "struct"}))) 41 elseif (! any (strcmpi (outtype, {"string", "struct"})))
42 error ("nargchk: output type must be either string or struct"); 42 error ("nargchk: output type must be either string or struct");
43 elseif (! (isscalar (mina) && isscalar (maxa) && isscalar (narg))) 43 elseif (! (isscalar (mina) && isscalar (maxa) && isscalar (narg)))
44 error ("nargchk: mina, maxa, and narg must be scalars"); 44 error ("nargchk: mina, maxa, and narg must be scalars");
45 endif 45 endif
46 46
53 msg.identifier = "Octave:nargchk:too-many-inputs"; 53 msg.identifier = "Octave:nargchk:too-many-inputs";
54 endif 54 endif
55 55
56 if (strcmpi (outtype, "string")) 56 if (strcmpi (outtype, "string"))
57 msg = msg.message; 57 msg = msg.message;
58 else 58 elseif (isempty (msg.message))
59 if (isempty (msg.message)) 59 msg = struct ([]);
60 msg = struct ([]);
61 endif
62 ## FIXME: remove the error below if error is modified to accept
63 ## struct inputs
64 error ("nargchk: error does not yet support struct inputs");
65 endif 60 endif
66 61
67 endfunction 62 endfunction
68 63
69 ## Tests 64 ## Tests
76 %!assert (nargchk (0, 1, 1), "") 71 %!assert (nargchk (0, 1, 1), "")
77 %!assert (nargchk (1, 1, 0), "not enough input arguments") 72 %!assert (nargchk (1, 1, 0), "not enough input arguments")
78 %!assert (nargchk (0, 1, 2), "too many input arguments") 73 %!assert (nargchk (0, 1, 2), "too many input arguments")
79 %!assert (nargchk (0, 1, 2, "string"), "too many input arguments") 74 %!assert (nargchk (0, 1, 2, "string"), "too many input arguments")
80 ## Struct outputs 75 ## Struct outputs
81 #%!assert (nargchk (0, 1, 0, "struct"), struct([])) 76 %!assert (nargchk (0, 1, 0, "struct"), struct([]))
82 #%!assert (nargchk (0, 1, 1, "struct"), struct([])) 77 %!assert (nargchk (0, 1, 1, "struct"), struct([]))
83 #%!assert (nargchk (1, 1, 0, "struct"), stmin) 78 %!assert (nargchk (1, 1, 0, "struct"), stmin)
84 #%!assert (nargchk (0, 1, 2, "struct"), stmax) 79 %!assert (nargchk (0, 1, 2, "struct"), stmax)