# HG changeset patch # User A.R. Burgers # Date 1681383336 -7200 # Thu Apr 13 12:55:36 2023 +0200 # Node ID 85755a5d7bbafde337bac7cb15eeded4a4c3bae6 # Parent c5b57a82a17cfb93d2dac06c678871da1368dedd add tests for bug 63841 * new subdir test/bug-63841 * add test/bug-63841 to build system diff -r c5b57a82a17c -r 85755a5d7bba test/Makefile.am --- a/test/Makefile.am Thu Apr 13 09:11:48 2023 +0200 +++ b/test/Makefile.am Thu Apr 13 12:55:36 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 c5b57a82a17c -r 85755a5d7bba 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 12:55:36 2023 +0200 @@ -0,0 +1,4 @@ +function y = cls2_b63841 () + y.a_property = 1; + y = class (y, 'cls2_b63841'); +end diff -r c5b57a82a17c -r 85755a5d7bba 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 12:55:36 2023 +0200 @@ -0,0 +1,3 @@ +function varargout = subsref(obj, s) + varargout = {nargout, s(1).type, 'arg3'}; +end diff -r c5b57a82a17c -r 85755a5d7bba 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 12:55:36 2023 +0200 @@ -0,0 +1,154 @@ +######################################################################## +## +## Copyright (C) 2017-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 c5b57a82a17c -r 85755a5d7bba 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 12:55:36 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 c5b57a82a17c -r 85755a5d7bba test/bug-63841/module.mk --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/test/bug-63841/module.mk Thu Apr 13 12:55:36 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)