# HG changeset patch # User A.R. Burgers and Fernando Alvarruiz # Date 1681543119 -7200 # Sat Apr 15 09:18:39 2023 +0200 # Node ID 961eb80fbce14856a15237f85174288b3f36aab8 # Parent a5413268eb471d14968a0564e8021086ad3cc683 add tests for bug 63841 * new subdir test/bug-63841 * add test/bug-63841 to build system diff -r a5413268eb47 -r 961eb80fbce1 test/Makefile.am --- a/test/Makefile.am Fri Apr 14 21:24:06 2023 -0400 +++ b/test/Makefile.am Sat Apr 15 09:18:39 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 a5413268eb47 -r 961eb80fbce1 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 Sat Apr 15 09:18:39 2023 +0200 @@ -0,0 +1,4 @@ +function y = cls2_b63841 () + y.a_property = 1; + y = class (y, 'cls2_b63841'); +end diff -r a5413268eb47 -r 961eb80fbce1 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 Sat Apr 15 09:18:39 2023 +0200 @@ -0,0 +1,3 @@ +function varargout = subsref(obj, s) + varargout = {nargout, s(1).type, 'arg3'}; +end diff -r a5413268eb47 -r 961eb80fbce1 test/bug-63841/bug-63841.tst --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/test/bug-63841/bug-63841.tst Sat Apr 15 09:18:39 2023 +0200 @@ -0,0 +1,162 @@ +######################################################################## +## +## 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 (classdef and struct-based classes) +%% + +%!shared ti, ti2 +%! ti = cls_b63841; +%! ti2 = cls2_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 +%!error 1 + ti2(1:3).a_property +%!error ti2(1:3).a_property + 1 +%!error ti2(1:3).a_property + ti2(1:3).a_property + +%% unary postfix operator +%!error ti(1:3).a_property' +%!error ti2(1:3).a_property' + +%% unary prefix operator +%!error ~ti(1:3).a_property +%!error ~ti2(1:3).a_property + +%% compound binary operation +%!error 3*ti(1:3).a_property' +%!error ti(1:3).a_property'*3 +%!error 3*ti2(1:3).a_property' +%!error ti2(1:3).a_property'*3 + diff -r a5413268eb47 -r 961eb80fbce1 test/bug-63841/cls_b63841.m --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/test/bug-63841/cls_b63841.m Sat Apr 15 09:18:39 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 a5413268eb47 -r 961eb80fbce1 test/bug-63841/module.mk --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/test/bug-63841/module.mk Sat Apr 15 09:18:39 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)