annotate test/parser.tst @ 33612:23bb1d9fcec8 bytecode-interpreter tip

maint: Merge default to bytecode-interpreter.
author Nicholas R. Jankowski <jankowski.nicholas@gmail.com>
date Sun, 19 May 2024 23:02:07 -0400
parents 2e484f9f1f18
children
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
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 ##
32632
2e484f9f1f18 maint: update Octave Project Developers copyright for the new year
John W. Eaton <jwe@octave.org>
parents: 32426
diff changeset
3 ## Copyright (C) 2010-2024 The Octave Project Developers
27918
b442ec6dda5c use centralized file for copyright info for individual contributors
John W. Eaton <jwe@octave.org>
parents: 27490
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/>.
11218
0910020c5ab6 add omitted file from previous change
John W. Eaton <jwe@octave.org>
parents:
diff changeset
7 ##
0910020c5ab6 add omitted file from previous change
John W. Eaton <jwe@octave.org>
parents:
diff changeset
8 ## This file is part of Octave.
0910020c5ab6 add omitted file from previous change
John W. Eaton <jwe@octave.org>
parents:
diff changeset
9 ##
24534
194eb4bd202b maint: Update punctuation for GPL v3 license text.
Rik <rik@octave.org>
parents: 24339
diff changeset
10 ## Octave is free software: you can redistribute it and/or modify it
11218
0910020c5ab6 add omitted file from previous change
John W. Eaton <jwe@octave.org>
parents:
diff changeset
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: 24339
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.
11218
0910020c5ab6 add omitted file from previous change
John W. Eaton <jwe@octave.org>
parents:
diff changeset
14 ##
0910020c5ab6 add omitted file from previous change
John W. Eaton <jwe@octave.org>
parents:
diff changeset
15 ## Octave is distributed in the hope that it will be useful, but
0910020c5ab6 add omitted file from previous change
John W. Eaton <jwe@octave.org>
parents:
diff changeset
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.
11218
0910020c5ab6 add omitted file from previous change
John W. Eaton <jwe@octave.org>
parents:
diff changeset
19 ##
0910020c5ab6 add omitted file from previous change
John W. Eaton <jwe@octave.org>
parents:
diff changeset
20 ## You should have received a copy of the GNU General Public License
0910020c5ab6 add omitted file from previous change
John W. Eaton <jwe@octave.org>
parents:
diff changeset
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: 24339
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 ########################################################################
11218
0910020c5ab6 add omitted file from previous change
John W. Eaton <jwe@octave.org>
parents:
diff changeset
25
14131
c3309e1ec50d test: Use Octave coding and spacing conventions for fixed test scripts
Rik <octave@nomad.inbox5.com>
parents: 13237
diff changeset
26 ## Tests for parser problems belong in this file.
c3309e1ec50d test: Use Octave coding and spacing conventions for fixed test scripts
Rik <octave@nomad.inbox5.com>
parents: 13237
diff changeset
27 ## We need many more tests here!
11218
0910020c5ab6 add omitted file from previous change
John W. Eaton <jwe@octave.org>
parents:
diff changeset
28
19451
e5a78897be9e Allow empty comma-separated lists in cell { } constructor (bug #43113).
Rik <rik@octave.org>
parents: 18492
diff changeset
29 ## Test cell construction operator {}
11218
0910020c5ab6 add omitted file from previous change
John W. Eaton <jwe@octave.org>
parents:
diff changeset
30 %!assert ({1 2 {3 4}}, {1,2,{3,4}})
0910020c5ab6 add omitted file from previous change
John W. Eaton <jwe@octave.org>
parents:
diff changeset
31 %!assert ({1, 2 {3 4}}, {1,2,{3,4}})
0910020c5ab6 add omitted file from previous change
John W. Eaton <jwe@octave.org>
parents:
diff changeset
32 %!assert ({1 2, {3 4}}, {1,2,{3,4}})
0910020c5ab6 add omitted file from previous change
John W. Eaton <jwe@octave.org>
parents:
diff changeset
33 %!assert ({1 2 {3, 4}}, {1,2,{3,4}})
0910020c5ab6 add omitted file from previous change
John W. Eaton <jwe@octave.org>
parents:
diff changeset
34 %!assert ({1, 2, {3 4}}, {1,2,{3,4}})
0910020c5ab6 add omitted file from previous change
John W. Eaton <jwe@octave.org>
parents:
diff changeset
35 %!assert ({1 2,{3 4}}, {1,2,{3,4}})
0910020c5ab6 add omitted file from previous change
John W. Eaton <jwe@octave.org>
parents:
diff changeset
36 %!assert ({1 2,{3,4}}, {1,2,{3,4}})
0910020c5ab6 add omitted file from previous change
John W. Eaton <jwe@octave.org>
parents:
diff changeset
37 %!assert ({1,2,{3 4}}, {1,2,{3,4}})
12518
9f926b9f83cc Add operator precedence tests to fixed list of parser tests.
Rik <octave@nomad.inbox5.com>
parents: 11523
diff changeset
38
19451
e5a78897be9e Allow empty comma-separated lists in cell { } constructor (bug #43113).
Rik <rik@octave.org>
parents: 18492
diff changeset
39 ## bug #43113 using null comma-separated list in constructor
e5a78897be9e Allow empty comma-separated lists in cell { } constructor (bug #43113).
Rik <rik@octave.org>
parents: 18492
diff changeset
40 %!test
e5a78897be9e Allow empty comma-separated lists in cell { } constructor (bug #43113).
Rik <rik@octave.org>
parents: 18492
diff changeset
41 %! z = cell (1,2,3,0,5);
e5a78897be9e Allow empty comma-separated lists in cell { } constructor (bug #43113).
Rik <rik@octave.org>
parents: 18492
diff changeset
42 %! assert ({1, z{:}, 2}, {1, 2});
e5a78897be9e Allow empty comma-separated lists in cell { } constructor (bug #43113).
Rik <rik@octave.org>
parents: 18492
diff changeset
43 %! assert ({1; z{:}; 2}, {1; 2});
e5a78897be9e Allow empty comma-separated lists in cell { } constructor (bug #43113).
Rik <rik@octave.org>
parents: 18492
diff changeset
44 %! assert ({1 2; z{:}; 3 4}, {1, 2; 3 4});
e5a78897be9e Allow empty comma-separated lists in cell { } constructor (bug #43113).
Rik <rik@octave.org>
parents: 18492
diff changeset
45 %! assert ({1 2; 5 z{:} 6; 3 4}, {1, 2; 5 6; 3 4});
e5a78897be9e Allow empty comma-separated lists in cell { } constructor (bug #43113).
Rik <rik@octave.org>
parents: 18492
diff changeset
46
12627
002948ae5bc0 fix precedence level of transpose operators (bug #32533)
John W. Eaton <jwe@octave.org>
parents: 12518
diff changeset
47 ## Tests for operator precedence as documented in section 8.8 of manual
002948ae5bc0 fix precedence level of transpose operators (bug #32533)
John W. Eaton <jwe@octave.org>
parents: 12518
diff changeset
48 ## There are 13 levels of precedence from "parentheses and indexing" (highest)
002948ae5bc0 fix precedence level of transpose operators (bug #32533)
John W. Eaton <jwe@octave.org>
parents: 12518
diff changeset
49 ## down to "statement operators" (lowest).
002948ae5bc0 fix precedence level of transpose operators (bug #32533)
John W. Eaton <jwe@octave.org>
parents: 12518
diff changeset
50 ##
002948ae5bc0 fix precedence level of transpose operators (bug #32533)
John W. Eaton <jwe@octave.org>
parents: 12518
diff changeset
51 ## Level 13 (parentheses and indexing)
002948ae5bc0 fix precedence level of transpose operators (bug #32533)
John W. Eaton <jwe@octave.org>
parents: 12518
diff changeset
52 ## Overrides all other levels
002948ae5bc0 fix precedence level of transpose operators (bug #32533)
John W. Eaton <jwe@octave.org>
parents: 12518
diff changeset
53 %!test
17313
1e1d42f0f332 parser.tst: Re-indent and add tests for bug #33304.
Rik <rik@octave.org>
parents: 16755
diff changeset
54 %! a.b = 1;
1e1d42f0f332 parser.tst: Re-indent and add tests for bug #33304.
Rik <rik@octave.org>
parents: 16755
diff changeset
55 %! assert (a. b++, 1);
1e1d42f0f332 parser.tst: Re-indent and add tests for bug #33304.
Rik <rik@octave.org>
parents: 16755
diff changeset
56 %! assert (a.b, 2);
1e1d42f0f332 parser.tst: Re-indent and add tests for bug #33304.
Rik <rik@octave.org>
parents: 16755
diff changeset
57 %! clear a;
1e1d42f0f332 parser.tst: Re-indent and add tests for bug #33304.
Rik <rik@octave.org>
parents: 16755
diff changeset
58 %! a.b = [0 1];
1e1d42f0f332 parser.tst: Re-indent and add tests for bug #33304.
Rik <rik@octave.org>
parents: 16755
diff changeset
59 %! b = 2;
1e1d42f0f332 parser.tst: Re-indent and add tests for bug #33304.
Rik <rik@octave.org>
parents: 16755
diff changeset
60 %! assert (a.b', [0;1]);
1e1d42f0f332 parser.tst: Re-indent and add tests for bug #33304.
Rik <rik@octave.org>
parents: 16755
diff changeset
61 %! assert (!a .b, logical ([1 0]));
1e1d42f0f332 parser.tst: Re-indent and add tests for bug #33304.
Rik <rik@octave.org>
parents: 16755
diff changeset
62 %! assert (3*a .b, [0 3]);
1e1d42f0f332 parser.tst: Re-indent and add tests for bug #33304.
Rik <rik@octave.org>
parents: 16755
diff changeset
63 %! assert (a. b-1, [-1 0]);
32151
72dcb1cef2c9 maint: Strip trailing whitespace from source files.
John W. Eaton <jwe@octave.org>
parents: 32068
diff changeset
64 %! warning ('off', 'Octave:colon-nonscalar-argument', 'local');
17313
1e1d42f0f332 parser.tst: Re-indent and add tests for bug #33304.
Rik <rik@octave.org>
parents: 16755
diff changeset
65 %! assert (a. b:3, 0:3);
1e1d42f0f332 parser.tst: Re-indent and add tests for bug #33304.
Rik <rik@octave.org>
parents: 16755
diff changeset
66 %! assert (a. b>0.5, logical ([0 1]));
1e1d42f0f332 parser.tst: Re-indent and add tests for bug #33304.
Rik <rik@octave.org>
parents: 16755
diff changeset
67 %! assert (a. b&0, logical ([0 0]));
1e1d42f0f332 parser.tst: Re-indent and add tests for bug #33304.
Rik <rik@octave.org>
parents: 16755
diff changeset
68 %! assert (a. b|0, logical ([0 1]));
1e1d42f0f332 parser.tst: Re-indent and add tests for bug #33304.
Rik <rik@octave.org>
parents: 16755
diff changeset
69 %! a.b = [1 2];
1e1d42f0f332 parser.tst: Re-indent and add tests for bug #33304.
Rik <rik@octave.org>
parents: 16755
diff changeset
70 %! assert (a. b&&0, false);
1e1d42f0f332 parser.tst: Re-indent and add tests for bug #33304.
Rik <rik@octave.org>
parents: 16755
diff changeset
71 %! assert (a. b||0, true);
1e1d42f0f332 parser.tst: Re-indent and add tests for bug #33304.
Rik <rik@octave.org>
parents: 16755
diff changeset
72 %! a.b += a. b*2;
1e1d42f0f332 parser.tst: Re-indent and add tests for bug #33304.
Rik <rik@octave.org>
parents: 16755
diff changeset
73 %! assert (a.b, [3 6]);
12627
002948ae5bc0 fix precedence level of transpose operators (bug #32533)
John W. Eaton <jwe@octave.org>
parents: 12518
diff changeset
74 ## Level 12 (postfix increment and decrement)
12518
9f926b9f83cc Add operator precedence tests to fixed list of parser tests.
Rik <octave@nomad.inbox5.com>
parents: 11523
diff changeset
75 %!test
17313
1e1d42f0f332 parser.tst: Re-indent and add tests for bug #33304.
Rik <rik@octave.org>
parents: 16755
diff changeset
76 %! a = [3 5];
1e1d42f0f332 parser.tst: Re-indent and add tests for bug #33304.
Rik <rik@octave.org>
parents: 16755
diff changeset
77 %! assert (2.^a ++, [8 32]);
1e1d42f0f332 parser.tst: Re-indent and add tests for bug #33304.
Rik <rik@octave.org>
parents: 16755
diff changeset
78 %! assert (a, [4 6]);
1e1d42f0f332 parser.tst: Re-indent and add tests for bug #33304.
Rik <rik@octave.org>
parents: 16755
diff changeset
79 %! assert (a--', [4; 6]);
1e1d42f0f332 parser.tst: Re-indent and add tests for bug #33304.
Rik <rik@octave.org>
parents: 16755
diff changeset
80 %! assert (a, [3 5]);
1e1d42f0f332 parser.tst: Re-indent and add tests for bug #33304.
Rik <rik@octave.org>
parents: 16755
diff changeset
81 %! a = 0;
1e1d42f0f332 parser.tst: Re-indent and add tests for bug #33304.
Rik <rik@octave.org>
parents: 16755
diff changeset
82 %! assert (!a --, true);
1e1d42f0f332 parser.tst: Re-indent and add tests for bug #33304.
Rik <rik@octave.org>
parents: 16755
diff changeset
83 %! assert (-a ++, 1);
1e1d42f0f332 parser.tst: Re-indent and add tests for bug #33304.
Rik <rik@octave.org>
parents: 16755
diff changeset
84 %! assert (3*a ++, 0);
1e1d42f0f332 parser.tst: Re-indent and add tests for bug #33304.
Rik <rik@octave.org>
parents: 16755
diff changeset
85 %! assert (a++-2, -1);
1e1d42f0f332 parser.tst: Re-indent and add tests for bug #33304.
Rik <rik@octave.org>
parents: 16755
diff changeset
86 %! assert (1:a ++, 1:2);
1e1d42f0f332 parser.tst: Re-indent and add tests for bug #33304.
Rik <rik@octave.org>
parents: 16755
diff changeset
87 %! assert (4>a++, true);
1e1d42f0f332 parser.tst: Re-indent and add tests for bug #33304.
Rik <rik@octave.org>
parents: 16755
diff changeset
88 %! a = [0 -1];
1e1d42f0f332 parser.tst: Re-indent and add tests for bug #33304.
Rik <rik@octave.org>
parents: 16755
diff changeset
89 %! assert ([1 1] & a++, logical ([0 1]));
1e1d42f0f332 parser.tst: Re-indent and add tests for bug #33304.
Rik <rik@octave.org>
parents: 16755
diff changeset
90 %! assert ([0 0] | a++, logical ([1 0]));
1e1d42f0f332 parser.tst: Re-indent and add tests for bug #33304.
Rik <rik@octave.org>
parents: 16755
diff changeset
91 %! a = 0;
1e1d42f0f332 parser.tst: Re-indent and add tests for bug #33304.
Rik <rik@octave.org>
parents: 16755
diff changeset
92 %! assert (1 && a ++, false);
1e1d42f0f332 parser.tst: Re-indent and add tests for bug #33304.
Rik <rik@octave.org>
parents: 16755
diff changeset
93 %! assert (0 || a --, true);
1e1d42f0f332 parser.tst: Re-indent and add tests for bug #33304.
Rik <rik@octave.org>
parents: 16755
diff changeset
94 %! a = 5; b = 2;
29900
da6e5914ddaf handle all binary operators the same when detecting command syntax (bug #60882)
John W. Eaton <jwe@octave.org>
parents: 29359
diff changeset
95 %! b += a ++;
17313
1e1d42f0f332 parser.tst: Re-indent and add tests for bug #33304.
Rik <rik@octave.org>
parents: 16755
diff changeset
96 %! assert (b, 7);
12627
002948ae5bc0 fix precedence level of transpose operators (bug #32533)
John W. Eaton <jwe@octave.org>
parents: 12518
diff changeset
97
002948ae5bc0 fix precedence level of transpose operators (bug #32533)
John W. Eaton <jwe@octave.org>
parents: 12518
diff changeset
98 ## Level 11 (transpose and exponentiation)
002948ae5bc0 fix precedence level of transpose operators (bug #32533)
John W. Eaton <jwe@octave.org>
parents: 12518
diff changeset
99 %!test
17622
fd712a12fe53 compatibility for power operator precedence and direction (bug #33304)
Axel Mathéi <axel.mathei@gmail.com>
parents: 17420
diff changeset
100 %! a = 2;
21580
ecce63c99c3f maint: Add semicolons to terminate code in %! blocks.
Rik <rik@octave.org>
parents: 21317
diff changeset
101 %! assert (2 ^a++, 4);
ecce63c99c3f maint: Add semicolons to terminate code in %! blocks.
Rik <rik@octave.org>
parents: 21317
diff changeset
102 %! assert (a, 3);
ecce63c99c3f maint: Add semicolons to terminate code in %! blocks.
Rik <rik@octave.org>
parents: 21317
diff changeset
103 %! assert (2 ^--a ^2, 16);
ecce63c99c3f maint: Add semicolons to terminate code in %! blocks.
Rik <rik@octave.org>
parents: 21317
diff changeset
104 %! assert (a, 2);
ecce63c99c3f maint: Add semicolons to terminate code in %! blocks.
Rik <rik@octave.org>
parents: 21317
diff changeset
105 %! assert (2 ^++a, 8);
ecce63c99c3f maint: Add semicolons to terminate code in %! blocks.
Rik <rik@octave.org>
parents: 21317
diff changeset
106 %! assert (a, 3);
ecce63c99c3f maint: Add semicolons to terminate code in %! blocks.
Rik <rik@octave.org>
parents: 21317
diff changeset
107 %! assert (a' ^2, 9);
28916
ec591c500fa4 maint: Use Octave convention of space after function name in test/.
Rik <rik@octave.org>
parents: 28583
diff changeset
108 %! assert (2 ^sin (0), 1);
31932
2e135e3cb1aa maint: replace double semicolon ';;' line ending with just ';'.
Rik <rik@octave.org>
parents: 31706
diff changeset
109 %! assert (-2 ^2, -4);
21580
ecce63c99c3f maint: Add semicolons to terminate code in %! blocks.
Rik <rik@octave.org>
parents: 21317
diff changeset
110 %! assert (2 ^+1 ^3, 8);
ecce63c99c3f maint: Add semicolons to terminate code in %! blocks.
Rik <rik@octave.org>
parents: 21317
diff changeset
111 %! assert (2 ^-1 ^3, 0.125);
ecce63c99c3f maint: Add semicolons to terminate code in %! blocks.
Rik <rik@octave.org>
parents: 21317
diff changeset
112 %! assert (2 ^~0 ^2, 4);
17313
1e1d42f0f332 parser.tst: Re-indent and add tests for bug #33304.
Rik <rik@octave.org>
parents: 16755
diff changeset
113 %! assert (!0 ^0, false);
1e1d42f0f332 parser.tst: Re-indent and add tests for bug #33304.
Rik <rik@octave.org>
parents: 16755
diff changeset
114 %! assert (2*3 ^2, 18);
1e1d42f0f332 parser.tst: Re-indent and add tests for bug #33304.
Rik <rik@octave.org>
parents: 16755
diff changeset
115 %! assert (2+3 ^2, 11);
1e1d42f0f332 parser.tst: Re-indent and add tests for bug #33304.
Rik <rik@octave.org>
parents: 16755
diff changeset
116 %! assert ([1:10](1:2 ^2), [1 2 3 4]);
1e1d42f0f332 parser.tst: Re-indent and add tests for bug #33304.
Rik <rik@octave.org>
parents: 16755
diff changeset
117 %! assert (3>2 ^2, false);
1e1d42f0f332 parser.tst: Re-indent and add tests for bug #33304.
Rik <rik@octave.org>
parents: 16755
diff changeset
118 %! assert (1&0 ^0, true);
1e1d42f0f332 parser.tst: Re-indent and add tests for bug #33304.
Rik <rik@octave.org>
parents: 16755
diff changeset
119 %! assert (0|0 ^0, true);
1e1d42f0f332 parser.tst: Re-indent and add tests for bug #33304.
Rik <rik@octave.org>
parents: 16755
diff changeset
120 %! assert (1&&0 ^0, true);
1e1d42f0f332 parser.tst: Re-indent and add tests for bug #33304.
Rik <rik@octave.org>
parents: 16755
diff changeset
121 %! assert (0||0 ^0, true);
1e1d42f0f332 parser.tst: Re-indent and add tests for bug #33304.
Rik <rik@octave.org>
parents: 16755
diff changeset
122 %! a = 3;
1e1d42f0f332 parser.tst: Re-indent and add tests for bug #33304.
Rik <rik@octave.org>
parents: 16755
diff changeset
123 %! a *= 0 ^0;
1e1d42f0f332 parser.tst: Re-indent and add tests for bug #33304.
Rik <rik@octave.org>
parents: 16755
diff changeset
124 %! assert (a, 3);
12627
002948ae5bc0 fix precedence level of transpose operators (bug #32533)
John W. Eaton <jwe@octave.org>
parents: 12518
diff changeset
125 ## Level 10 (unary plus/minus, prefix increment/decrement, not)
12518
9f926b9f83cc Add operator precedence tests to fixed list of parser tests.
Rik <octave@nomad.inbox5.com>
parents: 11523
diff changeset
126 %!test
17313
1e1d42f0f332 parser.tst: Re-indent and add tests for bug #33304.
Rik <rik@octave.org>
parents: 16755
diff changeset
127 %! a = 2;
1e1d42f0f332 parser.tst: Re-indent and add tests for bug #33304.
Rik <rik@octave.org>
parents: 16755
diff changeset
128 %! assert (++ a*3, 9);
1e1d42f0f332 parser.tst: Re-indent and add tests for bug #33304.
Rik <rik@octave.org>
parents: 16755
diff changeset
129 %! assert (-- a-2, 0);
1e1d42f0f332 parser.tst: Re-indent and add tests for bug #33304.
Rik <rik@octave.org>
parents: 16755
diff changeset
130 %! assert (a, 2);
1e1d42f0f332 parser.tst: Re-indent and add tests for bug #33304.
Rik <rik@octave.org>
parents: 16755
diff changeset
131 %! assert (! a-2, -2);
1e1d42f0f332 parser.tst: Re-indent and add tests for bug #33304.
Rik <rik@octave.org>
parents: 16755
diff changeset
132 %! assert ([1:10](++ a:5), 3:5);
1e1d42f0f332 parser.tst: Re-indent and add tests for bug #33304.
Rik <rik@octave.org>
parents: 16755
diff changeset
133 %! a = [1 0];
1e1d42f0f332 parser.tst: Re-indent and add tests for bug #33304.
Rik <rik@octave.org>
parents: 16755
diff changeset
134 %! assert (! a>=[1 0], [false true]);
1e1d42f0f332 parser.tst: Re-indent and add tests for bug #33304.
Rik <rik@octave.org>
parents: 16755
diff changeset
135 %! a = 0;
1e1d42f0f332 parser.tst: Re-indent and add tests for bug #33304.
Rik <rik@octave.org>
parents: 16755
diff changeset
136 %! assert (++ a&1, true);
1e1d42f0f332 parser.tst: Re-indent and add tests for bug #33304.
Rik <rik@octave.org>
parents: 16755
diff changeset
137 %! assert (-- a|0, false);
1e1d42f0f332 parser.tst: Re-indent and add tests for bug #33304.
Rik <rik@octave.org>
parents: 16755
diff changeset
138 %! assert (-- a&&1, true);
1e1d42f0f332 parser.tst: Re-indent and add tests for bug #33304.
Rik <rik@octave.org>
parents: 16755
diff changeset
139 %! assert (++ a||0, false);
1e1d42f0f332 parser.tst: Re-indent and add tests for bug #33304.
Rik <rik@octave.org>
parents: 16755
diff changeset
140 %! a = 3;
1e1d42f0f332 parser.tst: Re-indent and add tests for bug #33304.
Rik <rik@octave.org>
parents: 16755
diff changeset
141 %! a *= ++a;
1e1d42f0f332 parser.tst: Re-indent and add tests for bug #33304.
Rik <rik@octave.org>
parents: 16755
diff changeset
142 %! assert (a, 16);
12627
002948ae5bc0 fix precedence level of transpose operators (bug #32533)
John W. Eaton <jwe@octave.org>
parents: 12518
diff changeset
143 ## Level 9 (multiply, divide)
12518
9f926b9f83cc Add operator precedence tests to fixed list of parser tests.
Rik <octave@nomad.inbox5.com>
parents: 11523
diff changeset
144 %!test
17313
1e1d42f0f332 parser.tst: Re-indent and add tests for bug #33304.
Rik <rik@octave.org>
parents: 16755
diff changeset
145 %! assert (3+4 * 5, 23);
1e1d42f0f332 parser.tst: Re-indent and add tests for bug #33304.
Rik <rik@octave.org>
parents: 16755
diff changeset
146 %! assert (5 * 1:6, [5 6]);
1e1d42f0f332 parser.tst: Re-indent and add tests for bug #33304.
Rik <rik@octave.org>
parents: 16755
diff changeset
147 %! assert (3>1 * 5, false);
1e1d42f0f332 parser.tst: Re-indent and add tests for bug #33304.
Rik <rik@octave.org>
parents: 16755
diff changeset
148 %! assert (1&1 * 0, false);
1e1d42f0f332 parser.tst: Re-indent and add tests for bug #33304.
Rik <rik@octave.org>
parents: 16755
diff changeset
149 %! assert (1|1 * 0, true);
1e1d42f0f332 parser.tst: Re-indent and add tests for bug #33304.
Rik <rik@octave.org>
parents: 16755
diff changeset
150 %! assert (1&&1 * 0, false);
1e1d42f0f332 parser.tst: Re-indent and add tests for bug #33304.
Rik <rik@octave.org>
parents: 16755
diff changeset
151 %! assert (1||1 * 0, true);
1e1d42f0f332 parser.tst: Re-indent and add tests for bug #33304.
Rik <rik@octave.org>
parents: 16755
diff changeset
152 %! a = 3;
1e1d42f0f332 parser.tst: Re-indent and add tests for bug #33304.
Rik <rik@octave.org>
parents: 16755
diff changeset
153 %! a /= a * 2;
1e1d42f0f332 parser.tst: Re-indent and add tests for bug #33304.
Rik <rik@octave.org>
parents: 16755
diff changeset
154 %! assert (a, 0.5);
12627
002948ae5bc0 fix precedence level of transpose operators (bug #32533)
John W. Eaton <jwe@octave.org>
parents: 12518
diff changeset
155 ## Level 8 (add, subtract)
12518
9f926b9f83cc Add operator precedence tests to fixed list of parser tests.
Rik <octave@nomad.inbox5.com>
parents: 11523
diff changeset
156 %!test
17313
1e1d42f0f332 parser.tst: Re-indent and add tests for bug #33304.
Rik <rik@octave.org>
parents: 16755
diff changeset
157 %! assert ([2 + 1:6], 3:6);
1e1d42f0f332 parser.tst: Re-indent and add tests for bug #33304.
Rik <rik@octave.org>
parents: 16755
diff changeset
158 %! assert (3>1 + 5, false);
1e1d42f0f332 parser.tst: Re-indent and add tests for bug #33304.
Rik <rik@octave.org>
parents: 16755
diff changeset
159 %! assert (1&1 - 1, false);
1e1d42f0f332 parser.tst: Re-indent and add tests for bug #33304.
Rik <rik@octave.org>
parents: 16755
diff changeset
160 %! assert (0|1 - 2, true);
1e1d42f0f332 parser.tst: Re-indent and add tests for bug #33304.
Rik <rik@octave.org>
parents: 16755
diff changeset
161 %! assert (1&&1 - 1, false);
1e1d42f0f332 parser.tst: Re-indent and add tests for bug #33304.
Rik <rik@octave.org>
parents: 16755
diff changeset
162 %! assert (0||1 - 2, true);
1e1d42f0f332 parser.tst: Re-indent and add tests for bug #33304.
Rik <rik@octave.org>
parents: 16755
diff changeset
163 %! a = 3;
1e1d42f0f332 parser.tst: Re-indent and add tests for bug #33304.
Rik <rik@octave.org>
parents: 16755
diff changeset
164 %! a *= 1 + 1;
1e1d42f0f332 parser.tst: Re-indent and add tests for bug #33304.
Rik <rik@octave.org>
parents: 16755
diff changeset
165 %! assert (a, 6);
12627
002948ae5bc0 fix precedence level of transpose operators (bug #32533)
John W. Eaton <jwe@octave.org>
parents: 12518
diff changeset
166 ## Level 7 (colon)
12518
9f926b9f83cc Add operator precedence tests to fixed list of parser tests.
Rik <octave@nomad.inbox5.com>
parents: 11523
diff changeset
167 %!test
17313
1e1d42f0f332 parser.tst: Re-indent and add tests for bug #33304.
Rik <rik@octave.org>
parents: 16755
diff changeset
168 %! assert (5:-1: 3>4, [true false false]);
1e1d42f0f332 parser.tst: Re-indent and add tests for bug #33304.
Rik <rik@octave.org>
parents: 16755
diff changeset
169 %! assert (1: 3&1, [true true true]);
1e1d42f0f332 parser.tst: Re-indent and add tests for bug #33304.
Rik <rik@octave.org>
parents: 16755
diff changeset
170 %! assert (1: 3|0, [true true true]);
1e1d42f0f332 parser.tst: Re-indent and add tests for bug #33304.
Rik <rik@octave.org>
parents: 16755
diff changeset
171 %! assert (-1: 3&&1, false);
1e1d42f0f332 parser.tst: Re-indent and add tests for bug #33304.
Rik <rik@octave.org>
parents: 16755
diff changeset
172 %! assert (-1: 3||0, false);
1e1d42f0f332 parser.tst: Re-indent and add tests for bug #33304.
Rik <rik@octave.org>
parents: 16755
diff changeset
173 %! a = [1:3];
1e1d42f0f332 parser.tst: Re-indent and add tests for bug #33304.
Rik <rik@octave.org>
parents: 16755
diff changeset
174 %! a += 3 : 5;
1e1d42f0f332 parser.tst: Re-indent and add tests for bug #33304.
Rik <rik@octave.org>
parents: 16755
diff changeset
175 %! assert (a, [4 6 8]);
12627
002948ae5bc0 fix precedence level of transpose operators (bug #32533)
John W. Eaton <jwe@octave.org>
parents: 12518
diff changeset
176 ## Level 6 (relational)
12518
9f926b9f83cc Add operator precedence tests to fixed list of parser tests.
Rik <octave@nomad.inbox5.com>
parents: 11523
diff changeset
177 %!test
17313
1e1d42f0f332 parser.tst: Re-indent and add tests for bug #33304.
Rik <rik@octave.org>
parents: 16755
diff changeset
178 %! assert (0 == -1&0, false);
1e1d42f0f332 parser.tst: Re-indent and add tests for bug #33304.
Rik <rik@octave.org>
parents: 16755
diff changeset
179 %! assert (1 == -1|0, false);
1e1d42f0f332 parser.tst: Re-indent and add tests for bug #33304.
Rik <rik@octave.org>
parents: 16755
diff changeset
180 %! assert (0 == -1&&0, false);
1e1d42f0f332 parser.tst: Re-indent and add tests for bug #33304.
Rik <rik@octave.org>
parents: 16755
diff changeset
181 %! assert (1 == -1||0, false);
1e1d42f0f332 parser.tst: Re-indent and add tests for bug #33304.
Rik <rik@octave.org>
parents: 16755
diff changeset
182 %! a = 2;
1e1d42f0f332 parser.tst: Re-indent and add tests for bug #33304.
Rik <rik@octave.org>
parents: 16755
diff changeset
183 %! a *= 3 > 1;
1e1d42f0f332 parser.tst: Re-indent and add tests for bug #33304.
Rik <rik@octave.org>
parents: 16755
diff changeset
184 %! assert (a, 2);
12627
002948ae5bc0 fix precedence level of transpose operators (bug #32533)
John W. Eaton <jwe@octave.org>
parents: 12518
diff changeset
185 ## Level 5 (element-wise and)
12518
9f926b9f83cc Add operator precedence tests to fixed list of parser tests.
Rik <octave@nomad.inbox5.com>
parents: 11523
diff changeset
186 %!test
17313
1e1d42f0f332 parser.tst: Re-indent and add tests for bug #33304.
Rik <rik@octave.org>
parents: 16755
diff changeset
187 %! assert (0 & 1|1, true);
1e1d42f0f332 parser.tst: Re-indent and add tests for bug #33304.
Rik <rik@octave.org>
parents: 16755
diff changeset
188 %! assert ([0 1] & 1&&1, false);
1e1d42f0f332 parser.tst: Re-indent and add tests for bug #33304.
Rik <rik@octave.org>
parents: 16755
diff changeset
189 %! assert (0 & 1||1, true);
1e1d42f0f332 parser.tst: Re-indent and add tests for bug #33304.
Rik <rik@octave.org>
parents: 16755
diff changeset
190 %! a = 2;
1e1d42f0f332 parser.tst: Re-indent and add tests for bug #33304.
Rik <rik@octave.org>
parents: 16755
diff changeset
191 %! a *= 3 & 1;
1e1d42f0f332 parser.tst: Re-indent and add tests for bug #33304.
Rik <rik@octave.org>
parents: 16755
diff changeset
192 %! assert (a, 2);
12627
002948ae5bc0 fix precedence level of transpose operators (bug #32533)
John W. Eaton <jwe@octave.org>
parents: 12518
diff changeset
193 ## Level 4 (element-wise or)
12518
9f926b9f83cc Add operator precedence tests to fixed list of parser tests.
Rik <octave@nomad.inbox5.com>
parents: 11523
diff changeset
194 %!test
17313
1e1d42f0f332 parser.tst: Re-indent and add tests for bug #33304.
Rik <rik@octave.org>
parents: 16755
diff changeset
195 %! assert ([0 1] | 1&&0, false);
1e1d42f0f332 parser.tst: Re-indent and add tests for bug #33304.
Rik <rik@octave.org>
parents: 16755
diff changeset
196 %! assert ([0 1] | 1||0, true);
1e1d42f0f332 parser.tst: Re-indent and add tests for bug #33304.
Rik <rik@octave.org>
parents: 16755
diff changeset
197 %! a = 2;
1e1d42f0f332 parser.tst: Re-indent and add tests for bug #33304.
Rik <rik@octave.org>
parents: 16755
diff changeset
198 %! a *= 0 | 1;
1e1d42f0f332 parser.tst: Re-indent and add tests for bug #33304.
Rik <rik@octave.org>
parents: 16755
diff changeset
199 %! assert (a, 2);
12627
002948ae5bc0 fix precedence level of transpose operators (bug #32533)
John W. Eaton <jwe@octave.org>
parents: 12518
diff changeset
200 ## Level 3 (logical and)
002948ae5bc0 fix precedence level of transpose operators (bug #32533)
John W. Eaton <jwe@octave.org>
parents: 12518
diff changeset
201 %!test
17313
1e1d42f0f332 parser.tst: Re-indent and add tests for bug #33304.
Rik <rik@octave.org>
parents: 16755
diff changeset
202 %! assert (0 && 1||1, true);
1e1d42f0f332 parser.tst: Re-indent and add tests for bug #33304.
Rik <rik@octave.org>
parents: 16755
diff changeset
203 %! a = 2;
1e1d42f0f332 parser.tst: Re-indent and add tests for bug #33304.
Rik <rik@octave.org>
parents: 16755
diff changeset
204 %! a *= 3 && 1;
1e1d42f0f332 parser.tst: Re-indent and add tests for bug #33304.
Rik <rik@octave.org>
parents: 16755
diff changeset
205 %! assert (a, 2);
12627
002948ae5bc0 fix precedence level of transpose operators (bug #32533)
John W. Eaton <jwe@octave.org>
parents: 12518
diff changeset
206 ## Level 2 (logical or)
002948ae5bc0 fix precedence level of transpose operators (bug #32533)
John W. Eaton <jwe@octave.org>
parents: 12518
diff changeset
207 %!test
17313
1e1d42f0f332 parser.tst: Re-indent and add tests for bug #33304.
Rik <rik@octave.org>
parents: 16755
diff changeset
208 %! a = 2;
1e1d42f0f332 parser.tst: Re-indent and add tests for bug #33304.
Rik <rik@octave.org>
parents: 16755
diff changeset
209 %! a *= 0 || 1;
1e1d42f0f332 parser.tst: Re-indent and add tests for bug #33304.
Rik <rik@octave.org>
parents: 16755
diff changeset
210 %! assert (a, 2);
12518
9f926b9f83cc Add operator precedence tests to fixed list of parser tests.
Rik <octave@nomad.inbox5.com>
parents: 11523
diff changeset
211
12627
002948ae5bc0 fix precedence level of transpose operators (bug #32533)
John W. Eaton <jwe@octave.org>
parents: 12518
diff changeset
212 ## Tests for operator precedence within each level where ordering should
002948ae5bc0 fix precedence level of transpose operators (bug #32533)
John W. Eaton <jwe@octave.org>
parents: 12518
diff changeset
213 ## be left to right except for postfix and assignment operators.
002948ae5bc0 fix precedence level of transpose operators (bug #32533)
John W. Eaton <jwe@octave.org>
parents: 12518
diff changeset
214
002948ae5bc0 fix precedence level of transpose operators (bug #32533)
John W. Eaton <jwe@octave.org>
parents: 12518
diff changeset
215 ## Level 13 (parentheses and indexing)
12518
9f926b9f83cc Add operator precedence tests to fixed list of parser tests.
Rik <octave@nomad.inbox5.com>
parents: 11523
diff changeset
216 %!test
17313
1e1d42f0f332 parser.tst: Re-indent and add tests for bug #33304.
Rik <rik@octave.org>
parents: 16755
diff changeset
217 %! a.b1 = 2;
28916
ec591c500fa4 maint: Use Octave convention of space after function name in test/.
Rik <rik@octave.org>
parents: 28583
diff changeset
218 %! assert (a.(strcat ('b','1'))++, 2);
17313
1e1d42f0f332 parser.tst: Re-indent and add tests for bug #33304.
Rik <rik@octave.org>
parents: 16755
diff changeset
219 %! assert (a.b1, 3);
1e1d42f0f332 parser.tst: Re-indent and add tests for bug #33304.
Rik <rik@octave.org>
parents: 16755
diff changeset
220 %! b = {1 2 3 4 5};
1e1d42f0f332 parser.tst: Re-indent and add tests for bug #33304.
Rik <rik@octave.org>
parents: 16755
diff changeset
221 %! assert (b{(a. b1 + 1)}, 4);
1e1d42f0f332 parser.tst: Re-indent and add tests for bug #33304.
Rik <rik@octave.org>
parents: 16755
diff changeset
222 %! b = 1:5;
1e1d42f0f332 parser.tst: Re-indent and add tests for bug #33304.
Rik <rik@octave.org>
parents: 16755
diff changeset
223 %! assert (b(a. b1 + 1), 4);
1e1d42f0f332 parser.tst: Re-indent and add tests for bug #33304.
Rik <rik@octave.org>
parents: 16755
diff changeset
224 %! assert ([2 3].^2', [4; 9]);
12627
002948ae5bc0 fix precedence level of transpose operators (bug #32533)
John W. Eaton <jwe@octave.org>
parents: 12518
diff changeset
225 ## Level 12 (postfix increment and decrement)
002948ae5bc0 fix precedence level of transpose operators (bug #32533)
John W. Eaton <jwe@octave.org>
parents: 12518
diff changeset
226 ## No tests possible since a++-- is not valid
002948ae5bc0 fix precedence level of transpose operators (bug #32533)
John W. Eaton <jwe@octave.org>
parents: 12518
diff changeset
227 ## Level 11 (transpose and exponentiation)
17313
1e1d42f0f332 parser.tst: Re-indent and add tests for bug #33304.
Rik <rik@octave.org>
parents: 16755
diff changeset
228 %!test
30031
cf60f8f636f6 Start deprecation of Fortran exponentiation operator.
Rik <rik@octave.org>
parents: 29900
diff changeset
229 %! assert (2^3^2, 64);
17313
1e1d42f0f332 parser.tst: Re-indent and add tests for bug #33304.
Rik <rik@octave.org>
parents: 16755
diff changeset
230 %! assert ([2 3].^2.', [4;9]);
1e1d42f0f332 parser.tst: Re-indent and add tests for bug #33304.
Rik <rik@octave.org>
parents: 16755
diff changeset
231 %! assert ([2 3].'.^2, [4;9]);
1e1d42f0f332 parser.tst: Re-indent and add tests for bug #33304.
Rik <rik@octave.org>
parents: 16755
diff changeset
232 %! assert (3*4i'.', 0 - 12i);
1e1d42f0f332 parser.tst: Re-indent and add tests for bug #33304.
Rik <rik@octave.org>
parents: 16755
diff changeset
233 %! assert (3*4i.'.', 0 + 12i);
17420
577a19afdaf5 maint: Backed out changeset f81401b6b1f7.
Rik <rik@octave.org>
parents: 17419
diff changeset
234 %! assert (2^-4^3, (1/16)^3);
577a19afdaf5 maint: Backed out changeset f81401b6b1f7.
Rik <rik@octave.org>
parents: 17419
diff changeset
235 %! assert (2^+4^3, 16^3);
577a19afdaf5 maint: Backed out changeset f81401b6b1f7.
Rik <rik@octave.org>
parents: 17419
diff changeset
236 %! assert (2^~0^2, 4);
17419
f81401b6b1f7 parser.tst: known bug #33304 as xtest
Andreas Weber <andy.weber.aw@gmail.com>
parents: 17313
diff changeset
237
12627
002948ae5bc0 fix precedence level of transpose operators (bug #32533)
John W. Eaton <jwe@octave.org>
parents: 12518
diff changeset
238 ## Level 10 (unary plus/minus, prefix increment/decrement, not)
12518
9f926b9f83cc Add operator precedence tests to fixed list of parser tests.
Rik <octave@nomad.inbox5.com>
parents: 11523
diff changeset
239 %!test
17313
1e1d42f0f332 parser.tst: Re-indent and add tests for bug #33304.
Rik <rik@octave.org>
parents: 16755
diff changeset
240 %! assert (+-+1, -1);
1e1d42f0f332 parser.tst: Re-indent and add tests for bug #33304.
Rik <rik@octave.org>
parents: 16755
diff changeset
241 %! a = -1;
1e1d42f0f332 parser.tst: Re-indent and add tests for bug #33304.
Rik <rik@octave.org>
parents: 16755
diff changeset
242 %! assert (!++a, true);
1e1d42f0f332 parser.tst: Re-indent and add tests for bug #33304.
Rik <rik@octave.org>
parents: 16755
diff changeset
243 %! assert (a, 0);
1e1d42f0f332 parser.tst: Re-indent and add tests for bug #33304.
Rik <rik@octave.org>
parents: 16755
diff changeset
244 %! assert (-~a, -1);
1e1d42f0f332 parser.tst: Re-indent and add tests for bug #33304.
Rik <rik@octave.org>
parents: 16755
diff changeset
245 %! assert (!~--a, true);
1e1d42f0f332 parser.tst: Re-indent and add tests for bug #33304.
Rik <rik@octave.org>
parents: 16755
diff changeset
246 %! assert (a, -1);
12627
002948ae5bc0 fix precedence level of transpose operators (bug #32533)
John W. Eaton <jwe@octave.org>
parents: 12518
diff changeset
247 ## Level 9 (multiply, divide)
12518
9f926b9f83cc Add operator precedence tests to fixed list of parser tests.
Rik <octave@nomad.inbox5.com>
parents: 11523
diff changeset
248 %!test
17313
1e1d42f0f332 parser.tst: Re-indent and add tests for bug #33304.
Rik <rik@octave.org>
parents: 16755
diff changeset
249 %! assert (3 * 4 / 5, 2.4);
1e1d42f0f332 parser.tst: Re-indent and add tests for bug #33304.
Rik <rik@octave.org>
parents: 16755
diff changeset
250 %! assert (3 ./ 4 .* 5, 3.75);
1e1d42f0f332 parser.tst: Re-indent and add tests for bug #33304.
Rik <rik@octave.org>
parents: 16755
diff changeset
251 %! assert (2 * 4 \ 6, 0.75);
1e1d42f0f332 parser.tst: Re-indent and add tests for bug #33304.
Rik <rik@octave.org>
parents: 16755
diff changeset
252 %! assert (2 .\ 4 .* 6, 12);
12627
002948ae5bc0 fix precedence level of transpose operators (bug #32533)
John W. Eaton <jwe@octave.org>
parents: 12518
diff changeset
253 ## Level 8 (add, subtract)
12518
9f926b9f83cc Add operator precedence tests to fixed list of parser tests.
Rik <octave@nomad.inbox5.com>
parents: 11523
diff changeset
254 %!test
17313
1e1d42f0f332 parser.tst: Re-indent and add tests for bug #33304.
Rik <rik@octave.org>
parents: 16755
diff changeset
255 %! assert (-3 - 4 + 1 + 3 * 2, 0);
12627
002948ae5bc0 fix precedence level of transpose operators (bug #32533)
John W. Eaton <jwe@octave.org>
parents: 12518
diff changeset
256 ## Level 7 (colon)
17313
1e1d42f0f332 parser.tst: Re-indent and add tests for bug #33304.
Rik <rik@octave.org>
parents: 16755
diff changeset
257 ## No tests possible because colon operator can't be combined
1e1d42f0f332 parser.tst: Re-indent and add tests for bug #33304.
Rik <rik@octave.org>
parents: 16755
diff changeset
258 ## with second colon operator.
12627
002948ae5bc0 fix precedence level of transpose operators (bug #32533)
John W. Eaton <jwe@octave.org>
parents: 12518
diff changeset
259 ## Level 6 (relational)
12518
9f926b9f83cc Add operator precedence tests to fixed list of parser tests.
Rik <octave@nomad.inbox5.com>
parents: 11523
diff changeset
260 %!test
17313
1e1d42f0f332 parser.tst: Re-indent and add tests for bug #33304.
Rik <rik@octave.org>
parents: 16755
diff changeset
261 %! assert (0 < 1 <= 0.5 == 0 >= 0.5 > 0, true);
1e1d42f0f332 parser.tst: Re-indent and add tests for bug #33304.
Rik <rik@octave.org>
parents: 16755
diff changeset
262 %! assert (1 < 1 == 0 != 0, true);
1e1d42f0f332 parser.tst: Re-indent and add tests for bug #33304.
Rik <rik@octave.org>
parents: 16755
diff changeset
263 %! assert (1 < 1 == 0 ~= 0, true);
12627
002948ae5bc0 fix precedence level of transpose operators (bug #32533)
John W. Eaton <jwe@octave.org>
parents: 12518
diff changeset
264 ## Level 5 (element-wise and)
17313
1e1d42f0f332 parser.tst: Re-indent and add tests for bug #33304.
Rik <rik@octave.org>
parents: 16755
diff changeset
265 ## No tests possible. Only one operator (&) at this precedence level
1e1d42f0f332 parser.tst: Re-indent and add tests for bug #33304.
Rik <rik@octave.org>
parents: 16755
diff changeset
266 ## and operation is associative.
12627
002948ae5bc0 fix precedence level of transpose operators (bug #32533)
John W. Eaton <jwe@octave.org>
parents: 12518
diff changeset
267 ## Level 4 (element-wise or)
17313
1e1d42f0f332 parser.tst: Re-indent and add tests for bug #33304.
Rik <rik@octave.org>
parents: 16755
diff changeset
268 ## No tests possible. Only one operator (|) at this precedence level
1e1d42f0f332 parser.tst: Re-indent and add tests for bug #33304.
Rik <rik@octave.org>
parents: 16755
diff changeset
269 ## and operation is associative.
12627
002948ae5bc0 fix precedence level of transpose operators (bug #32533)
John W. Eaton <jwe@octave.org>
parents: 12518
diff changeset
270 ## Level 3 (logical and)
12518
9f926b9f83cc Add operator precedence tests to fixed list of parser tests.
Rik <octave@nomad.inbox5.com>
parents: 11523
diff changeset
271 %!test
17313
1e1d42f0f332 parser.tst: Re-indent and add tests for bug #33304.
Rik <rik@octave.org>
parents: 16755
diff changeset
272 %! a = 1;
1e1d42f0f332 parser.tst: Re-indent and add tests for bug #33304.
Rik <rik@octave.org>
parents: 16755
diff changeset
273 %! assert (1 && 0 && ++a, false);
1e1d42f0f332 parser.tst: Re-indent and add tests for bug #33304.
Rik <rik@octave.org>
parents: 16755
diff changeset
274 %! assert (a, 1);
12627
002948ae5bc0 fix precedence level of transpose operators (bug #32533)
John W. Eaton <jwe@octave.org>
parents: 12518
diff changeset
275 ## Level 2 (logical or)
002948ae5bc0 fix precedence level of transpose operators (bug #32533)
John W. Eaton <jwe@octave.org>
parents: 12518
diff changeset
276 %!test
17313
1e1d42f0f332 parser.tst: Re-indent and add tests for bug #33304.
Rik <rik@octave.org>
parents: 16755
diff changeset
277 %! a = 1;
1e1d42f0f332 parser.tst: Re-indent and add tests for bug #33304.
Rik <rik@octave.org>
parents: 16755
diff changeset
278 %! assert (0 || 1 || ++a, true);
1e1d42f0f332 parser.tst: Re-indent and add tests for bug #33304.
Rik <rik@octave.org>
parents: 16755
diff changeset
279 %! assert (a, 1);
12627
002948ae5bc0 fix precedence level of transpose operators (bug #32533)
John W. Eaton <jwe@octave.org>
parents: 12518
diff changeset
280 ## Level 1 (assignment)
12518
9f926b9f83cc Add operator precedence tests to fixed list of parser tests.
Rik <octave@nomad.inbox5.com>
parents: 11523
diff changeset
281 %!test
9f926b9f83cc Add operator precedence tests to fixed list of parser tests.
Rik <octave@nomad.inbox5.com>
parents: 11523
diff changeset
282 %! a = 2; b = 5; c = 7;
17313
1e1d42f0f332 parser.tst: Re-indent and add tests for bug #33304.
Rik <rik@octave.org>
parents: 16755
diff changeset
283 %! assert (a += b *= c += 1, 42);
1e1d42f0f332 parser.tst: Re-indent and add tests for bug #33304.
Rik <rik@octave.org>
parents: 16755
diff changeset
284 %! assert (b == 40 && c == 8);
12627
002948ae5bc0 fix precedence level of transpose operators (bug #32533)
John W. Eaton <jwe@octave.org>
parents: 12518
diff changeset
285
20588
e34692daf663 Extend parser to accept '_' in numbers.
Rik <rik@octave.org>
parents: 19697
diff changeset
286 ## Test extended number format which allows '_' as NOP character
e34692daf663 Extend parser to accept '_' in numbers.
Rik <rik@octave.org>
parents: 19697
diff changeset
287 %!assert (123_456, 123456)
e34692daf663 Extend parser to accept '_' in numbers.
Rik <rik@octave.org>
parents: 19697
diff changeset
288 %!assert (.123_456, .123456)
e34692daf663 Extend parser to accept '_' in numbers.
Rik <rik@octave.org>
parents: 19697
diff changeset
289 %!assert (123_456.123_456, 123456.123456)
28583
96e7dc4c2214 improve Matlab compatibility for binary and hexadecimal constants
John W. Eaton <jwe@octave.org>
parents: 27923
diff changeset
290 %!assert (0xAB_CD, uint16 (43981))
21317
a4faec57f4c8 maint: remove semicolon after %!assert tests to follow Octave conventions.
Rik <rik@octave.org>
parents: 21076
diff changeset
291 %!assert (2e0_1, 20)
20588
e34692daf663 Extend parser to accept '_' in numbers.
Rik <rik@octave.org>
parents: 19697
diff changeset
292
20589
7c0e10f035bd Extend parser to accept binary constants that begin with '0b' or '0B'.
Rik <rik@octave.org>
parents: 20588
diff changeset
293 ## Test binary constants
28583
96e7dc4c2214 improve Matlab compatibility for binary and hexadecimal constants
John W. Eaton <jwe@octave.org>
parents: 27923
diff changeset
294 %!assert (0b101, uint8 (5))
20589
7c0e10f035bd Extend parser to accept binary constants that begin with '0b' or '0B'.
Rik <rik@octave.org>
parents: 20588
diff changeset
295 %!assert (0B1100_0001, 0xC1)
28583
96e7dc4c2214 improve Matlab compatibility for binary and hexadecimal constants
John W. Eaton <jwe@octave.org>
parents: 27923
diff changeset
296 %!assert (class (0b1), "uint8")
20589
7c0e10f035bd Extend parser to accept binary constants that begin with '0b' or '0B'.
Rik <rik@octave.org>
parents: 20588
diff changeset
297
21636
a3a412dee704 * parser.tst: Add BIST tests for 64-bit integer literal support (bug #47690)
Mike Miller <mtmiller@octave.org>
parents: 21580
diff changeset
298 ## Test range of large binary and hexadecimal literals
28583
96e7dc4c2214 improve Matlab compatibility for binary and hexadecimal constants
John W. Eaton <jwe@octave.org>
parents: 27923
diff changeset
299 %!assert (0x8000_0000_0000_0000, uint64 (2^63))
96e7dc4c2214 improve Matlab compatibility for binary and hexadecimal constants
John W. Eaton <jwe@octave.org>
parents: 27923
diff changeset
300 %!assert (0xFFFF_FFFF_FFFF_FFFF, uint64 (2^64))
96e7dc4c2214 improve Matlab compatibility for binary and hexadecimal constants
John W. Eaton <jwe@octave.org>
parents: 27923
diff changeset
301 %!assert (0b10000000_0000000_000000000_00000000_00000000_00000000_00000000_00000000, uint64 (2^63))
96e7dc4c2214 improve Matlab compatibility for binary and hexadecimal constants
John W. Eaton <jwe@octave.org>
parents: 27923
diff changeset
302 %!assert (0b11111111_1111111_111111111_11111111_11111111_11111111_11111111_11111111, uint64 (2^64))
21636
a3a412dee704 * parser.tst: Add BIST tests for 64-bit integer literal support (bug #47690)
Mike Miller <mtmiller@octave.org>
parents: 21580
diff changeset
303
14131
c3309e1ec50d test: Use Octave coding and spacing conventions for fixed test scripts
Rik <octave@nomad.inbox5.com>
parents: 13237
diff changeset
304 ## Test creation of anonymous functions
c3309e1ec50d test: Use Octave coding and spacing conventions for fixed test scripts
Rik <octave@nomad.inbox5.com>
parents: 13237
diff changeset
305
13237
1bfca2bbea8b fix parsing of anonymous functions inside cell array lists.
John W. Eaton <jwe@octave.org>
parents: 12689
diff changeset
306 %!test
1bfca2bbea8b fix parsing of anonymous functions inside cell array lists.
John W. Eaton <jwe@octave.org>
parents: 12689
diff changeset
307 %! af_in_cell = {@(x) [1 2]};
1bfca2bbea8b fix parsing of anonymous functions inside cell array lists.
John W. Eaton <jwe@octave.org>
parents: 12689
diff changeset
308 %! assert (af_in_cell{1}(), [1, 2]);
1bfca2bbea8b fix parsing of anonymous functions inside cell array lists.
John W. Eaton <jwe@octave.org>
parents: 12689
diff changeset
309
1bfca2bbea8b fix parsing of anonymous functions inside cell array lists.
John W. Eaton <jwe@octave.org>
parents: 12689
diff changeset
310 %!test
1bfca2bbea8b fix parsing of anonymous functions inside cell array lists.
John W. Eaton <jwe@octave.org>
parents: 12689
diff changeset
311 %! R = @(rot) [cos(rot) -sin(rot); sin(rot) cos(rot)];
1bfca2bbea8b fix parsing of anonymous functions inside cell array lists.
John W. Eaton <jwe@octave.org>
parents: 12689
diff changeset
312 %! assert (R(pi/2), [cos(pi/2), -sin(pi/2); sin(pi/2),cos(pi/2)]);
14131
c3309e1ec50d test: Use Octave coding and spacing conventions for fixed test scripts
Rik <octave@nomad.inbox5.com>
parents: 13237
diff changeset
313
16755
787168f5f858 tag symbols in indexed assignments as variables (bug #39240)
John W. Eaton <jwe@octave.org>
parents: 16030
diff changeset
314 ## Check that xyz is tagged as a variable in the parser. Both
787168f5f858 tag symbols in indexed assignments as variables (bug #39240)
John W. Eaton <jwe@octave.org>
parents: 16030
diff changeset
315 ## expressions must remain on one line for this test to work as
787168f5f858 tag symbols in indexed assignments as variables (bug #39240)
John W. Eaton <jwe@octave.org>
parents: 16030
diff changeset
316 ## intended.
787168f5f858 tag symbols in indexed assignments as variables (bug #39240)
John W. Eaton <jwe@octave.org>
parents: 16030
diff changeset
317 %!test
787168f5f858 tag symbols in indexed assignments as variables (bug #39240)
John W. Eaton <jwe@octave.org>
parents: 16030
diff changeset
318 %! xyz(1) = 1; xyz /= 1;
787168f5f858 tag symbols in indexed assignments as variables (bug #39240)
John W. Eaton <jwe@octave.org>
parents: 16030
diff changeset
319 %! assert (xyz, 1);
17624
b92242ad316f parser.tst: Remove comments about bug #33304 which has been fixed.
Rik <rik@octave.org>
parents: 17622
diff changeset
320
18246
1f072ae35ede fix parsing of single quote after continuation and comment (bug #41048)
John W. Eaton <jwe@octave.org>
parents: 17744
diff changeset
321 %!test
19670
e5facc6eec13 Silence warning messages in %!test code.
Rik <rik@octave.org>
parents: 19451
diff changeset
322 %! warning ("off", "Octave:num-to-str", "local");
18246
1f072ae35ede fix parsing of single quote after continuation and comment (bug #41048)
John W. Eaton <jwe@octave.org>
parents: 17744
diff changeset
323 %! a = [97 ... % comment
1f072ae35ede fix parsing of single quote after continuation and comment (bug #41048)
John W. Eaton <jwe@octave.org>
parents: 17744
diff changeset
324 %! 'b'];
1f072ae35ede fix parsing of single quote after continuation and comment (bug #41048)
John W. Eaton <jwe@octave.org>
parents: 17744
diff changeset
325 %! assert (a, 'ab');
18492
e4c319ed2414 Fix regression, allow space-separated cell array of function handles (bug #41569)
Mike Miller <mtmiller@ieee.org>
parents: 18246
diff changeset
326
e4c319ed2414 Fix regression, allow space-separated cell array of function handles (bug #41569)
Mike Miller <mtmiller@ieee.org>
parents: 18246
diff changeset
327 ## Check that a cell array containing function handles is parsed
e4c319ed2414 Fix regression, allow space-separated cell array of function handles (bug #41569)
Mike Miller <mtmiller@ieee.org>
parents: 18246
diff changeset
328 ## correctly with or without commas.
e4c319ed2414 Fix regression, allow space-separated cell array of function handles (bug #41569)
Mike Miller <mtmiller@ieee.org>
parents: 18246
diff changeset
329 %!test
e4c319ed2414 Fix regression, allow space-separated cell array of function handles (bug #41569)
Mike Miller <mtmiller@ieee.org>
parents: 18246
diff changeset
330 %! a = {1, @sin, 2, @cos};
e4c319ed2414 Fix regression, allow space-separated cell array of function handles (bug #41569)
Mike Miller <mtmiller@ieee.org>
parents: 18246
diff changeset
331 %! b = {1 @sin 2 @cos};
21580
ecce63c99c3f maint: Add semicolons to terminate code in %! blocks.
Rik <rik@octave.org>
parents: 21317
diff changeset
332 %! assert (a, b);
20775
cd50ce72fa24 parser.tst: Add test for resolved bug #46534.
Rik <rik@octave.org>
parents: 20589
diff changeset
333
21076
b433f9990452 strip trailing whitespace from files
John W. Eaton <jwe@octave.org>
parents: 20775
diff changeset
334 ## Maybe unnecessary, but check that further changes to parser don't
20775
cd50ce72fa24 parser.tst: Add test for resolved bug #46534.
Rik <rik@octave.org>
parents: 20589
diff changeset
335 ## invalidate error handling (bug #46534).
cd50ce72fa24 parser.tst: Add test for resolved bug #46534.
Rik <rik@octave.org>
parents: 20589
diff changeset
336 #!error <vertical dimensions mismatch \(1x2 vs 1x1\)> z = [1, 2; 3]
24338
1212ffc13d24 Fix concatenation of empty char matrices with other strings (bug #52542).
Rik <rik@octave.org>
parents: 23219
diff changeset
337
23788
c94e9509461b restore parse tree dup function delete in changeset 214cb58ccc1c
John W. Eaton <jwe@octave.org>
parents: 23220
diff changeset
338 %!test
28916
ec591c500fa4 maint: Use Octave convention of space after function name in test/.
Rik <rik@octave.org>
parents: 28583
diff changeset
339 %! f = @(s,t=toeplitz (s),u=t(x=2:end-1,x)=32)t;
23788
c94e9509461b restore parse tree dup function delete in changeset 214cb58ccc1c
John W. Eaton <jwe@octave.org>
parents: 23220
diff changeset
340 %! assert (f (1), 1);
c94e9509461b restore parse tree dup function delete in changeset 214cb58ccc1c
John W. Eaton <jwe@octave.org>
parents: 23220
diff changeset
341 %! assert (f (1, 2), 2);
24339
648616b26cc6 maint: merge of stable to default.
Rik <rik@octave.org>
parents: 23788 24338
diff changeset
342
24338
1212ffc13d24 Fix concatenation of empty char matrices with other strings (bug #52542).
Rik <rik@octave.org>
parents: 23219
diff changeset
343 ## FIXME: We need a sequence of concatenation tests since this seems
1212ffc13d24 Fix concatenation of empty char matrices with other strings (bug #52542).
Rik <rik@octave.org>
parents: 23219
diff changeset
344 ## to be a frequently reported source of incompatibilities w/Matlab
1212ffc13d24 Fix concatenation of empty char matrices with other strings (bug #52542).
Rik <rik@octave.org>
parents: 23219
diff changeset
345 ## Check concatenation of empty char matrices (bug #52542)
1212ffc13d24 Fix concatenation of empty char matrices with other strings (bug #52542).
Rik <rik@octave.org>
parents: 23219
diff changeset
346 %!assert (double ([char(ones(0,3)); 'A']), 65)
1212ffc13d24 Fix concatenation of empty char matrices with other strings (bug #52542).
Rik <rik@octave.org>
parents: 23219
diff changeset
347 %!assert (double ([char(ones(0,3)); char(ones(2,0)); 'A']), 65)
25753
b5dc88246c02 disable compound binary operator optimization (bug #54465)
John W. Eaton <jwe@octave.org>
parents: 25054
diff changeset
348
b5dc88246c02 disable compound binary operator optimization (bug #54465)
John W. Eaton <jwe@octave.org>
parents: 25054
diff changeset
349 %!test <*54465>
b5dc88246c02 disable compound binary operator optimization (bug #54465)
John W. Eaton <jwe@octave.org>
parents: 25054
diff changeset
350 %! x = 0;
b5dc88246c02 disable compound binary operator optimization (bug #54465)
John W. Eaton <jwe@octave.org>
parents: 25054
diff changeset
351 %! if (! 0 || (x = 1))
b5dc88246c02 disable compound binary operator optimization (bug #54465)
John W. Eaton <jwe@octave.org>
parents: 25054
diff changeset
352 %! endif
b5dc88246c02 disable compound binary operator optimization (bug #54465)
John W. Eaton <jwe@octave.org>
parents: 25054
diff changeset
353 %! assert (x == 0);
b5dc88246c02 disable compound binary operator optimization (bug #54465)
John W. Eaton <jwe@octave.org>
parents: 25054
diff changeset
354
b5dc88246c02 disable compound binary operator optimization (bug #54465)
John W. Eaton <jwe@octave.org>
parents: 25054
diff changeset
355 %!function x = matlab_short_circuit ()
b5dc88246c02 disable compound binary operator optimization (bug #54465)
John W. Eaton <jwe@octave.org>
parents: 25054
diff changeset
356 %! x = 0;
b5dc88246c02 disable compound binary operator optimization (bug #54465)
John W. Eaton <jwe@octave.org>
parents: 25054
diff changeset
357 %! if (! 0 | (x = 1))
b5dc88246c02 disable compound binary operator optimization (bug #54465)
John W. Eaton <jwe@octave.org>
parents: 25054
diff changeset
358 %! endif
b5dc88246c02 disable compound binary operator optimization (bug #54465)
John W. Eaton <jwe@octave.org>
parents: 25054
diff changeset
359 %!endfunction
b5dc88246c02 disable compound binary operator optimization (bug #54465)
John W. Eaton <jwe@octave.org>
parents: 25054
diff changeset
360 %!test <*54465>
b5dc88246c02 disable compound binary operator optimization (bug #54465)
John W. Eaton <jwe@octave.org>
parents: 25054
diff changeset
361 %! fail ("x = matlab_short_circuit ()", "warning", "Matlab-style short-circuit operation performed for operator |");
b5dc88246c02 disable compound binary operator optimization (bug #54465)
John W. Eaton <jwe@octave.org>
parents: 25054
diff changeset
362 %! assert (x == 0);
27489
c2c9185d3389 Issue warning when range expression contains a complex number (bug #56959).
Rik <rik@octave.org>
parents: 26376
diff changeset
363
c2c9185d3389 Issue warning when range expression contains a complex number (bug #56959).
Rik <rik@octave.org>
parents: 26376
diff changeset
364 %!test <*56959>
27490
19ba2619d746 More informative warning message when range expression has a complex number (bug #56959).
Rik <rik@octave.org>
parents: 27489
diff changeset
365 %! fail ("i:5", "warning", "imaginary part of complex colon arguments is ignored");
19ba2619d746 More informative warning message when range expression has a complex number (bug #56959).
Rik <rik@octave.org>
parents: 27489
diff changeset
366 %! fail ("1:5*i", "warning", "imaginary part of complex colon arguments is ignored");
19ba2619d746 More informative warning message when range expression has a complex number (bug #56959).
Rik <rik@octave.org>
parents: 27489
diff changeset
367 %! fail ("1:i:5", "warning", "imaginary part of complex colon arguments is ignored");