Mercurial > octave
changeset 23598:287b07229aff
update test for handles to nested functions
* no_closure.m, nest.tst: Turn %!error checks in to %!tests (one known
bug, one now working). Check additional features.
author | John W. Eaton <jwe@octave.org> |
---|---|
date | Fri, 09 Jun 2017 11:36:34 -0400 |
parents | 0f4d3b06464c |
children | 5cb3a2bb5e1e |
files | test/nest/nest.tst test/nest/no_closure.m |
diffstat | 2 files changed, 24 insertions(+), 8 deletions(-) [+] |
line wrap: on
line diff
--- a/test/nest/nest.tst Wed Jun 14 09:15:53 2017 -0700 +++ b/test/nest/nest.tst Fri Jun 09 11:36:34 2017 -0400 @@ -51,8 +51,16 @@ %!assert (nest_eval ("x = 5;", "y = 6;"), 5) %!assert (nest_eval ("x = -5; x = abs (x);", "y = 6;"), 5) +%!test +%! f = no_closure (0); +%! assert (f("foo"), "nested foo"); +%! assert (f("foo"), "nested foo"); + +%!test <39257> +%! f = no_closure (1); +%! assert (f(), "nested"); +%! assert (f("foo"), "nested foo"); + %!error <D' undefined near line 7> scope2 -%!error <handles to nested functions are not yet supported> no_closure (0) -%!error <handles to nested functions are not yet supported> no_closure (1) %!error <can not add variable "y" to a static workspace> nest_eval ("y = 5;", "") %!error <can not add variable "y" to a static workspace> nest_eval ("y;", "")
--- a/test/nest/no_closure.m Wed Jun 14 09:15:53 2017 -0700 +++ b/test/nest/no_closure.m Fri Jun 09 11:36:34 2017 -0400 @@ -1,11 +1,19 @@ # no_closure.m -function no_closure (n) - if n == 0 - x = @no_closure; +function r = no_closure (n) + if (ischar (n)) + r = nested (n); else - f = @no_closure; + if (n == 0) + r = @no_closure; + elseif (n == 1) + r = @nested; + endif endif - - function f + function r = nested (x) + if (nargin == 1) + r = ["nested ", x]; + else + r = "nested"; + endif endfunction endfunction