Mercurial > hg > octave-nkf
diff scripts/strings/validatestring.m @ 18714:d227178a0d40
validatestring.m: Change error message to follow Octave guidelines (bug #41484).
* validatestring.m: Adapted the error messages to not mention validatestring
when not needed. Modified %!tests to comply with the new output.
* contributors.in: Add Eugenio Gianniti to list of contributors.
author | Eugenio Gianniti <eugenio.gianniti@mail.polimi.it> |
---|---|
date | Fri, 28 Feb 2014 19:24:10 +0100 |
parents | d63878346099 |
children | efd5cf93013b |
line wrap: on
line diff
--- a/scripts/strings/validatestring.m +++ b/scripts/strings/validatestring.m @@ -100,22 +100,21 @@ ## Make static part of error string that uses funcname, varname, and position errstr = ""; if (! isempty (funcname)) - errstr = sprintf ("Function: %s ", funcname); + errstr = [funcname ": "]; endif if (! isempty (varname)) - errstr = sprintf ("%sVariable: %s ", errstr, varname); + errstr = [errstr varname " "]; + else + errstr = sprintf ("%s'%s' ", errstr, str); endif if (position > 0) - errstr = sprintf ("%sArgument position %d ", errstr, position); - endif - if (! isempty (errstr)) - errstr(end:end+1) = ":\n"; + errstr = sprintf ("%s(argument #%i) ", errstr, position); endif matches = strncmpi (str, strarray(:), length (str)); nmatches = sum (matches); if (nmatches == 0) - error ("validatestring: %s'%s' does not match any of\n%s", errstr, str, + error ("%sdoes not match any of\n%s", errstr, sprintf ("%s, ", strarray{:})(1:end-2)); elseif (nmatches == 1) str = strarray{matches}; @@ -130,8 +129,8 @@ if (all (submatch)) str = short_str; else - error ("validatestring: %smultiple unique matches were found for '%s':\n%s", - errstr, str, sprintf ("%s, ", strarray{match_idx})(1:end-2)); + error ("%sallows multiple unique matches:\n%s", + errstr, sprintf ("%s, ", strarray{match_idx})(1:end-2)); endif endif @@ -147,10 +146,10 @@ %!assert (validatestring ("d", strarray), "def") %!error <'xyz' does not match any> validatestring ("xyz", strarray) -%!error <Function: DUMMY_TEST> validatestring ("xyz", strarray, "DUMMY_TEST") -%!error <Function: DUMMY_TEST Variable: DUMMY_VAR:> validatestring ("xyz", strarray, "DUMMY_TEST", "DUMMY_VAR") -%!error <Function: DUMMY_TEST Variable: DUMMY_VAR Argument position 5> validatestring ("xyz", strarray, "DUMMY_TEST", "DUMMY_VAR", 5) -%!error <multiple unique matches were found for 'abc'> validatestring ("abc", strarray) +%!error <DUMMY_TEST: 'xyz' does not> validatestring ("xyz", strarray, "DUMMY_TEST") +%!error <DUMMY_TEST: DUMMY_VAR does> validatestring ("xyz", strarray, "DUMMY_TEST", "DUMMY_VAR") +%!error <DUMMY_TEST: DUMMY_VAR \(argument #5\) does> validatestring ("xyz", strarray, "DUMMY_TEST", "DUMMY_VAR", 5) +%!error <'abc' allows multiple unique matches> validatestring ("abc", strarray) %% Test input validation %!error validatestring ("xyz")