changeset 20274:48284e32530b

test: Add tests for 'echo' and 'completion_matches' builtins * input.cc: Add %!tests for the 'echo' and 'completion_matches' builtins.
author Mike Miller <mtmiller@octave.org>
date Sat, 30 May 2015 20:06:27 -0400
parents a3bf35bd5b44
children 35fc5ea83030
files libinterp/corefcn/input.cc
diffstat 1 files changed, 62 insertions(+), 0 deletions(-) [+]
line wrap: on
line diff
--- a/libinterp/corefcn/input.cc	Sat May 30 13:50:14 2015 +0100
+++ b/libinterp/corefcn/input.cc	Sat May 30 20:06:27 2015 -0400
@@ -1028,6 +1028,53 @@
   return retval;
 }
 
+/*
+%!test
+%! state = echo_executing_commands ();
+%! unwind_protect
+%!   echo ();
+%!   s1 = echo_executing_commands ();
+%!   assert (s1 != state);
+%!   echo ();
+%!   s2 = echo_executing_commands ();
+%!   assert (s2 != s1);
+%! unwind_protect_cleanup
+%!   echo_executing_commands (state);
+%! end_unwind_protect
+
+%!test
+%! state = echo_executing_commands ();
+%! unwind_protect
+%!   echo ("off");
+%!   assert (echo_executing_commands () == 0);
+%!   echo ("on");
+%!   assert (echo_executing_commands () != 0);
+%!   echo ("off");
+%!   assert (echo_executing_commands () == 0);
+%! unwind_protect_cleanup
+%!   echo_executing_commands (state);
+%! end_unwind_protect
+
+%!#test  # FIXME: Uncommend when ug #45209 is fixed
+%! state = echo_executing_commands ();
+%! unwind_protect
+%!   echo ("on", "all");
+%!   assert (echo_executing_commands () != 0);
+%!   echo ("off", "all");
+%!   assert (echo_executing_commands () == 0);
+%! unwind_protect_cleanup
+%!   echo_executing_commands (state);
+%! end_unwind_protect
+
+%!error echo ([])
+%!error echo (0)
+%!error echo ("")
+%!error echo ("Octave")
+%!error echo ("off", "invalid")
+%!error echo ("on", "invalid")
+%!error echo ("on", "all", "all")
+*/
+
 DEFUN (__echostate__, , ,
        "-*- texinfo -*-\n\
 @deftypefn {Built-in Function} {@var{state} =} __echostate__ ()\n\
@@ -1113,6 +1160,21 @@
   return retval;
 }
 
+/*
+%!assert (ischar (completion_matches ("")))
+%!assert (ischar (completion_matches ("a")))
+%!assert (ischar (completion_matches (" ")))
+%!assert (isempty (completion_matches (" ")))
+%!assert (any (strcmp ("abs", deblank (cellstr (completion_matches (""))))))
+%!assert (any (strcmp ("abs", deblank (cellstr (completion_matches ("a"))))))
+%!assert (any (strcmp ("abs", deblank (cellstr (completion_matches ("ab"))))))
+%!assert (any (strcmp ("abs", deblank (cellstr (completion_matches ("abs"))))))
+%!assert (! any (strcmp ("abs", deblank (cellstr (completion_matches ("absa"))))))
+
+%!error completion_matches ()
+%!error completion_matches (1, 2)
+*/
+
 DEFUN (readline_read_init_file, args, ,
        "-*- texinfo -*-\n\
 @deftypefn {Built-in Function} {} readline_read_init_file (@var{file})\n\