Mercurial > octave
annotate scripts/legacy/genvarname.m @ 32002:939e5d952675
Use upper/lower in preference to toupper/tolower to match Matlab.
* mappers.cc (Fupper, Flower): Functions renamed from toupper/tolower and now
use "DEFUN" macro. Change DEFALIAS to correctly map toXXX to XXX. Update all
BIST tests.
* func.txi, strings.txi: Update manual.
* cellfun.cc, utils.cc, Map.m, idivide.m, integral.m, integral2.m,
integral3.m, interp1.m, quad2d.m, quadgk.m, rng.m, griddata.m, griddatan.m,
listdlg.m, movegui.m, __file_filter__.m, uigetfile.m, uisetfont.m,
__unimplemented__.m, colormap.m, imformats.m, imshow.m, __imread__.m,
__imwrite__.m, rgbplot.m, javaclasspath.m, genvarname.m, edit.m, inputParser.m,
license.m, open.m, parseparams.m, unpack.m, validateattributes.m,
__all_opts__.m, get_description.m, get_forge_pkg.m, camorbit.m, daspect.m,
datetick.m, pbaspect.m, __tickangle__.m, rticks.m, thetaticks.m, xticks.m,
yticks.m, zticks.m, camlight.m, colorbar.m, isocaps.m, isosurface.m,
__add_datasource__.m, __patch__.m, __scatter__.m, reducepatch.m, smooth3.m,
surfl.m, hgload.m, hold.m, openfig.m, __add_default_menu__.m,
__print_parse_opts__.m, refreshdata.m, saveas.m, struct2hdl.m, movfun.m,
stft.m, eigs.m, ichol.m, ilu.m, gammainc.m, gallery.m, corrcoef.m, iqr.m,
normalize.m, base2dec.m, index.m, regexptranslate.m, strsplit.m, datestr.m,
mk-sparse-tst.sh: Replace toupper/tolower with upper/lower in Octave code.
author | Rik <rik@octave.org> |
---|---|
date | Wed, 12 Apr 2023 15:34:43 -0700 |
parents | 597f3ee61a48 |
children | 2e484f9f1f18 |
rev | line source |
---|---|
27923
bd51beb6205e
update formatting of copyright notices
John W. Eaton <jwe@octave.org>
parents:
27919
diff
changeset
|
1 ######################################################################## |
bd51beb6205e
update formatting of copyright notices
John W. Eaton <jwe@octave.org>
parents:
27919
diff
changeset
|
2 ## |
31706
597f3ee61a48
update Octave Project Developers copyright for the new year
John W. Eaton <jwe@octave.org>
parents:
30564
diff
changeset
|
3 ## Copyright (C) 2008-2023 The Octave Project Developers |
27918
b442ec6dda5c
use centralized file for copyright info for individual contributors
John W. Eaton <jwe@octave.org>
parents:
26376
diff
changeset
|
4 ## |
27923
bd51beb6205e
update formatting of copyright notices
John W. Eaton <jwe@octave.org>
parents:
27919
diff
changeset
|
5 ## See the file COPYRIGHT.md in the top-level directory of this |
bd51beb6205e
update formatting of copyright notices
John W. Eaton <jwe@octave.org>
parents:
27919
diff
changeset
|
6 ## distribution or <https://octave.org/copyright/>. |
7657 | 7 ## |
8 ## This file is part of Octave. | |
9 ## | |
24534
194eb4bd202b
maint: Update punctuation for GPL v3 license text.
Rik <rik@octave.org>
parents:
23220
diff
changeset
|
10 ## Octave is free software: you can redistribute it and/or modify it |
7657 | 11 ## under the terms of the GNU General Public License as published by |
24534
194eb4bd202b
maint: Update punctuation for GPL v3 license text.
Rik <rik@octave.org>
parents:
23220
diff
changeset
|
12 ## the Free Software Foundation, either version 3 of the License, or |
22755
3a2b891d0b33
maint: Standardize Copyright formatting.
Rik <rik@octave.org>
parents:
22323
diff
changeset
|
13 ## (at your option) any later version. |
7657 | 14 ## |
15 ## Octave is distributed in the hope that it will be useful, but | |
16 ## WITHOUT ANY WARRANTY; without even the implied warranty of | |
22755
3a2b891d0b33
maint: Standardize Copyright formatting.
Rik <rik@octave.org>
parents:
22323
diff
changeset
|
17 ## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
3a2b891d0b33
maint: Standardize Copyright formatting.
Rik <rik@octave.org>
parents:
22323
diff
changeset
|
18 ## GNU General Public License for more details. |
7657 | 19 ## |
20 ## You should have received a copy of the GNU General Public License | |
21 ## along with Octave; see the file COPYING. If not, see | |
24534
194eb4bd202b
maint: Update punctuation for GPL v3 license text.
Rik <rik@octave.org>
parents:
23220
diff
changeset
|
22 ## <https://www.gnu.org/licenses/>. |
27923
bd51beb6205e
update formatting of copyright notices
John W. Eaton <jwe@octave.org>
parents:
27919
diff
changeset
|
23 ## |
bd51beb6205e
update formatting of copyright notices
John W. Eaton <jwe@octave.org>
parents:
27919
diff
changeset
|
24 ######################################################################## |
7657 | 25 |
26 ## -*- texinfo -*- | |
20852
516bb87ea72e
2015 Code Sprint: remove class of function from docstring for all m-files.
Rik <rik@octave.org>
parents:
20735
diff
changeset
|
27 ## @deftypefn {} {@var{varname} =} genvarname (@var{str}) |
516bb87ea72e
2015 Code Sprint: remove class of function from docstring for all m-files.
Rik <rik@octave.org>
parents:
20735
diff
changeset
|
28 ## @deftypefnx {} {@var{varname} =} genvarname (@var{str}, @var{exclusions}) |
26202
368dc1142072
makeValidName.m, makeUniqueStrings.m: Clean up functions to use Octave conventions.
Rik <rik@octave.org>
parents:
25054
diff
changeset
|
29 ## |
368dc1142072
makeValidName.m, makeUniqueStrings.m: Clean up functions to use Octave conventions.
Rik <rik@octave.org>
parents:
25054
diff
changeset
|
30 ## This function is obsolete. Use @code{matlab.lang.makeValidName} or |
368dc1142072
makeValidName.m, makeUniqueStrings.m: Clean up functions to use Octave conventions.
Rik <rik@octave.org>
parents:
25054
diff
changeset
|
31 ## @code{matlab.lang.makeUniqueStrings} instead. |
368dc1142072
makeValidName.m, makeUniqueStrings.m: Clean up functions to use Octave conventions.
Rik <rik@octave.org>
parents:
25054
diff
changeset
|
32 ## |
19194 | 33 ## Create valid unique variable name(s) from @var{str}. |
7657 | 34 ## |
20164
df437a52bcaf
doc: Update more docstrings to have one sentence summary as first line.
Rik <rik@octave.org>
parents:
19833
diff
changeset
|
35 ## If @var{str} is a cellstr, then a unique variable is created for each cell |
df437a52bcaf
doc: Update more docstrings to have one sentence summary as first line.
Rik <rik@octave.org>
parents:
19833
diff
changeset
|
36 ## in @var{str}. |
7657 | 37 ## |
38 ## @example | |
39 ## @group | |
40 ## genvarname (@{"foo", "foo"@}) | |
14327
4d917a6a858b
doc: Use Octave coding conventions in @example blocks of docstrings.
Rik <octave@nomad.inbox5.com>
parents:
14138
diff
changeset
|
41 ## @result{} |
4d917a6a858b
doc: Use Octave coding conventions in @example blocks of docstrings.
Rik <octave@nomad.inbox5.com>
parents:
14138
diff
changeset
|
42 ## @{ |
4d917a6a858b
doc: Use Octave coding conventions in @example blocks of docstrings.
Rik <octave@nomad.inbox5.com>
parents:
14138
diff
changeset
|
43 ## [1,1] = foo |
4d917a6a858b
doc: Use Octave coding conventions in @example blocks of docstrings.
Rik <octave@nomad.inbox5.com>
parents:
14138
diff
changeset
|
44 ## [1,2] = foo1 |
4d917a6a858b
doc: Use Octave coding conventions in @example blocks of docstrings.
Rik <octave@nomad.inbox5.com>
parents:
14138
diff
changeset
|
45 ## @} |
7657 | 46 ## @end group |
47 ## @end example | |
48 ## | |
19194 | 49 ## If @var{exclusions} is given, then the variable(s) will be unique to each |
20164
df437a52bcaf
doc: Update more docstrings to have one sentence summary as first line.
Rik <rik@octave.org>
parents:
19833
diff
changeset
|
50 ## other and to @var{exclusions} (@var{exclusions} may be either a string or a |
df437a52bcaf
doc: Update more docstrings to have one sentence summary as first line.
Rik <rik@octave.org>
parents:
19833
diff
changeset
|
51 ## cellstr). |
19194 | 52 ## |
53 ## @example | |
54 ## @group | |
55 ## x = 3.141; | |
56 ## genvarname ("x", who ()) | |
57 ## @result{} x1 | |
58 ## @end group | |
59 ## @end example | |
60 ## | |
61 ## Note that the result is a char array or cell array of strings, not the | |
20181
aa36fb998a4d
maint: Remove unnecessary whitespace at end of lines.
Rik <rik@octave.org>
parents:
20164
diff
changeset
|
62 ## variables themselves. To define a variable, @code{eval()} can be used. |
24985
d85b2485af9e
doc: grammarcheck m-files ahead of 4.4 release.
Rik <rik@octave.org>
parents:
24534
diff
changeset
|
63 ## The following trivial example sets @code{x} to 42. |
7657 | 64 ## |
65 ## @example | |
66 ## @group | |
67 ## name = genvarname ("x"); | |
14327
4d917a6a858b
doc: Use Octave coding conventions in @example blocks of docstrings.
Rik <octave@nomad.inbox5.com>
parents:
14138
diff
changeset
|
68 ## eval ([name " = 42"]); |
4d917a6a858b
doc: Use Octave coding conventions in @example blocks of docstrings.
Rik <octave@nomad.inbox5.com>
parents:
14138
diff
changeset
|
69 ## @result{} x = 42 |
7657 | 70 ## @end group |
71 ## @end example | |
72 ## | |
19194 | 73 ## This can be useful for creating unique struct field names. |
7657 | 74 ## |
75 ## @example | |
76 ## @group | |
77 ## x = struct (); | |
78 ## for i = 1:3 | |
79 ## x.(genvarname ("a", fieldnames (x))) = i; | |
80 ## endfor | |
14327
4d917a6a858b
doc: Use Octave coding conventions in @example blocks of docstrings.
Rik <octave@nomad.inbox5.com>
parents:
14138
diff
changeset
|
81 ## @result{} x = |
4d917a6a858b
doc: Use Octave coding conventions in @example blocks of docstrings.
Rik <octave@nomad.inbox5.com>
parents:
14138
diff
changeset
|
82 ## @{ |
4d917a6a858b
doc: Use Octave coding conventions in @example blocks of docstrings.
Rik <octave@nomad.inbox5.com>
parents:
14138
diff
changeset
|
83 ## a = 1 |
4d917a6a858b
doc: Use Octave coding conventions in @example blocks of docstrings.
Rik <octave@nomad.inbox5.com>
parents:
14138
diff
changeset
|
84 ## a1 = 2 |
4d917a6a858b
doc: Use Octave coding conventions in @example blocks of docstrings.
Rik <octave@nomad.inbox5.com>
parents:
14138
diff
changeset
|
85 ## a2 = 3 |
4d917a6a858b
doc: Use Octave coding conventions in @example blocks of docstrings.
Rik <octave@nomad.inbox5.com>
parents:
14138
diff
changeset
|
86 ## @} |
7657 | 87 ## @end group |
88 ## @end example | |
89 ## | |
19194 | 90 ## Since variable names may only contain letters, digits, and underscores, |
91 ## @code{genvarname} will replace any sequence of disallowed characters with | |
20164
df437a52bcaf
doc: Update more docstrings to have one sentence summary as first line.
Rik <rik@octave.org>
parents:
19833
diff
changeset
|
92 ## an underscore. Also, variables may not begin with a digit; in this case |
df437a52bcaf
doc: Update more docstrings to have one sentence summary as first line.
Rik <rik@octave.org>
parents:
19833
diff
changeset
|
93 ## an @samp{x} is added before the variable name. |
7657 | 94 ## |
17281
bc924baa2c4e
doc: Add new @qcode macro for code samples which are quoted.
Rik <rik@octave.org>
parents:
16994
diff
changeset
|
95 ## Variable names beginning and ending with two underscores @qcode{"__"} are |
19194 | 96 ## valid, but they are used internally by Octave and should generally be |
97 ## avoided; therefore, @code{genvarname} will not generate such names. | |
7657 | 98 ## |
19194 | 99 ## @code{genvarname} will also ensure that returned names do not clash with |
17281
bc924baa2c4e
doc: Add new @qcode macro for code samples which are quoted.
Rik <rik@octave.org>
parents:
16994
diff
changeset
|
100 ## keywords such as @qcode{"for"} and @qcode{"if"}. A number will be |
bc924baa2c4e
doc: Add new @qcode macro for code samples which are quoted.
Rik <rik@octave.org>
parents:
16994
diff
changeset
|
101 ## appended if necessary. Note, however, that this does @strong{not} include |
19194 | 102 ## function names such as @qcode{"sin"}. Such names should be included in |
103 ## @var{exclusions} if necessary. | |
26202
368dc1142072
makeValidName.m, makeUniqueStrings.m: Clean up functions to use Octave conventions.
Rik <rik@octave.org>
parents:
25054
diff
changeset
|
104 ## @seealso{matlab.lang.makeValidName, matlab.lang.makeUniqueStrings, |
368dc1142072
makeValidName.m, makeUniqueStrings.m: Clean up functions to use Octave conventions.
Rik <rik@octave.org>
parents:
25054
diff
changeset
|
105 ## namelengthmax, isvarname, iskeyword, exist, who, tempname, eval} |
7657 | 106 ## @end deftypefn |
107 | |
19194 | 108 function varname = genvarname (str, exclusions = {}) |
109 | |
28458
ef8cf8dda0ba
warn if legacy inline, genvarname or vectorize functions are used
John W. Eaton <jwe@octave.org>
parents:
27923
diff
changeset
|
110 persistent warned = false; |
ef8cf8dda0ba
warn if legacy inline, genvarname or vectorize functions are used
John W. Eaton <jwe@octave.org>
parents:
27923
diff
changeset
|
111 if (! warned) |
ef8cf8dda0ba
warn if legacy inline, genvarname or vectorize functions are used
John W. Eaton <jwe@octave.org>
parents:
27923
diff
changeset
|
112 warned = true; |
ef8cf8dda0ba
warn if legacy inline, genvarname or vectorize functions are used
John W. Eaton <jwe@octave.org>
parents:
27923
diff
changeset
|
113 warning ("Octave:legacy-function", |
ef8cf8dda0ba
warn if legacy inline, genvarname or vectorize functions are used
John W. Eaton <jwe@octave.org>
parents:
27923
diff
changeset
|
114 "genvarname is obsolete; use matlab.lang.makeValidName or matlab.lang.makeUniqueStrings instead\n"); |
ef8cf8dda0ba
warn if legacy inline, genvarname or vectorize functions are used
John W. Eaton <jwe@octave.org>
parents:
27923
diff
changeset
|
115 endif |
ef8cf8dda0ba
warn if legacy inline, genvarname or vectorize functions are used
John W. Eaton <jwe@octave.org>
parents:
27923
diff
changeset
|
116 |
28789
28de41192f3c
Eliminate unneeded verification of nargin, nargout in m-files.
Rik <rik@octave.org>
parents:
28458
diff
changeset
|
117 if (nargin < 1) |
19194 | 118 print_usage (); |
119 endif | |
7657 | 120 |
121 strinput = ischar (str); | |
122 ## Process the inputs | |
19194 | 123 if (strinput) |
124 if (rows (str) != 1) | |
125 error ("genvarname: if more than one STR is given, it must be a cellstr"); | |
126 endif | |
127 str = {str}; | |
128 elseif (! iscellstr (str)) | |
129 error ("genvarname: STR must be a string or cellstr"); | |
130 endif | |
131 | |
132 if (ischar (exclusions)) | |
7657 | 133 if (rows (exclusions) != 1) |
8664 | 134 error ("genvarname: if more than one exclusion is given, it must be a cellstr"); |
7657 | 135 endif |
136 exclusions = {exclusions}; | |
137 elseif (! iscellstr (exclusions)) | |
19194 | 138 error ("genvarname: EXCLUSIONS must be a string or cellstr"); |
139 else | |
140 exclusions = exclusions(:); | |
7657 | 141 endif |
142 | |
143 varname = cell (size (str)); | |
144 for i = 1:numel (str) | |
145 ## Perform any modifications to the varname to make sure that it is | |
146 ## a valid variable name. | |
147 | |
148 ## remove invalid characters | |
19194 | 149 str{i}(! (isalnum (str{i}) | str{i} == "_")) = "_"; |
7657 | 150 ## do not use keywords |
151 if (iskeyword (str{i})) | |
32002
939e5d952675
Use upper/lower in preference to toupper/tolower to match Matlab.
Rik <rik@octave.org>
parents:
31706
diff
changeset
|
152 firstcharacter = upper (str{i}(1)); |
18594
56f3c564baaf
genvarname: don't produce names with leading underscored (bug #41923)
Eugenio Gianniti <eugenio.gianniti@mail.polimi.it>
parents:
17745
diff
changeset
|
153 str{i} = ["x", firstcharacter, str{i}(2:end)]; |
7657 | 154 endif |
155 ## The variable cannot be empty | |
156 if (isempty (str{i})) | |
157 str{i} = "x"; | |
158 endif | |
18594
56f3c564baaf
genvarname: don't produce names with leading underscored (bug #41923)
Eugenio Gianniti <eugenio.gianniti@mail.polimi.it>
parents:
17745
diff
changeset
|
159 ## Leading underscores are not Matlab compatible |
56f3c564baaf
genvarname: don't produce names with leading underscored (bug #41923)
Eugenio Gianniti <eugenio.gianniti@mail.polimi.it>
parents:
17745
diff
changeset
|
160 if (str{i}(1) == "_") |
56f3c564baaf
genvarname: don't produce names with leading underscored (bug #41923)
Eugenio Gianniti <eugenio.gianniti@mail.polimi.it>
parents:
17745
diff
changeset
|
161 str{i} = ["x", str{i}]; |
56f3c564baaf
genvarname: don't produce names with leading underscored (bug #41923)
Eugenio Gianniti <eugenio.gianniti@mail.polimi.it>
parents:
17745
diff
changeset
|
162 endif |
7657 | 163 ## it cannot start with a number |
19194 | 164 if (isdigit (str{i}(1))) |
18594
56f3c564baaf
genvarname: don't produce names with leading underscored (bug #41923)
Eugenio Gianniti <eugenio.gianniti@mail.polimi.it>
parents:
17745
diff
changeset
|
165 str{i} = ["x", str{i}]; |
7657 | 166 endif |
167 | |
168 ## make sure that the variable is unique relative to other variables | |
169 ## and the exclusions list | |
170 excluded = any (strcmp (str{i}, exclusions)); | |
19194 | 171 if (excluded && isdigit (str{i}(end))) |
7657 | 172 ## if it is not unique and ends with a digit, add an underscore to |
173 ## make the variable name more readable ("x1_1" instead of "x11") | |
19194 | 174 str{i} = [str{i}, "_"]; |
7657 | 175 endif |
176 varname(i) = str(i); | |
177 idx = 0; | |
14552
86854d032a37
maint: miscellaneous style fixes for .m files
John W. Eaton <jwe@octave.org>
parents:
14363
diff
changeset
|
178 while (excluded) |
20735
418ae0cb752f
Replace ++,-- with in-place operators for performance.
Rik <rik@octave.org>
parents:
20181
diff
changeset
|
179 idx += 1; |
14868
5d3a684236b0
maint: Use Octave coding conventions for cuddling parentheses in scripts directory
Rik <octave@nomad.inbox5.com>
parents:
14552
diff
changeset
|
180 varname{i} = sprintf ("%s%d", str{i}, idx); |
7657 | 181 excluded = any (strcmp (varname{i}, exclusions)); |
182 endwhile | |
183 exclusions(end+1) = varname(i); | |
184 endfor | |
185 | |
14552
86854d032a37
maint: miscellaneous style fixes for .m files
John W. Eaton <jwe@octave.org>
parents:
14363
diff
changeset
|
186 if (strinput) |
7657 | 187 varname = varname{1}; |
188 endif | |
189 | |
190 endfunction | |
191 | |
14363
f3d52523cde1
Use Octave coding conventions in all m-file %!test blocks
Rik <octave@nomad.inbox5.com>
parents:
14327
diff
changeset
|
192 |
7657 | 193 ## a single argument |
14363
f3d52523cde1
Use Octave coding conventions in all m-file %!test blocks
Rik <octave@nomad.inbox5.com>
parents:
14327
diff
changeset
|
194 %!assert (genvarname ("a"), "a") |
7657 | 195 ## a single argument with a non-conflicting exception |
14363
f3d52523cde1
Use Octave coding conventions in all m-file %!test blocks
Rik <octave@nomad.inbox5.com>
parents:
14327
diff
changeset
|
196 %!assert (genvarname ("a", "b"), "a") |
7657 | 197 ## a single argument with a conflicting exception |
14363
f3d52523cde1
Use Octave coding conventions in all m-file %!test blocks
Rik <octave@nomad.inbox5.com>
parents:
14327
diff
changeset
|
198 %!assert (genvarname ("a", "a"), "a1") |
7657 | 199 ## a single argument as a cell |
14363
f3d52523cde1
Use Octave coding conventions in all m-file %!test blocks
Rik <octave@nomad.inbox5.com>
parents:
14327
diff
changeset
|
200 %!assert (genvarname ({"a"}), {"a"}) |
f3d52523cde1
Use Octave coding conventions in all m-file %!test blocks
Rik <octave@nomad.inbox5.com>
parents:
14327
diff
changeset
|
201 %!assert (genvarname ({"a"}, "b"), {"a"}) |
f3d52523cde1
Use Octave coding conventions in all m-file %!test blocks
Rik <octave@nomad.inbox5.com>
parents:
14327
diff
changeset
|
202 %!assert (genvarname ({"a"}, {"b"}), {"a"}) |
f3d52523cde1
Use Octave coding conventions in all m-file %!test blocks
Rik <octave@nomad.inbox5.com>
parents:
14327
diff
changeset
|
203 %!assert (genvarname ({"a"}, "a"), {"a1"}) |
f3d52523cde1
Use Octave coding conventions in all m-file %!test blocks
Rik <octave@nomad.inbox5.com>
parents:
14327
diff
changeset
|
204 %!assert (genvarname ({"a"}, {"a"}), {"a1"}) |
7657 | 205 ## Test different arguments |
206 ## orientation | |
14363
f3d52523cde1
Use Octave coding conventions in all m-file %!test blocks
Rik <octave@nomad.inbox5.com>
parents:
14327
diff
changeset
|
207 %!assert (genvarname ({"a" "b"}), {"a" "b"}) |
f3d52523cde1
Use Octave coding conventions in all m-file %!test blocks
Rik <octave@nomad.inbox5.com>
parents:
14327
diff
changeset
|
208 %!assert (genvarname ({"a";"b"}), {"a";"b"}) |
f3d52523cde1
Use Octave coding conventions in all m-file %!test blocks
Rik <octave@nomad.inbox5.com>
parents:
14327
diff
changeset
|
209 %!assert (genvarname ({"a" "a"}), {"a" "a1"}) |
f3d52523cde1
Use Octave coding conventions in all m-file %!test blocks
Rik <octave@nomad.inbox5.com>
parents:
14327
diff
changeset
|
210 %!assert (genvarname ({"a" "b";"c" "d"}), {"a" "b";"c" "d"}) |
30330
01de0045b2e3
maint: Shorten some long lines to <= 80 characters (bug #57599)
Rik <rik@octave.org>
parents:
29359
diff
changeset
|
211 %!assert (genvarname ({"a" "a" "a";"a" "a" "a"}), |
01de0045b2e3
maint: Shorten some long lines to <= 80 characters (bug #57599)
Rik <rik@octave.org>
parents:
29359
diff
changeset
|
212 %! {"a" "a2" "a4";"a1" "a3" "a5"}) |
7657 | 213 ## more than one repetition |
14363
f3d52523cde1
Use Octave coding conventions in all m-file %!test blocks
Rik <octave@nomad.inbox5.com>
parents:
14327
diff
changeset
|
214 %!assert (genvarname ({"a" "a" "a"}), {"a" "a1" "a2"}) |
f3d52523cde1
Use Octave coding conventions in all m-file %!test blocks
Rik <octave@nomad.inbox5.com>
parents:
14327
diff
changeset
|
215 %!assert (genvarname ({"a" "a" "a"}, {"a" "a1" "a2"}), {"a3" "a4" "a5"}) |
7657 | 216 ## more than one repetition not in order |
14363
f3d52523cde1
Use Octave coding conventions in all m-file %!test blocks
Rik <octave@nomad.inbox5.com>
parents:
14327
diff
changeset
|
217 %!assert (genvarname ({"a" "b" "a" "b" "a"}), {"a" "b" "a1" "b1" "a2"}) |
7657 | 218 ## Variable name munging |
18594
56f3c564baaf
genvarname: don't produce names with leading underscored (bug #41923)
Eugenio Gianniti <eugenio.gianniti@mail.polimi.it>
parents:
17745
diff
changeset
|
219 %!assert (genvarname ("__x__"), "x__x__") |
56f3c564baaf
genvarname: don't produce names with leading underscored (bug #41923)
Eugenio Gianniti <eugenio.gianniti@mail.polimi.it>
parents:
17745
diff
changeset
|
220 %!assert (genvarname ("123456789"), "x123456789") |
56f3c564baaf
genvarname: don't produce names with leading underscored (bug #41923)
Eugenio Gianniti <eugenio.gianniti@mail.polimi.it>
parents:
17745
diff
changeset
|
221 %!assert (genvarname ("_$1__"), "x__1__") |
56f3c564baaf
genvarname: don't produce names with leading underscored (bug #41923)
Eugenio Gianniti <eugenio.gianniti@mail.polimi.it>
parents:
17745
diff
changeset
|
222 %!assert (genvarname ("__foo__", "x__foo__"), "x__foo__1") |
56f3c564baaf
genvarname: don't produce names with leading underscored (bug #41923)
Eugenio Gianniti <eugenio.gianniti@mail.polimi.it>
parents:
17745
diff
changeset
|
223 %!assert (genvarname ("1million_and1", "x1million_and1"), "x1million_and1_1") |
7657 | 224 %!assert (genvarname ({"", "", ""}), {"x", "x1", "x2"}) |
18594
56f3c564baaf
genvarname: don't produce names with leading underscored (bug #41923)
Eugenio Gianniti <eugenio.gianniti@mail.polimi.it>
parents:
17745
diff
changeset
|
225 %!assert (genvarname ("if"), "xIf") |
56f3c564baaf
genvarname: don't produce names with leading underscored (bug #41923)
Eugenio Gianniti <eugenio.gianniti@mail.polimi.it>
parents:
17745
diff
changeset
|
226 %!assert (genvarname ({"if", "if", "if"}), {"xIf", "xIf1", "xIf2"}) |
19194 | 227 ## Exclusions in odd format |
228 %!assert (genvarname ("x", {"a", "b"; "x", "d"}), "x1") | |
14363
f3d52523cde1
Use Octave coding conventions in all m-file %!test blocks
Rik <octave@nomad.inbox5.com>
parents:
14327
diff
changeset
|
229 |
19833
9fc020886ae9
maint: Clean up m-files to follow Octave coding conventions.
Rik <rik@octave.org>
parents:
19697
diff
changeset
|
230 ## Test input validation |
28886
d8318c12d903
test: remove unnecessary BIST tests in m-files checking for excessive number of inputs.
Rik <rik@octave.org>
parents:
28789
diff
changeset
|
231 %!error <Invalid call> genvarname () |
19194 | 232 %!error <more than one STR is given, it must be a cellstr> genvarname (char ("a", "b", "c")) |
233 %!error <STR must be a string or cellstr> genvarname (1) | |
234 %!error <more than one exclusion is given, it must be a cellstr> genvarname ("x", char ("a", "b", "c")) | |
235 %!error <EXCLUSIONS must be a string or cellstr> genvarname ("x", 1) |