Mercurial > hg > octave-terminal
changeset 13094:7d4f5a033330
new tests for utils.cc
* utils.cc: New tests.
author | John W. Eaton <jwe@octave.org> |
---|---|
date | Sun, 04 Sep 2011 01:19:09 -0400 |
parents | 1a21c4c5eeeb |
children | 32fdd834c09a |
files | src/utils.cc |
diffstat | 1 files changed, 133 insertions(+), 0 deletions(-) [+] |
line wrap: on
line diff
--- a/src/utils.cc +++ b/src/utils.cc @@ -114,6 +114,17 @@ return retval; } +/* +%!error isvarname (); +%!error isvarname ("foo", "bar"); + +%!assert (isvarname ("foo"), true); +%!assert (isvarname ("_foo"), true); +%!assert (isvarname ("_1"), true); +%!assert (isvarname ("1foo"), false); +%!assert (isvarname (""), false); +*/ + // Return TRUE if F and G are both names for the same file. bool @@ -325,6 +336,24 @@ return retval; } +/* +%!error file_in_loadpath (); +%!error file_in_loadpath ("foo", "bar", 1); + +%!test +%! f = file_in_loadpath ("plot.m"); +%! assert (ischar (f)); +%! assert (! isempty (f)); + +%!test +%! f = file_in_loadpath ("$$probably_!!_not_&&_a_!!_file$$"); +%! assert (f, ""); + +%!test +%! lst = file_in_loadpath ("$$probably_!!_not_&&_a_!!_file$$", "all"); +%! assert (lst, {}); +*/ + DEFUN (file_in_path, args, , "-*- texinfo -*-\n\ @deftypefn {Built-in Function} {} file_in_path (@var{path}, @var{file})\n\ @@ -390,6 +419,25 @@ return retval; } +/* +%!error file_in_path (); +%!error file_in_path ("foo"); +%!error file_in_path ("foo", "bar", "baz", 1); + +%!test +%! f = file_in_path (path (), "plot.m"); +%! assert (ischar (f)); +%! assert (! isempty (f)); + +%!test +%! f = file_in_path (path (), "$$probably_!!_not_&&_a_!!_file$$"); +%! assert (f, ""); + +%!test +%! lst = file_in_path (path (), "$$probably_!!_not_&&_a_!!_file$$", "all"); +%! assert (lst, {}); +*/ + std::string file_in_path (const std::string& name, const std::string& suffix) { @@ -623,6 +671,20 @@ return retval; } +/* +%!error do_string_escapes (); +%!error do_string_escapes ("foo", "bar"); + +%!assert (do_string_escapes ('foo\nbar'), "foo\nbar"); +%!assert (do_string_escapes ("foo\\nbar"), "foo\nbar"); +%!assert (do_string_escapes ("foo\\nbar"), ["foo", char(10), "bar"]); + +%!assert (do_string_escapes ('\a\b\f\n\r\t\v'), "\a\b\f\n\r\t\v"); +%!assert (do_string_escapes ("\\a\\b\\f\\n\\r\\t\\v"), "\a\b\f\n\r\t\v"); +%!assert (do_string_escapes ("\\a\\b\\f\\n\\r\\t\\v"), +%! char ([7, 8, 12, 10, 13, 9, 11])); +*/ + const char * undo_string_escape (char c) { @@ -729,6 +791,20 @@ return retval; } +/* +%!error undo_string_escapes (); +%!error undo_string_escapes ("foo", "bar"); + +%!assert (undo_string_escapes ("foo\nbar"), 'foo\nbar'); +%!assert (undo_string_escapes ("foo\nbar"), "foo\\nbar"); +%!assert (undo_string_escapes (["foo", char(10), "bar"]), "foo\\nbar"); + +%!assert (undo_string_escapes ("\a\b\f\n\r\t\v"), '\a\b\f\n\r\t\v'); +%!assert (undo_string_escapes ("\a\b\f\n\r\t\v"), "\\a\\b\\f\\n\\r\\t\\v"); +%!assert (undo_string_escapes (char ([7, 8, 12, 10, 13, 9, 11])), +%! "\\a\\b\\f\\n\\r\\t\\v"); +*/ + DEFUN (is_absolute_filename, args, , "-*- texinfo -*-\n\ @deftypefn {Built-in Function} {} is_absolute_filename (@var{file})\n\ @@ -747,6 +823,13 @@ return retval; } +/* +%!error is_absolute_filename (); +%!error is_absolute_filename ("foo", "bar"); + +FIXME -- we need system-dependent tests here. +*/ + DEFUN (is_rooted_relative_filename, args, , "-*- texinfo -*-\n\ @deftypefn {Built-in Function} {} is_rooted_relative_filename (@var{file})\n\ @@ -765,6 +848,13 @@ return retval; } +/* +%!error is_rooted_relative_filename (); +%!error is_rooted_relative_filename ("foo", "bar"); + +FIXME -- we need system-dependent tests here. +*/ + DEFUN (make_absolute_filename, args, , "-*- texinfo -*-\n\ @deftypefn {Built-in Function} {} make_absolute_filename (@var{file})\n\ @@ -789,6 +879,13 @@ return retval; } +/* +%!error make_absolute_filename (); +%!error make_absolute_filename ("foo", "bar"); + +FIXME -- we need system-dependent tests here. +*/ + DEFUN (find_dir_in_path, args, , "-*- texinfo -*-\n\ @deftypefn {Built-in Function} {} find_dir_in_path (@var{dir})\n\ @@ -829,6 +926,13 @@ return retval; } +/* +%!error find_dir_in_path (); +%!error find_dir_in_path ("foo", "bar", 1); + +FIXME -- need to create tests using current path, pathsep, and dirsep. +*/ + DEFUNX ("errno", Ferrno, args, , "-*- texinfo -*-\n\ @deftypefn {Built-in Function} {@var{err} =} errno ()\n\ @@ -873,6 +977,21 @@ return retval; } +/* +%!error errno ("foo", 1); + +%!assert (isnumeric (errno ())); + +%!test +%! lst = errno_list (); +%! fns = fieldnames (lst); +%! oldval = errno (fns{1}); +%! assert (isnumeric (oldval)); +%! errno (oldval); +%! newval = errno (); +%! assert (oldval, newval); +*/ + DEFUN (errno_list, args, , "-*- texinfo -*-\n\ @deftypefn {Built-in Function} {} errno_list ()\n\ @@ -889,6 +1008,12 @@ return retval; } +/* +%!error errno_list ("foo"); + +%!assert (isstruct (errno_list ())); +*/ + static void check_dimensions (octave_idx_type& nr, octave_idx_type& nc, const char *warnfor) { @@ -1352,6 +1477,14 @@ return retval; } +/* +%!error isindex (); + +%!assert (isindex ([1, 2, 3])); +%!assert (isindex (1:3)); +%!assert (isindex ([1, 2, -3]), false); +*/ + octave_value_list do_simple_cellfun (octave_value_list (*fun) (const octave_value_list&, int), const char *fun_name, const octave_value_list& args,