Mercurial > octave-nkf
comparison scripts/general/nargoutchk.m @ 12865:a4d1581f9e72
Return correct struct for nargchk, nargoutchk (Bug #33808).
* nargchk.m, nargoutchk.m: Return struct with message and identifier fields
when number of arguments is valid, not just an empty struct.
author | Rik <octave@nomad.inbox5.com> |
---|---|
date | Wed, 20 Jul 2011 10:41:59 -0700 |
parents | 4972eb61c6d6 |
children | 49553ea11764 |
comparison
equal
deleted
inserted
replaced
12864:213c791292a6 | 12865:a4d1581f9e72 |
---|---|
53 msg.identifier = "Octave:nargoutchk:too-many-outputs"; | 53 msg.identifier = "Octave:nargoutchk:too-many-outputs"; |
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 elseif (isempty (msg.message)) | |
59 msg = struct (); | |
60 endif | 58 endif |
61 | 59 |
62 endfunction | 60 endfunction |
63 | 61 |
64 | 62 |
65 ## Tests | 63 ## Tests |
66 %!shared stmin, stmax | 64 %!shared stnul, stmin, stmax |
65 %! stnul = struct ("message", "", | |
66 %! "identifier", ""); | |
67 %! stmin = struct ("message", "not enough output arguments", | 67 %! stmin = struct ("message", "not enough output arguments", |
68 %! "identifier", "Octave:nargoutchk:not-enough-outputs"); | 68 %! "identifier", "Octave:nargoutchk:not-enough-outputs"); |
69 %! stmax = struct ("message", "too many output arguments", | 69 %! stmax = struct ("message", "too many output arguments", |
70 %! "identifier", "Octave:nargoutchk:too-many-outputs"); | 70 %! "identifier", "Octave:nargoutchk:too-many-outputs"); |
71 %!assert (nargoutchk (0, 1, 0), "") | 71 %!assert (nargoutchk (0, 1, 0), "") |
72 %!assert (nargoutchk (0, 1, 1), "") | 72 %!assert (nargoutchk (0, 1, 1), "") |
73 %!assert (nargoutchk (1, 1, 0), "not enough output arguments") | 73 %!assert (nargoutchk (1, 1, 0), "not enough output arguments") |
74 %!assert (nargoutchk (0, 1, 2), "too many output arguments") | 74 %!assert (nargoutchk (0, 1, 2), "too many output arguments") |
75 %!assert (nargoutchk (0, 1, 2, "string"), "too many output arguments") | 75 %!assert (nargoutchk (0, 1, 2, "string"), "too many output arguments") |
76 ## Struct outputs | 76 ## Struct outputs |
77 #%!assert (nargoutchk (0, 1, 0, "struct"), struct()) | 77 %!assert (nargoutchk (0, 1, 0, "struct"), stnul) |
78 #%!assert (nargoutchk (0, 1, 1, "struct"), struct()) | 78 %!assert (nargoutchk (0, 1, 1, "struct"), stnul) |
79 #%!assert (nargoutchk (1, 1, 0, "struct"), stmin) | 79 %!assert (nargoutchk (1, 1, 0, "struct"), stmin) |
80 #%!assert (nargoutchk (0, 1, 2, "struct"), stmax) | 80 %!assert (nargoutchk (0, 1, 2, "struct"), stmax) |
81 |