# HG changeset patch # User A.R. Burgers # Date 1681413704 -7200 # Thu Apr 13 21:21:44 2023 +0200 # Node ID 64399e267d7a006dc91032b690bd6022ec890f3b # Parent 21751aa1527304db9d45583fdac2c353756d217b add tests for bug 63841 * new subdir test/bug-63841 * add test/bug-63841 to build system diff -r 21751aa15273 -r 64399e267d7a test/Makefile.am --- a/test/Makefile.am Thu Apr 13 14:50:45 2023 +0200 +++ b/test/Makefile.am Thu Apr 13 21:21:44 2023 +0200 @@ -107,6 +107,7 @@ include bug-60882/module.mk include bug-61105/module.mk include bug-61191/module.mk +include bug-63841/module.mk include class-concat/module.mk include classdef/module.mk include classdef-multiple-inheritance/module.mk diff -r 21751aa15273 -r 64399e267d7a test/bug-63841/@cls2_b63841/cls2_b63841.m --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/test/bug-63841/@cls2_b63841/cls2_b63841.m Thu Apr 13 21:21:44 2023 +0200 @@ -0,0 +1,4 @@ +function y = cls2_b63841 () + y.a_property = 1; + y = class (y, 'cls2_b63841'); +end diff -r 21751aa15273 -r 64399e267d7a test/bug-63841/@cls2_b63841/subsref.m --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/test/bug-63841/@cls2_b63841/subsref.m Thu Apr 13 21:21:44 2023 +0200 @@ -0,0 +1,3 @@ +function varargout = subsref(obj, s) + varargout = {nargout, s(1).type, 'arg3'}; +end diff -r 21751aa15273 -r 64399e267d7a test/bug-63841/bug-63841.tst --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/test/bug-63841/bug-63841.tst Thu Apr 13 21:21:44 2023 +0200 @@ -0,0 +1,154 @@ +######################################################################## +## +## Copyright (C) 2023-2023 The Octave Project Developers +## +## See the file COPYRIGHT.md in the top-level directory of this +## distribution or . +## +## This file is part of Octave. +## +## Octave is free software: you can redistribute it and/or modify it +## under the terms of the GNU General Public License as published by +## the Free Software Foundation, either version 3 of the License, or +## (at your option) any later version. +## +## Octave is distributed in the hope that it will be useful, but +## WITHOUT ANY WARRANTY; without even the implied warranty of +## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +## GNU General Public License for more details. +## +## You should have received a copy of the GNU General Public License +## along with Octave; see the file COPYING. If not, see +## . +## +######################################################################## + +%% +%% Testing nargout when calling subsref for classdef classes +%% + +%!test <*63841> +%! cm = containers.Map; +%! cm('first') = cls_b63841; +%! a_63841 = 0; +%! try +%! if cm('first').a_property +%! a_63841 = 1; +%! endif +%! catch +%! end_try_catch +%! assert (a_63841, 1); + +%!test <*63841> +%! ti = cls_b63841; +%! a = 0; +%! if ti(1:5).a_property +%! a = 1; +%! endif +%! assert (a, 1); + +%!test <*63841> +%! ti = cls_b63841; +%! a = 0; +%! for x = ti(1:5).a_property +%! a = 1; +%! endfor +%! assert (a, 1); + +%!test <*63841> +%! ti = cls_b63841; +%! [n_arg, b] = ti.call_a_method; +%! assert (n_arg, 2); + +%!test <*63841> +%! ti = cls_b63841; +%! [n_arg, b] = ti{1}; +%! assert (n_arg, 2); + +%!test <*63841> +%! ti = cls_b63841; +%! [n_arg, b] = ti(1); +%! assert (n_arg, 2); + +%!test <*63841> +%! ti = cls_b63841; +%! [n_arg, b] = ti(1).a_property; +%! assert (n_arg, 2); + +%!test <*63841> +%! ti = cls_b63841; +%! [n_arg, b, c] = ti.call_a_method; +%! assert (n_arg, 3); + +%!test <*63841> +%! ti = cls_b63841; +%! [n_arg, b, c] = ti{1}; +%! assert (n_arg, 3); + +%!test <*63841> +%! ti = cls_b63841; +%! [n_arg, b, c] = ti(1); +%! assert (n_arg, 3); + +%% +%% Testing nargout when calling subsref for struct-based classes +%% + +%!test <*63841> +%! ti = cls2_b63841; +%! a = 0; +%! if ti(1:5).a_property +%! a = 1; +%! endif +%! assert (a, 1); + +%!test <*63841> +%! ti = cls2_b63841; +%! a = 0; +%! for x = ti(1:5).a_property +%! a = 1; +%! endfor +%! assert (a, 1); + +%!test <*63841> +%! ti = cls2_b63841; +%! [n_arg, b] = ti.call_a_method; +%! assert (n_arg, 2); + +%!test <*63841> +%! ti = cls2_b63841; +%! [n_arg, b] = ti{1}; +%! assert (n_arg, 2); + +%!test <*63841> +%! ti = cls2_b63841; +%! [n_arg, b] = ti(1); +%! assert (n_arg, 2); + +%!test <*63841> +%! ti = cls2_b63841; +%! [n_arg, b] = ti(1).a_property; +%! assert (n_arg, 2); + +%% +%% Different expressions that should produce errors +%% + +%!shared ti +%! ti = cls_b63841; + +%% binary operator +%!error 1 + ti(1:3).a_property +%!error ti(1:3).a_property + 1 +%!error ti(1:3).a_property + ti(1:3).a_property + +%% unary postfix operator +%!error ti(1:3).a_property' + +%% unary prefix operator +%!error ~ti(1:3).a_property + +%% compound binary operation +%!error 3*ti(1:3).a_property' +%!error ti(1:3).a_property'*3 + diff -r 21751aa15273 -r 64399e267d7a test/bug-63841/cls_b63841.m --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/test/bug-63841/cls_b63841.m Thu Apr 13 21:21:44 2023 +0200 @@ -0,0 +1,10 @@ +classdef cls_b63841 + properties + a_property = 1; + end + methods + function varargout = subsref(obj, s) + varargout = {nargout, s(1).type, 'arg3'}; + end + end +end diff -r 21751aa15273 -r 64399e267d7a test/bug-63841/module.mk --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/test/bug-63841/module.mk Thu Apr 13 21:21:44 2023 +0200 @@ -0,0 +1,7 @@ +bug_63841_TEST_FILES = \ + %reldir%/@cls2_b63841/cls2_b63841.m \ + %reldir%/@cls2_b63841/subsref.m \ + %reldir%/bug-63841.tst \ + %reldir%/cls_b63841.m + +TEST_FILES += $(bug_63841_TEST_FILES)