annotate test/parser.tst @ 20624:7c0e10f035bd

Extend parser to accept binary constants that begin with '0b' or '0B'. * NEWS: Announce change: * lex.ll: Define NUMBIN to be 0[bB] followed by 0,1, or '_'. Define NUMBER to be NUMREAL|NUMHEX|NUMBIN. *lex.ll (looks_like_bin): New function to detect 0[bB] prefix. *lex.ll (handle_numbe): Call looks_like_bin() and if found then convert binary string to double. * parser.tst: Add tests for new behavior.
author Rik <rik@octave.org>
date Fri, 09 Oct 2015 18:52:58 -0700
parents e34692daf663
children
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
19731
4197fc428c7d maint: Update copyright notices for 2015.
John W. Eaton <jwe@octave.org>
parents: 19704
diff changeset
1 ## Copyright (C) 2010-2015 John W. Eaton
11218
0910020c5ab6 add omitted file from previous change
John W. Eaton <jwe@octave.org>
parents:
diff changeset
2 ##
0910020c5ab6 add omitted file from previous change
John W. Eaton <jwe@octave.org>
parents:
diff changeset
3 ## This file is part of Octave.
0910020c5ab6 add omitted file from previous change
John W. Eaton <jwe@octave.org>
parents:
diff changeset
4 ##
0910020c5ab6 add omitted file from previous change
John W. Eaton <jwe@octave.org>
parents:
diff changeset
5 ## Octave is free software; you can redistribute it and/or modify it
0910020c5ab6 add omitted file from previous change
John W. Eaton <jwe@octave.org>
parents:
diff changeset
6 ## under the terms of the GNU General Public License as published by
0910020c5ab6 add omitted file from previous change
John W. Eaton <jwe@octave.org>
parents:
diff changeset
7 ## the Free Software Foundation; either version 3 of the License, or (at
0910020c5ab6 add omitted file from previous change
John W. Eaton <jwe@octave.org>
parents:
diff changeset
8 ## your option) any later version.
0910020c5ab6 add omitted file from previous change
John W. Eaton <jwe@octave.org>
parents:
diff changeset
9 ##
0910020c5ab6 add omitted file from previous change
John W. Eaton <jwe@octave.org>
parents:
diff changeset
10 ## 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
11 ## WITHOUT ANY WARRANTY; without even the implied warranty of
0910020c5ab6 add omitted file from previous change
John W. Eaton <jwe@octave.org>
parents:
diff changeset
12 ## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
0910020c5ab6 add omitted file from previous change
John W. Eaton <jwe@octave.org>
parents:
diff changeset
13 ## General Public License for more details.
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 ## 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
16 ## along with Octave; see the file COPYING. If not, see
0910020c5ab6 add omitted file from previous change
John W. Eaton <jwe@octave.org>
parents:
diff changeset
17 ## <http://www.gnu.org/licenses/>.
0910020c5ab6 add omitted file from previous change
John W. Eaton <jwe@octave.org>
parents:
diff changeset
18
14131
c3309e1ec50d test: Use Octave coding and spacing conventions for fixed test scripts
Rik <octave@nomad.inbox5.com>
parents: 13237
diff changeset
19 ## 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
20 ## We need many more tests here!
11218
0910020c5ab6 add omitted file from previous change
John W. Eaton <jwe@octave.org>
parents:
diff changeset
21
19485
e5a78897be9e Allow empty comma-separated lists in cell { } constructor (bug #43113).
Rik <rik@octave.org>
parents: 18492
diff changeset
22 ## Test cell construction operator {}
11218
0910020c5ab6 add omitted file from previous change
John W. Eaton <jwe@octave.org>
parents:
diff changeset
23 %!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
24 %!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
25 %!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
26 %!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
27 %!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
28 %!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
29 %!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
30 %!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
31
19485
e5a78897be9e Allow empty comma-separated lists in cell { } constructor (bug #43113).
Rik <rik@octave.org>
parents: 18492
diff changeset
32 ## 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
33 %!test
e5a78897be9e Allow empty comma-separated lists in cell { } constructor (bug #43113).
Rik <rik@octave.org>
parents: 18492
diff changeset
34 %! 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
35 %! 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
36 %! 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
37 %! 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
38 %! 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
39
12627
002948ae5bc0 fix precedence level of transpose operators (bug #32533)
John W. Eaton <jwe@octave.org>
parents: 12518
diff changeset
40 ## 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
41 ## 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
42 ## down to "statement operators" (lowest).
002948ae5bc0 fix precedence level of transpose operators (bug #32533)
John W. Eaton <jwe@octave.org>
parents: 12518
diff changeset
43 ##
002948ae5bc0 fix precedence level of transpose operators (bug #32533)
John W. Eaton <jwe@octave.org>
parents: 12518
diff changeset
44 ## Level 13 (parentheses and indexing)
002948ae5bc0 fix precedence level of transpose operators (bug #32533)
John W. Eaton <jwe@octave.org>
parents: 12518
diff changeset
45 ## Overrides all other levels
002948ae5bc0 fix precedence level of transpose operators (bug #32533)
John W. Eaton <jwe@octave.org>
parents: 12518
diff changeset
46 %!test
17313
1e1d42f0f332 parser.tst: Re-indent and add tests for bug #33304.
Rik <rik@octave.org>
parents: 16755
diff changeset
47 %! a.b = 1;
1e1d42f0f332 parser.tst: Re-indent and add tests for bug #33304.
Rik <rik@octave.org>
parents: 16755
diff changeset
48 %! assert (a. b++, 1);
1e1d42f0f332 parser.tst: Re-indent and add tests for bug #33304.
Rik <rik@octave.org>
parents: 16755
diff changeset
49 %! assert (a.b, 2);
1e1d42f0f332 parser.tst: Re-indent and add tests for bug #33304.
Rik <rik@octave.org>
parents: 16755
diff changeset
50 %! clear a;
1e1d42f0f332 parser.tst: Re-indent and add tests for bug #33304.
Rik <rik@octave.org>
parents: 16755
diff changeset
51 %! a.b = [0 1];
1e1d42f0f332 parser.tst: Re-indent and add tests for bug #33304.
Rik <rik@octave.org>
parents: 16755
diff changeset
52 %! b = 2;
1e1d42f0f332 parser.tst: Re-indent and add tests for bug #33304.
Rik <rik@octave.org>
parents: 16755
diff changeset
53 %! assert (a.b', [0;1]);
1e1d42f0f332 parser.tst: Re-indent and add tests for bug #33304.
Rik <rik@octave.org>
parents: 16755
diff changeset
54 %! 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
55 %! 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
56 %! assert (a. b-1, [-1 0]);
1e1d42f0f332 parser.tst: Re-indent and add tests for bug #33304.
Rik <rik@octave.org>
parents: 16755
diff changeset
57 %! 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
58 %! 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
59 %! 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
60 %! 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
61 %! a.b = [1 2];
1e1d42f0f332 parser.tst: Re-indent and add tests for bug #33304.
Rik <rik@octave.org>
parents: 16755
diff changeset
62 %! assert (a. b&&0, false);
1e1d42f0f332 parser.tst: Re-indent and add tests for bug #33304.
Rik <rik@octave.org>
parents: 16755
diff changeset
63 %! assert (a. b||0, true);
1e1d42f0f332 parser.tst: Re-indent and add tests for bug #33304.
Rik <rik@octave.org>
parents: 16755
diff changeset
64 %! a.b += a. b*2;
1e1d42f0f332 parser.tst: Re-indent and add tests for bug #33304.
Rik <rik@octave.org>
parents: 16755
diff changeset
65 %! 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
66 ## 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
67 %!test
17313
1e1d42f0f332 parser.tst: Re-indent and add tests for bug #33304.
Rik <rik@octave.org>
parents: 16755
diff changeset
68 %! a = [3 5];
1e1d42f0f332 parser.tst: Re-indent and add tests for bug #33304.
Rik <rik@octave.org>
parents: 16755
diff changeset
69 %! assert (2.^a ++, [8 32]);
1e1d42f0f332 parser.tst: Re-indent and add tests for bug #33304.
Rik <rik@octave.org>
parents: 16755
diff changeset
70 %! assert (a, [4 6]);
1e1d42f0f332 parser.tst: Re-indent and add tests for bug #33304.
Rik <rik@octave.org>
parents: 16755
diff changeset
71 %! assert (a--', [4; 6]);
1e1d42f0f332 parser.tst: Re-indent and add tests for bug #33304.
Rik <rik@octave.org>
parents: 16755
diff changeset
72 %! assert (a, [3 5]);
1e1d42f0f332 parser.tst: Re-indent and add tests for bug #33304.
Rik <rik@octave.org>
parents: 16755
diff changeset
73 %! a = 0;
1e1d42f0f332 parser.tst: Re-indent and add tests for bug #33304.
Rik <rik@octave.org>
parents: 16755
diff changeset
74 %! assert (!a --, true);
1e1d42f0f332 parser.tst: Re-indent and add tests for bug #33304.
Rik <rik@octave.org>
parents: 16755
diff changeset
75 %! assert (-a ++, 1);
1e1d42f0f332 parser.tst: Re-indent and add tests for bug #33304.
Rik <rik@octave.org>
parents: 16755
diff changeset
76 %! assert (3*a ++, 0);
1e1d42f0f332 parser.tst: Re-indent and add tests for bug #33304.
Rik <rik@octave.org>
parents: 16755
diff changeset
77 %! assert (a++-2, -1);
1e1d42f0f332 parser.tst: Re-indent and add tests for bug #33304.
Rik <rik@octave.org>
parents: 16755
diff changeset
78 %! assert (1:a ++, 1:2);
1e1d42f0f332 parser.tst: Re-indent and add tests for bug #33304.
Rik <rik@octave.org>
parents: 16755
diff changeset
79 %! assert (4>a++, true);
1e1d42f0f332 parser.tst: Re-indent and add tests for bug #33304.
Rik <rik@octave.org>
parents: 16755
diff changeset
80 %! a = [0 -1];
1e1d42f0f332 parser.tst: Re-indent and add tests for bug #33304.
Rik <rik@octave.org>
parents: 16755
diff changeset
81 %! 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
82 %! 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
83 %! a = 0;
1e1d42f0f332 parser.tst: Re-indent and add tests for bug #33304.
Rik <rik@octave.org>
parents: 16755
diff changeset
84 %! assert (1 && a ++, false);
1e1d42f0f332 parser.tst: Re-indent and add tests for bug #33304.
Rik <rik@octave.org>
parents: 16755
diff changeset
85 %! assert (0 || a --, true);
1e1d42f0f332 parser.tst: Re-indent and add tests for bug #33304.
Rik <rik@octave.org>
parents: 16755
diff changeset
86 %! a = 5; b = 2;
1e1d42f0f332 parser.tst: Re-indent and add tests for bug #33304.
Rik <rik@octave.org>
parents: 16755
diff changeset
87 %! b +=a ++;
1e1d42f0f332 parser.tst: Re-indent and add tests for bug #33304.
Rik <rik@octave.org>
parents: 16755
diff changeset
88 %! assert (b, 7);
12627
002948ae5bc0 fix precedence level of transpose operators (bug #32533)
John W. Eaton <jwe@octave.org>
parents: 12518
diff changeset
89
002948ae5bc0 fix precedence level of transpose operators (bug #32533)
John W. Eaton <jwe@octave.org>
parents: 12518
diff changeset
90 ## Level 11 (transpose and exponentiation)
002948ae5bc0 fix precedence level of transpose operators (bug #32533)
John W. Eaton <jwe@octave.org>
parents: 12518
diff changeset
91 %!test
17622
fd712a12fe53 compatibility for power operator precedence and direction (bug #33304)
Axel Mathéi <axel.mathei@gmail.com>
parents: 17420
diff changeset
92 %! a = 2;
fd712a12fe53 compatibility for power operator precedence and direction (bug #33304)
Axel Mathéi <axel.mathei@gmail.com>
parents: 17420
diff changeset
93 %! assert (2 ^a++, 4)
fd712a12fe53 compatibility for power operator precedence and direction (bug #33304)
Axel Mathéi <axel.mathei@gmail.com>
parents: 17420
diff changeset
94 %! assert (a, 3)
fd712a12fe53 compatibility for power operator precedence and direction (bug #33304)
Axel Mathéi <axel.mathei@gmail.com>
parents: 17420
diff changeset
95 %! assert (2 ^--a ^2, 16)
fd712a12fe53 compatibility for power operator precedence and direction (bug #33304)
Axel Mathéi <axel.mathei@gmail.com>
parents: 17420
diff changeset
96 %! assert (a, 2)
fd712a12fe53 compatibility for power operator precedence and direction (bug #33304)
Axel Mathéi <axel.mathei@gmail.com>
parents: 17420
diff changeset
97 %! assert (2 ^++a, 8)
fd712a12fe53 compatibility for power operator precedence and direction (bug #33304)
Axel Mathéi <axel.mathei@gmail.com>
parents: 17420
diff changeset
98 %! assert (a, 3)
fd712a12fe53 compatibility for power operator precedence and direction (bug #33304)
Axel Mathéi <axel.mathei@gmail.com>
parents: 17420
diff changeset
99 %! assert (a' ^2, 9)
fd712a12fe53 compatibility for power operator precedence and direction (bug #33304)
Axel Mathéi <axel.mathei@gmail.com>
parents: 17420
diff changeset
100 %! assert (2 ^sin(0), 1)
17313
1e1d42f0f332 parser.tst: Re-indent and add tests for bug #33304.
Rik <rik@octave.org>
parents: 16755
diff changeset
101 %! assert (-2 ^2, -4);
17622
fd712a12fe53 compatibility for power operator precedence and direction (bug #33304)
Axel Mathéi <axel.mathei@gmail.com>
parents: 17420
diff changeset
102 %! assert (2 ^+1 ^3, 8)
fd712a12fe53 compatibility for power operator precedence and direction (bug #33304)
Axel Mathéi <axel.mathei@gmail.com>
parents: 17420
diff changeset
103 %! assert (2 ^-1 ^3, 0.125)
fd712a12fe53 compatibility for power operator precedence and direction (bug #33304)
Axel Mathéi <axel.mathei@gmail.com>
parents: 17420
diff changeset
104 %! 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
105 %! assert (!0 ^0, false);
1e1d42f0f332 parser.tst: Re-indent and add tests for bug #33304.
Rik <rik@octave.org>
parents: 16755
diff changeset
106 %! assert (2*3 ^2, 18);
1e1d42f0f332 parser.tst: Re-indent and add tests for bug #33304.
Rik <rik@octave.org>
parents: 16755
diff changeset
107 %! assert (2+3 ^2, 11);
1e1d42f0f332 parser.tst: Re-indent and add tests for bug #33304.
Rik <rik@octave.org>
parents: 16755
diff changeset
108 %! 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
109 %! assert (3>2 ^2, false);
1e1d42f0f332 parser.tst: Re-indent and add tests for bug #33304.
Rik <rik@octave.org>
parents: 16755
diff changeset
110 %! assert (1&0 ^0, true);
1e1d42f0f332 parser.tst: Re-indent and add tests for bug #33304.
Rik <rik@octave.org>
parents: 16755
diff changeset
111 %! assert (0|0 ^0, true);
1e1d42f0f332 parser.tst: Re-indent and add tests for bug #33304.
Rik <rik@octave.org>
parents: 16755
diff changeset
112 %! assert (1&&0 ^0, true);
1e1d42f0f332 parser.tst: Re-indent and add tests for bug #33304.
Rik <rik@octave.org>
parents: 16755
diff changeset
113 %! assert (0||0 ^0, true);
1e1d42f0f332 parser.tst: Re-indent and add tests for bug #33304.
Rik <rik@octave.org>
parents: 16755
diff changeset
114 %! a = 3;
1e1d42f0f332 parser.tst: Re-indent and add tests for bug #33304.
Rik <rik@octave.org>
parents: 16755
diff changeset
115 %! a *= 0 ^0;
1e1d42f0f332 parser.tst: Re-indent and add tests for bug #33304.
Rik <rik@octave.org>
parents: 16755
diff changeset
116 %! assert (a, 3);
12627
002948ae5bc0 fix precedence level of transpose operators (bug #32533)
John W. Eaton <jwe@octave.org>
parents: 12518
diff changeset
117 ## 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
118 %!test
17313
1e1d42f0f332 parser.tst: Re-indent and add tests for bug #33304.
Rik <rik@octave.org>
parents: 16755
diff changeset
119 %! a = 2;
1e1d42f0f332 parser.tst: Re-indent and add tests for bug #33304.
Rik <rik@octave.org>
parents: 16755
diff changeset
120 %! assert (++ a*3, 9);
1e1d42f0f332 parser.tst: Re-indent and add tests for bug #33304.
Rik <rik@octave.org>
parents: 16755
diff changeset
121 %! assert (-- a-2, 0);
1e1d42f0f332 parser.tst: Re-indent and add tests for bug #33304.
Rik <rik@octave.org>
parents: 16755
diff changeset
122 %! assert (a, 2);
1e1d42f0f332 parser.tst: Re-indent and add tests for bug #33304.
Rik <rik@octave.org>
parents: 16755
diff changeset
123 %! assert (! a-2, -2);
1e1d42f0f332 parser.tst: Re-indent and add tests for bug #33304.
Rik <rik@octave.org>
parents: 16755
diff changeset
124 %! 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
125 %! a = [1 0];
1e1d42f0f332 parser.tst: Re-indent and add tests for bug #33304.
Rik <rik@octave.org>
parents: 16755
diff changeset
126 %! 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
127 %! a = 0;
1e1d42f0f332 parser.tst: Re-indent and add tests for bug #33304.
Rik <rik@octave.org>
parents: 16755
diff changeset
128 %! assert (++ a&1, true);
1e1d42f0f332 parser.tst: Re-indent and add tests for bug #33304.
Rik <rik@octave.org>
parents: 16755
diff changeset
129 %! assert (-- a|0, false);
1e1d42f0f332 parser.tst: Re-indent and add tests for bug #33304.
Rik <rik@octave.org>
parents: 16755
diff changeset
130 %! assert (-- a&&1, true);
1e1d42f0f332 parser.tst: Re-indent and add tests for bug #33304.
Rik <rik@octave.org>
parents: 16755
diff changeset
131 %! assert (++ a||0, false);
1e1d42f0f332 parser.tst: Re-indent and add tests for bug #33304.
Rik <rik@octave.org>
parents: 16755
diff changeset
132 %! a = 3;
1e1d42f0f332 parser.tst: Re-indent and add tests for bug #33304.
Rik <rik@octave.org>
parents: 16755
diff changeset
133 %! a *= ++a;
1e1d42f0f332 parser.tst: Re-indent and add tests for bug #33304.
Rik <rik@octave.org>
parents: 16755
diff changeset
134 %! assert (a, 16);
12627
002948ae5bc0 fix precedence level of transpose operators (bug #32533)
John W. Eaton <jwe@octave.org>
parents: 12518
diff changeset
135 ## 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
136 %!test
17313
1e1d42f0f332 parser.tst: Re-indent and add tests for bug #33304.
Rik <rik@octave.org>
parents: 16755
diff changeset
137 %! assert (3+4 * 5, 23);
1e1d42f0f332 parser.tst: Re-indent and add tests for bug #33304.
Rik <rik@octave.org>
parents: 16755
diff changeset
138 %! 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
139 %! assert (3>1 * 5, false);
1e1d42f0f332 parser.tst: Re-indent and add tests for bug #33304.
Rik <rik@octave.org>
parents: 16755
diff changeset
140 %! assert (1&1 * 0, false);
1e1d42f0f332 parser.tst: Re-indent and add tests for bug #33304.
Rik <rik@octave.org>
parents: 16755
diff changeset
141 %! assert (1|1 * 0, true);
1e1d42f0f332 parser.tst: Re-indent and add tests for bug #33304.
Rik <rik@octave.org>
parents: 16755
diff changeset
142 %! assert (1&&1 * 0, false);
1e1d42f0f332 parser.tst: Re-indent and add tests for bug #33304.
Rik <rik@octave.org>
parents: 16755
diff changeset
143 %! assert (1||1 * 0, true);
1e1d42f0f332 parser.tst: Re-indent and add tests for bug #33304.
Rik <rik@octave.org>
parents: 16755
diff changeset
144 %! a = 3;
1e1d42f0f332 parser.tst: Re-indent and add tests for bug #33304.
Rik <rik@octave.org>
parents: 16755
diff changeset
145 %! a /= a * 2;
1e1d42f0f332 parser.tst: Re-indent and add tests for bug #33304.
Rik <rik@octave.org>
parents: 16755
diff changeset
146 %! assert (a, 0.5);
12627
002948ae5bc0 fix precedence level of transpose operators (bug #32533)
John W. Eaton <jwe@octave.org>
parents: 12518
diff changeset
147 ## 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
148 %!test
17313
1e1d42f0f332 parser.tst: Re-indent and add tests for bug #33304.
Rik <rik@octave.org>
parents: 16755
diff changeset
149 %! 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
150 %! assert (3>1 + 5, false);
1e1d42f0f332 parser.tst: Re-indent and add tests for bug #33304.
Rik <rik@octave.org>
parents: 16755
diff changeset
151 %! assert (1&1 - 1, false);
1e1d42f0f332 parser.tst: Re-indent and add tests for bug #33304.
Rik <rik@octave.org>
parents: 16755
diff changeset
152 %! assert (0|1 - 2, true);
1e1d42f0f332 parser.tst: Re-indent and add tests for bug #33304.
Rik <rik@octave.org>
parents: 16755
diff changeset
153 %! assert (1&&1 - 1, false);
1e1d42f0f332 parser.tst: Re-indent and add tests for bug #33304.
Rik <rik@octave.org>
parents: 16755
diff changeset
154 %! assert (0||1 - 2, true);
1e1d42f0f332 parser.tst: Re-indent and add tests for bug #33304.
Rik <rik@octave.org>
parents: 16755
diff changeset
155 %! a = 3;
1e1d42f0f332 parser.tst: Re-indent and add tests for bug #33304.
Rik <rik@octave.org>
parents: 16755
diff changeset
156 %! a *= 1 + 1;
1e1d42f0f332 parser.tst: Re-indent and add tests for bug #33304.
Rik <rik@octave.org>
parents: 16755
diff changeset
157 %! assert (a, 6);
12627
002948ae5bc0 fix precedence level of transpose operators (bug #32533)
John W. Eaton <jwe@octave.org>
parents: 12518
diff changeset
158 ## Level 7 (colon)
12518
9f926b9f83cc Add operator precedence tests to fixed list of parser tests.
Rik <octave@nomad.inbox5.com>
parents: 11523
diff changeset
159 %!test
17313
1e1d42f0f332 parser.tst: Re-indent and add tests for bug #33304.
Rik <rik@octave.org>
parents: 16755
diff changeset
160 %! 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
161 %! 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
162 %! 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
163 %! assert (-1: 3&&1, false);
1e1d42f0f332 parser.tst: Re-indent and add tests for bug #33304.
Rik <rik@octave.org>
parents: 16755
diff changeset
164 %! assert (-1: 3||0, false);
1e1d42f0f332 parser.tst: Re-indent and add tests for bug #33304.
Rik <rik@octave.org>
parents: 16755
diff changeset
165 %! a = [1:3];
1e1d42f0f332 parser.tst: Re-indent and add tests for bug #33304.
Rik <rik@octave.org>
parents: 16755
diff changeset
166 %! a += 3 : 5;
1e1d42f0f332 parser.tst: Re-indent and add tests for bug #33304.
Rik <rik@octave.org>
parents: 16755
diff changeset
167 %! 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
168 ## Level 6 (relational)
12518
9f926b9f83cc Add operator precedence tests to fixed list of parser tests.
Rik <octave@nomad.inbox5.com>
parents: 11523
diff changeset
169 %!test
17313
1e1d42f0f332 parser.tst: Re-indent and add tests for bug #33304.
Rik <rik@octave.org>
parents: 16755
diff changeset
170 %! assert (0 == -1&0, false);
1e1d42f0f332 parser.tst: Re-indent and add tests for bug #33304.
Rik <rik@octave.org>
parents: 16755
diff changeset
171 %! assert (1 == -1|0, false);
1e1d42f0f332 parser.tst: Re-indent and add tests for bug #33304.
Rik <rik@octave.org>
parents: 16755
diff changeset
172 %! assert (0 == -1&&0, false);
1e1d42f0f332 parser.tst: Re-indent and add tests for bug #33304.
Rik <rik@octave.org>
parents: 16755
diff changeset
173 %! assert (1 == -1||0, false);
1e1d42f0f332 parser.tst: Re-indent and add tests for bug #33304.
Rik <rik@octave.org>
parents: 16755
diff changeset
174 %! a = 2;
1e1d42f0f332 parser.tst: Re-indent and add tests for bug #33304.
Rik <rik@octave.org>
parents: 16755
diff changeset
175 %! a *= 3 > 1;
1e1d42f0f332 parser.tst: Re-indent and add tests for bug #33304.
Rik <rik@octave.org>
parents: 16755
diff changeset
176 %! assert (a, 2);
12627
002948ae5bc0 fix precedence level of transpose operators (bug #32533)
John W. Eaton <jwe@octave.org>
parents: 12518
diff changeset
177 ## 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
178 %!test
17313
1e1d42f0f332 parser.tst: Re-indent and add tests for bug #33304.
Rik <rik@octave.org>
parents: 16755
diff changeset
179 %! assert (0 & 1|1, true);
1e1d42f0f332 parser.tst: Re-indent and add tests for bug #33304.
Rik <rik@octave.org>
parents: 16755
diff changeset
180 %! 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
181 %! assert (0 & 1||1, true);
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 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
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&&0, false);
1e1d42f0f332 parser.tst: Re-indent and add tests for bug #33304.
Rik <rik@octave.org>
parents: 16755
diff changeset
188 %! 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
189 %! a = 2;
1e1d42f0f332 parser.tst: Re-indent and add tests for bug #33304.
Rik <rik@octave.org>
parents: 16755
diff changeset
190 %! a *= 0 | 1;
1e1d42f0f332 parser.tst: Re-indent and add tests for bug #33304.
Rik <rik@octave.org>
parents: 16755
diff changeset
191 %! assert (a, 2);
12627
002948ae5bc0 fix precedence level of transpose operators (bug #32533)
John W. Eaton <jwe@octave.org>
parents: 12518
diff changeset
192 ## Level 3 (logical and)
002948ae5bc0 fix precedence level of transpose operators (bug #32533)
John W. Eaton <jwe@octave.org>
parents: 12518
diff changeset
193 %!test
17313
1e1d42f0f332 parser.tst: Re-indent and add tests for bug #33304.
Rik <rik@octave.org>
parents: 16755
diff changeset
194 %! assert (0 && 1||1, true);
1e1d42f0f332 parser.tst: Re-indent and add tests for bug #33304.
Rik <rik@octave.org>
parents: 16755
diff changeset
195 %! a = 2;
1e1d42f0f332 parser.tst: Re-indent and add tests for bug #33304.
Rik <rik@octave.org>
parents: 16755
diff changeset
196 %! a *= 3 && 1;
1e1d42f0f332 parser.tst: Re-indent and add tests for bug #33304.
Rik <rik@octave.org>
parents: 16755
diff changeset
197 %! assert (a, 2);
12627
002948ae5bc0 fix precedence level of transpose operators (bug #32533)
John W. Eaton <jwe@octave.org>
parents: 12518
diff changeset
198 ## Level 2 (logical or)
002948ae5bc0 fix precedence level of transpose operators (bug #32533)
John W. Eaton <jwe@octave.org>
parents: 12518
diff changeset
199 %!test
17313
1e1d42f0f332 parser.tst: Re-indent and add tests for bug #33304.
Rik <rik@octave.org>
parents: 16755
diff changeset
200 %! a = 2;
1e1d42f0f332 parser.tst: Re-indent and add tests for bug #33304.
Rik <rik@octave.org>
parents: 16755
diff changeset
201 %! a *= 0 || 1;
1e1d42f0f332 parser.tst: Re-indent and add tests for bug #33304.
Rik <rik@octave.org>
parents: 16755
diff changeset
202 %! assert (a, 2);
12518
9f926b9f83cc Add operator precedence tests to fixed list of parser tests.
Rik <octave@nomad.inbox5.com>
parents: 11523
diff changeset
203
12627
002948ae5bc0 fix precedence level of transpose operators (bug #32533)
John W. Eaton <jwe@octave.org>
parents: 12518
diff changeset
204 ## 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
205 ## 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
206
002948ae5bc0 fix precedence level of transpose operators (bug #32533)
John W. Eaton <jwe@octave.org>
parents: 12518
diff changeset
207 ## 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
208 %!test
17313
1e1d42f0f332 parser.tst: Re-indent and add tests for bug #33304.
Rik <rik@octave.org>
parents: 16755
diff changeset
209 %! a.b1 = 2;
1e1d42f0f332 parser.tst: Re-indent and add tests for bug #33304.
Rik <rik@octave.org>
parents: 16755
diff changeset
210 %! assert (a.(strcat('b','1'))++, 2);
1e1d42f0f332 parser.tst: Re-indent and add tests for bug #33304.
Rik <rik@octave.org>
parents: 16755
diff changeset
211 %! assert (a.b1, 3);
1e1d42f0f332 parser.tst: Re-indent and add tests for bug #33304.
Rik <rik@octave.org>
parents: 16755
diff changeset
212 %! 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
213 %! 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
214 %! b = 1:5;
1e1d42f0f332 parser.tst: Re-indent and add tests for bug #33304.
Rik <rik@octave.org>
parents: 16755
diff changeset
215 %! 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
216 %! 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
217 ## 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
218 ## 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
219 ## 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
220 %!test
1e1d42f0f332 parser.tst: Re-indent and add tests for bug #33304.
Rik <rik@octave.org>
parents: 16755
diff changeset
221 %! assert (2^3**2, 64);
1e1d42f0f332 parser.tst: Re-indent and add tests for bug #33304.
Rik <rik@octave.org>
parents: 16755
diff changeset
222 %! 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
223 %! 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
224 %! assert (3*4i'.', 0 - 12i);
1e1d42f0f332 parser.tst: Re-indent and add tests for bug #33304.
Rik <rik@octave.org>
parents: 16755
diff changeset
225 %! assert (3*4i.'.', 0 + 12i);
17420
577a19afdaf5 maint: Backed out changeset f81401b6b1f7.
Rik <rik@octave.org>
parents: 17419
diff changeset
226 %! assert (2^-4^3, (1/16)^3);
577a19afdaf5 maint: Backed out changeset f81401b6b1f7.
Rik <rik@octave.org>
parents: 17419
diff changeset
227 %! assert (2^+4^3, 16^3);
577a19afdaf5 maint: Backed out changeset f81401b6b1f7.
Rik <rik@octave.org>
parents: 17419
diff changeset
228 %! 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
229
12627
002948ae5bc0 fix precedence level of transpose operators (bug #32533)
John W. Eaton <jwe@octave.org>
parents: 12518
diff changeset
230 ## 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
231 %!test
17313
1e1d42f0f332 parser.tst: Re-indent and add tests for bug #33304.
Rik <rik@octave.org>
parents: 16755
diff changeset
232 %! assert (+-+1, -1);
1e1d42f0f332 parser.tst: Re-indent and add tests for bug #33304.
Rik <rik@octave.org>
parents: 16755
diff changeset
233 %! a = -1;
1e1d42f0f332 parser.tst: Re-indent and add tests for bug #33304.
Rik <rik@octave.org>
parents: 16755
diff changeset
234 %! assert (!++a, true);
1e1d42f0f332 parser.tst: Re-indent and add tests for bug #33304.
Rik <rik@octave.org>
parents: 16755
diff changeset
235 %! assert (a, 0);
1e1d42f0f332 parser.tst: Re-indent and add tests for bug #33304.
Rik <rik@octave.org>
parents: 16755
diff changeset
236 %! assert (-~a, -1);
1e1d42f0f332 parser.tst: Re-indent and add tests for bug #33304.
Rik <rik@octave.org>
parents: 16755
diff changeset
237 %! assert (!~--a, true);
1e1d42f0f332 parser.tst: Re-indent and add tests for bug #33304.
Rik <rik@octave.org>
parents: 16755
diff changeset
238 %! assert (a, -1);
12627
002948ae5bc0 fix precedence level of transpose operators (bug #32533)
John W. Eaton <jwe@octave.org>
parents: 12518
diff changeset
239 ## 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
240 %!test
17313
1e1d42f0f332 parser.tst: Re-indent and add tests for bug #33304.
Rik <rik@octave.org>
parents: 16755
diff changeset
241 %! 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
242 %! 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
243 %! 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
244 %! 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
245 ## 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
246 %!test
17313
1e1d42f0f332 parser.tst: Re-indent and add tests for bug #33304.
Rik <rik@octave.org>
parents: 16755
diff changeset
247 %! 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
248 ## Level 7 (colon)
17313
1e1d42f0f332 parser.tst: Re-indent and add tests for bug #33304.
Rik <rik@octave.org>
parents: 16755
diff changeset
249 ## 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
250 ## with second colon operator.
12627
002948ae5bc0 fix precedence level of transpose operators (bug #32533)
John W. Eaton <jwe@octave.org>
parents: 12518
diff changeset
251 ## Level 6 (relational)
12518
9f926b9f83cc Add operator precedence tests to fixed list of parser tests.
Rik <octave@nomad.inbox5.com>
parents: 11523
diff changeset
252 %!test
17313
1e1d42f0f332 parser.tst: Re-indent and add tests for bug #33304.
Rik <rik@octave.org>
parents: 16755
diff changeset
253 %! 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
254 %! 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
255 %! 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
256 ## 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
257 ## 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
258 ## and operation is associative.
12627
002948ae5bc0 fix precedence level of transpose operators (bug #32533)
John W. Eaton <jwe@octave.org>
parents: 12518
diff changeset
259 ## 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
260 ## 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
261 ## and operation is associative.
12627
002948ae5bc0 fix precedence level of transpose operators (bug #32533)
John W. Eaton <jwe@octave.org>
parents: 12518
diff changeset
262 ## 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
263 %!test
17313
1e1d42f0f332 parser.tst: Re-indent and add tests for bug #33304.
Rik <rik@octave.org>
parents: 16755
diff changeset
264 %! a = 1;
1e1d42f0f332 parser.tst: Re-indent and add tests for bug #33304.
Rik <rik@octave.org>
parents: 16755
diff changeset
265 %! assert (1 && 0 && ++a, false);
1e1d42f0f332 parser.tst: Re-indent and add tests for bug #33304.
Rik <rik@octave.org>
parents: 16755
diff changeset
266 %! assert (a, 1);
12627
002948ae5bc0 fix precedence level of transpose operators (bug #32533)
John W. Eaton <jwe@octave.org>
parents: 12518
diff changeset
267 ## Level 2 (logical or)
002948ae5bc0 fix precedence level of transpose operators (bug #32533)
John W. Eaton <jwe@octave.org>
parents: 12518
diff changeset
268 %!test
17313
1e1d42f0f332 parser.tst: Re-indent and add tests for bug #33304.
Rik <rik@octave.org>
parents: 16755
diff changeset
269 %! a = 1;
1e1d42f0f332 parser.tst: Re-indent and add tests for bug #33304.
Rik <rik@octave.org>
parents: 16755
diff changeset
270 %! assert (0 || 1 || ++a, true);
1e1d42f0f332 parser.tst: Re-indent and add tests for bug #33304.
Rik <rik@octave.org>
parents: 16755
diff changeset
271 %! assert (a, 1);
12627
002948ae5bc0 fix precedence level of transpose operators (bug #32533)
John W. Eaton <jwe@octave.org>
parents: 12518
diff changeset
272 ## Level 1 (assignment)
12518
9f926b9f83cc Add operator precedence tests to fixed list of parser tests.
Rik <octave@nomad.inbox5.com>
parents: 11523
diff changeset
273 %!test
9f926b9f83cc Add operator precedence tests to fixed list of parser tests.
Rik <octave@nomad.inbox5.com>
parents: 11523
diff changeset
274 %! 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
275 %! 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
276 %! 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
277
20623
e34692daf663 Extend parser to accept '_' in numbers.
Rik <rik@octave.org>
parents: 19731
diff changeset
278 ## Test extended number format which allows '_' as NOP character
e34692daf663 Extend parser to accept '_' in numbers.
Rik <rik@octave.org>
parents: 19731
diff changeset
279 %!assert (123_456, 123456)
e34692daf663 Extend parser to accept '_' in numbers.
Rik <rik@octave.org>
parents: 19731
diff changeset
280 %!assert (.123_456, .123456)
e34692daf663 Extend parser to accept '_' in numbers.
Rik <rik@octave.org>
parents: 19731
diff changeset
281 %!assert (123_456.123_456, 123456.123456)
e34692daf663 Extend parser to accept '_' in numbers.
Rik <rik@octave.org>
parents: 19731
diff changeset
282 %!assert (0xAB_CD, 43981)
e34692daf663 Extend parser to accept '_' in numbers.
Rik <rik@octave.org>
parents: 19731
diff changeset
283 %!assert (2e0_1, 20);
e34692daf663 Extend parser to accept '_' in numbers.
Rik <rik@octave.org>
parents: 19731
diff changeset
284
20624
7c0e10f035bd Extend parser to accept binary constants that begin with '0b' or '0B'.
Rik <rik@octave.org>
parents: 20623
diff changeset
285 ## Test binary constants
7c0e10f035bd Extend parser to accept binary constants that begin with '0b' or '0B'.
Rik <rik@octave.org>
parents: 20623
diff changeset
286 %!assert (0b101, 5)
7c0e10f035bd Extend parser to accept binary constants that begin with '0b' or '0B'.
Rik <rik@octave.org>
parents: 20623
diff changeset
287 %!assert (0B1100_0001, 0xC1)
7c0e10f035bd Extend parser to accept binary constants that begin with '0b' or '0B'.
Rik <rik@octave.org>
parents: 20623
diff changeset
288 %!assert (class (0b1), "double")
7c0e10f035bd Extend parser to accept binary constants that begin with '0b' or '0B'.
Rik <rik@octave.org>
parents: 20623
diff changeset
289
14131
c3309e1ec50d test: Use Octave coding and spacing conventions for fixed test scripts
Rik <octave@nomad.inbox5.com>
parents: 13237
diff changeset
290 ## 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
291
13237
1bfca2bbea8b fix parsing of anonymous functions inside cell array lists.
John W. Eaton <jwe@octave.org>
parents: 12689
diff changeset
292 %!test
1bfca2bbea8b fix parsing of anonymous functions inside cell array lists.
John W. Eaton <jwe@octave.org>
parents: 12689
diff changeset
293 %! 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
294 %! 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
295
1bfca2bbea8b fix parsing of anonymous functions inside cell array lists.
John W. Eaton <jwe@octave.org>
parents: 12689
diff changeset
296 %!test
1bfca2bbea8b fix parsing of anonymous functions inside cell array lists.
John W. Eaton <jwe@octave.org>
parents: 12689
diff changeset
297 %! 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
298 %! 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
299
16755
787168f5f858 tag symbols in indexed assignments as variables (bug #39240)
John W. Eaton <jwe@octave.org>
parents: 16030
diff changeset
300 ## 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
301 ## 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
302 ## intended.
787168f5f858 tag symbols in indexed assignments as variables (bug #39240)
John W. Eaton <jwe@octave.org>
parents: 16030
diff changeset
303 %!test
787168f5f858 tag symbols in indexed assignments as variables (bug #39240)
John W. Eaton <jwe@octave.org>
parents: 16030
diff changeset
304 %! 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
305 %! assert (xyz, 1);
17624
b92242ad316f parser.tst: Remove comments about bug #33304 which has been fixed.
Rik <rik@octave.org>
parents: 17622
diff changeset
306
18245
1f072ae35ede fix parsing of single quote after continuation and comment (bug #41048)
John W. Eaton <jwe@octave.org>
parents: 17744
diff changeset
307 %!test
19704
e5facc6eec13 Silence warning messages in %!test code.
Rik <rik@octave.org>
parents: 19485
diff changeset
308 %! warning ("off", "Octave:num-to-str", "local");
18245
1f072ae35ede fix parsing of single quote after continuation and comment (bug #41048)
John W. Eaton <jwe@octave.org>
parents: 17744
diff changeset
309 %! 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
310 %! 'b'];
1f072ae35ede fix parsing of single quote after continuation and comment (bug #41048)
John W. Eaton <jwe@octave.org>
parents: 17744
diff changeset
311 %! assert (a, 'ab');
18492
e4c319ed2414 Fix regression, allow space-separated cell array of function handles (bug #41569)
Mike Miller <mtmiller@ieee.org>
parents: 18245
diff changeset
312
e4c319ed2414 Fix regression, allow space-separated cell array of function handles (bug #41569)
Mike Miller <mtmiller@ieee.org>
parents: 18245
diff changeset
313 ## 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: 18245
diff changeset
314 ## correctly with or without commas.
e4c319ed2414 Fix regression, allow space-separated cell array of function handles (bug #41569)
Mike Miller <mtmiller@ieee.org>
parents: 18245
diff changeset
315 %!test
e4c319ed2414 Fix regression, allow space-separated cell array of function handles (bug #41569)
Mike Miller <mtmiller@ieee.org>
parents: 18245
diff changeset
316 %! a = {1, @sin, 2, @cos};
e4c319ed2414 Fix regression, allow space-separated cell array of function handles (bug #41569)
Mike Miller <mtmiller@ieee.org>
parents: 18245
diff changeset
317 %! b = {1 @sin 2 @cos};
e4c319ed2414 Fix regression, allow space-separated cell array of function handles (bug #41569)
Mike Miller <mtmiller@ieee.org>
parents: 18245
diff changeset
318 %! assert (a, b)