annotate test/for.tst @ 16681:d3619d4d267c

recognize character string at beginning of statement (bug #38926, #38958) * lex.ll ("'"): Always begin a character string if at the beginning of a statement. * oct-parse.in.yy (stmt_begin): New non-terminal. (anon_fcn_handle, if_cmd_list1, elseif_clause, switch_case, loop_command): Use it. * pt-fcn-handle.cc, for.tst, if.tst, switch.tst, while.tst: New tests.
author John W. Eaton <jwe@octave.org>
date Sat, 18 May 2013 16:21:32 -0400
parents b1283d4c06c2
children 57fad64de019
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
14138
72c96de7a403 maint: update copyright notices for 2012
John W. Eaton <jwe@octave.org>
parents: 14131
diff changeset
1 ## Copyright (C) 2006-2012 John W. Eaton
7016
93c65f2a5668 [project @ 2007-10-12 06:40:56 by jwe]
jwe
parents: 6602
diff changeset
2 ##
93c65f2a5668 [project @ 2007-10-12 06:40:56 by jwe]
jwe
parents: 6602
diff changeset
3 ## This file is part of Octave.
93c65f2a5668 [project @ 2007-10-12 06:40:56 by jwe]
jwe
parents: 6602
diff changeset
4 ##
93c65f2a5668 [project @ 2007-10-12 06:40:56 by jwe]
jwe
parents: 6602
diff changeset
5 ## Octave is free software; you can redistribute it and/or modify it
93c65f2a5668 [project @ 2007-10-12 06:40:56 by jwe]
jwe
parents: 6602
diff changeset
6 ## under the terms of the GNU General Public License as published by
93c65f2a5668 [project @ 2007-10-12 06:40:56 by jwe]
jwe
parents: 6602
diff changeset
7 ## the Free Software Foundation; either version 3 of the License, or (at
93c65f2a5668 [project @ 2007-10-12 06:40:56 by jwe]
jwe
parents: 6602
diff changeset
8 ## your option) any later version.
93c65f2a5668 [project @ 2007-10-12 06:40:56 by jwe]
jwe
parents: 6602
diff changeset
9 ##
93c65f2a5668 [project @ 2007-10-12 06:40:56 by jwe]
jwe
parents: 6602
diff changeset
10 ## Octave is distributed in the hope that it will be useful, but
93c65f2a5668 [project @ 2007-10-12 06:40:56 by jwe]
jwe
parents: 6602
diff changeset
11 ## WITHOUT ANY WARRANTY; without even the implied warranty of
93c65f2a5668 [project @ 2007-10-12 06:40:56 by jwe]
jwe
parents: 6602
diff changeset
12 ## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
93c65f2a5668 [project @ 2007-10-12 06:40:56 by jwe]
jwe
parents: 6602
diff changeset
13 ## General Public License for more details.
93c65f2a5668 [project @ 2007-10-12 06:40:56 by jwe]
jwe
parents: 6602
diff changeset
14 ##
93c65f2a5668 [project @ 2007-10-12 06:40:56 by jwe]
jwe
parents: 6602
diff changeset
15 ## You should have received a copy of the GNU General Public License
93c65f2a5668 [project @ 2007-10-12 06:40:56 by jwe]
jwe
parents: 6602
diff changeset
16 ## along with Octave; see the file COPYING. If not, see
93c65f2a5668 [project @ 2007-10-12 06:40:56 by jwe]
jwe
parents: 6602
diff changeset
17 ## <http://www.gnu.org/licenses/>.
93c65f2a5668 [project @ 2007-10-12 06:40:56 by jwe]
jwe
parents: 6602
diff changeset
18
5590
1ad66ea35fe5 [project @ 2006-01-06 00:24:05 by jwe]
jwe
parents:
diff changeset
19 %% test/octave.test/for/for-1.m
1ad66ea35fe5 [project @ 2006-01-06 00:24:05 by jwe]
jwe
parents:
diff changeset
20 %!test
1ad66ea35fe5 [project @ 2006-01-06 00:24:05 by jwe]
jwe
parents:
diff changeset
21 %! for i = 1
16019
5b2126a8c84f install tests and functions to run them
John W. Eaton <jwe@octave.org>
parents: 14138
diff changeset
22 %! __printf_assert__ ("%d", i);
5590
1ad66ea35fe5 [project @ 2006-01-06 00:24:05 by jwe]
jwe
parents:
diff changeset
23 %! end
16019
5b2126a8c84f install tests and functions to run them
John W. Eaton <jwe@octave.org>
parents: 14138
diff changeset
24 %! __printf_assert__ ("\n");
5b2126a8c84f install tests and functions to run them
John W. Eaton <jwe@octave.org>
parents: 14138
diff changeset
25 %! assert (__prog_output_assert__ ("1"));
5590
1ad66ea35fe5 [project @ 2006-01-06 00:24:05 by jwe]
jwe
parents:
diff changeset
26
1ad66ea35fe5 [project @ 2006-01-06 00:24:05 by jwe]
jwe
parents:
diff changeset
27 %% test/octave.test/for/for-2.m
1ad66ea35fe5 [project @ 2006-01-06 00:24:05 by jwe]
jwe
parents:
diff changeset
28 %!test
1ad66ea35fe5 [project @ 2006-01-06 00:24:05 by jwe]
jwe
parents:
diff changeset
29 %! for i = 1:4
16019
5b2126a8c84f install tests and functions to run them
John W. Eaton <jwe@octave.org>
parents: 14138
diff changeset
30 %! __printf_assert__ ("%d", i);
5590
1ad66ea35fe5 [project @ 2006-01-06 00:24:05 by jwe]
jwe
parents:
diff changeset
31 %! endfor
16019
5b2126a8c84f install tests and functions to run them
John W. Eaton <jwe@octave.org>
parents: 14138
diff changeset
32 %! __printf_assert__ ("\n");
5b2126a8c84f install tests and functions to run them
John W. Eaton <jwe@octave.org>
parents: 14138
diff changeset
33 %! assert (__prog_output_assert__ ("1234"));
5590
1ad66ea35fe5 [project @ 2006-01-06 00:24:05 by jwe]
jwe
parents:
diff changeset
34
1ad66ea35fe5 [project @ 2006-01-06 00:24:05 by jwe]
jwe
parents:
diff changeset
35 %% test/octave.test/for/for-3.m
1ad66ea35fe5 [project @ 2006-01-06 00:24:05 by jwe]
jwe
parents:
diff changeset
36 %!test
1ad66ea35fe5 [project @ 2006-01-06 00:24:05 by jwe]
jwe
parents:
diff changeset
37 %! for i = [1,2,3,4]
16019
5b2126a8c84f install tests and functions to run them
John W. Eaton <jwe@octave.org>
parents: 14138
diff changeset
38 %! __printf_assert__ ("%d", i);
5590
1ad66ea35fe5 [project @ 2006-01-06 00:24:05 by jwe]
jwe
parents:
diff changeset
39 %! endfor
16019
5b2126a8c84f install tests and functions to run them
John W. Eaton <jwe@octave.org>
parents: 14138
diff changeset
40 %! __printf_assert__ ("\n");
5b2126a8c84f install tests and functions to run them
John W. Eaton <jwe@octave.org>
parents: 14138
diff changeset
41 %! assert (__prog_output_assert__ ("1234"));
5590
1ad66ea35fe5 [project @ 2006-01-06 00:24:05 by jwe]
jwe
parents:
diff changeset
42
1ad66ea35fe5 [project @ 2006-01-06 00:24:05 by jwe]
jwe
parents:
diff changeset
43 %% test/octave.test/for/for-4.m
1ad66ea35fe5 [project @ 2006-01-06 00:24:05 by jwe]
jwe
parents:
diff changeset
44 %!test
1ad66ea35fe5 [project @ 2006-01-06 00:24:05 by jwe]
jwe
parents:
diff changeset
45 %! for i = [1,2;3,4]
16019
5b2126a8c84f install tests and functions to run them
John W. Eaton <jwe@octave.org>
parents: 14138
diff changeset
46 %! __printf_assert__ ("%d", i(1,1));
5b2126a8c84f install tests and functions to run them
John W. Eaton <jwe@octave.org>
parents: 14138
diff changeset
47 %! __printf_assert__ ("%d", i(2,1));
5590
1ad66ea35fe5 [project @ 2006-01-06 00:24:05 by jwe]
jwe
parents:
diff changeset
48 %! endfor
16019
5b2126a8c84f install tests and functions to run them
John W. Eaton <jwe@octave.org>
parents: 14138
diff changeset
49 %! __printf_assert__ ("\n");
5b2126a8c84f install tests and functions to run them
John W. Eaton <jwe@octave.org>
parents: 14138
diff changeset
50 %! assert (__prog_output_assert__ ("1324"));
5590
1ad66ea35fe5 [project @ 2006-01-06 00:24:05 by jwe]
jwe
parents:
diff changeset
51
1ad66ea35fe5 [project @ 2006-01-06 00:24:05 by jwe]
jwe
parents:
diff changeset
52 %% test/octave.test/for/for-5.m
1ad66ea35fe5 [project @ 2006-01-06 00:24:05 by jwe]
jwe
parents:
diff changeset
53 %!test
1ad66ea35fe5 [project @ 2006-01-06 00:24:05 by jwe]
jwe
parents:
diff changeset
54 %! for i = I
16019
5b2126a8c84f install tests and functions to run them
John W. Eaton <jwe@octave.org>
parents: 14138
diff changeset
55 %! __printf_assert__ ("%d", imag (i));
5590
1ad66ea35fe5 [project @ 2006-01-06 00:24:05 by jwe]
jwe
parents:
diff changeset
56 %! endfor
16019
5b2126a8c84f install tests and functions to run them
John W. Eaton <jwe@octave.org>
parents: 14138
diff changeset
57 %! __printf_assert__ ("\n");
5b2126a8c84f install tests and functions to run them
John W. Eaton <jwe@octave.org>
parents: 14138
diff changeset
58 %! assert (__prog_output_assert__ ("1"));
5590
1ad66ea35fe5 [project @ 2006-01-06 00:24:05 by jwe]
jwe
parents:
diff changeset
59
1ad66ea35fe5 [project @ 2006-01-06 00:24:05 by jwe]
jwe
parents:
diff changeset
60 %% test/octave.test/for/for-6.m
1ad66ea35fe5 [project @ 2006-01-06 00:24:05 by jwe]
jwe
parents:
diff changeset
61 %!test
1ad66ea35fe5 [project @ 2006-01-06 00:24:05 by jwe]
jwe
parents:
diff changeset
62 %! for i = [1,2,3,4]*I
16019
5b2126a8c84f install tests and functions to run them
John W. Eaton <jwe@octave.org>
parents: 14138
diff changeset
63 %! __printf_assert__ ("%d", imag (i));
5590
1ad66ea35fe5 [project @ 2006-01-06 00:24:05 by jwe]
jwe
parents:
diff changeset
64 %! endfor
16019
5b2126a8c84f install tests and functions to run them
John W. Eaton <jwe@octave.org>
parents: 14138
diff changeset
65 %! __printf_assert__ ("\n");
5b2126a8c84f install tests and functions to run them
John W. Eaton <jwe@octave.org>
parents: 14138
diff changeset
66 %! assert (__prog_output_assert__ ("1234"));
5590
1ad66ea35fe5 [project @ 2006-01-06 00:24:05 by jwe]
jwe
parents:
diff changeset
67
1ad66ea35fe5 [project @ 2006-01-06 00:24:05 by jwe]
jwe
parents:
diff changeset
68 %% test/octave.test/for/for-7.m
1ad66ea35fe5 [project @ 2006-01-06 00:24:05 by jwe]
jwe
parents:
diff changeset
69 %!test
1ad66ea35fe5 [project @ 2006-01-06 00:24:05 by jwe]
jwe
parents:
diff changeset
70 %! for i = [1,2;3,4]*I
16019
5b2126a8c84f install tests and functions to run them
John W. Eaton <jwe@octave.org>
parents: 14138
diff changeset
71 %! __printf_assert__ ("%d", imag (i(1,1)));
5b2126a8c84f install tests and functions to run them
John W. Eaton <jwe@octave.org>
parents: 14138
diff changeset
72 %! __printf_assert__ ("%d", imag (i(2,1)));
5590
1ad66ea35fe5 [project @ 2006-01-06 00:24:05 by jwe]
jwe
parents:
diff changeset
73 %! endfor
16019
5b2126a8c84f install tests and functions to run them
John W. Eaton <jwe@octave.org>
parents: 14138
diff changeset
74 %! __printf_assert__ ("\n");
5b2126a8c84f install tests and functions to run them
John W. Eaton <jwe@octave.org>
parents: 14138
diff changeset
75 %! assert (__prog_output_assert__ ("1324"));
5590
1ad66ea35fe5 [project @ 2006-01-06 00:24:05 by jwe]
jwe
parents:
diff changeset
76
1ad66ea35fe5 [project @ 2006-01-06 00:24:05 by jwe]
jwe
parents:
diff changeset
77 %% test/octave.test/for/for-8.m
1ad66ea35fe5 [project @ 2006-01-06 00:24:05 by jwe]
jwe
parents:
diff changeset
78 %!test
1ad66ea35fe5 [project @ 2006-01-06 00:24:05 by jwe]
jwe
parents:
diff changeset
79 %! for i = [1,2,3,4]
14131
c3309e1ec50d test: Use Octave coding and spacing conventions for fixed test scripts
Rik <octave@nomad.inbox5.com>
parents: 11523
diff changeset
80 %! if (i > 2)
c3309e1ec50d test: Use Octave coding and spacing conventions for fixed test scripts
Rik <octave@nomad.inbox5.com>
parents: 11523
diff changeset
81 %! break;
c3309e1ec50d test: Use Octave coding and spacing conventions for fixed test scripts
Rik <octave@nomad.inbox5.com>
parents: 11523
diff changeset
82 %! endif
16019
5b2126a8c84f install tests and functions to run them
John W. Eaton <jwe@octave.org>
parents: 14138
diff changeset
83 %! __printf_assert__ ("%d", i);
5590
1ad66ea35fe5 [project @ 2006-01-06 00:24:05 by jwe]
jwe
parents:
diff changeset
84 %! endfor
16019
5b2126a8c84f install tests and functions to run them
John W. Eaton <jwe@octave.org>
parents: 14138
diff changeset
85 %! __printf_assert__ ("\n");
5b2126a8c84f install tests and functions to run them
John W. Eaton <jwe@octave.org>
parents: 14138
diff changeset
86 %! assert (__prog_output_assert__ ("12"));
5590
1ad66ea35fe5 [project @ 2006-01-06 00:24:05 by jwe]
jwe
parents:
diff changeset
87
1ad66ea35fe5 [project @ 2006-01-06 00:24:05 by jwe]
jwe
parents:
diff changeset
88 %% test/octave.test/for/for-9.m
1ad66ea35fe5 [project @ 2006-01-06 00:24:05 by jwe]
jwe
parents:
diff changeset
89 %!test
1ad66ea35fe5 [project @ 2006-01-06 00:24:05 by jwe]
jwe
parents:
diff changeset
90 %! for i = [1,2,3,4]
14131
c3309e1ec50d test: Use Octave coding and spacing conventions for fixed test scripts
Rik <octave@nomad.inbox5.com>
parents: 11523
diff changeset
91 %! if (i < 3)
c3309e1ec50d test: Use Octave coding and spacing conventions for fixed test scripts
Rik <octave@nomad.inbox5.com>
parents: 11523
diff changeset
92 %! continue;
c3309e1ec50d test: Use Octave coding and spacing conventions for fixed test scripts
Rik <octave@nomad.inbox5.com>
parents: 11523
diff changeset
93 %! endif
16019
5b2126a8c84f install tests and functions to run them
John W. Eaton <jwe@octave.org>
parents: 14138
diff changeset
94 %! __printf_assert__ ("%d", i);
5590
1ad66ea35fe5 [project @ 2006-01-06 00:24:05 by jwe]
jwe
parents:
diff changeset
95 %! endfor
16019
5b2126a8c84f install tests and functions to run them
John W. Eaton <jwe@octave.org>
parents: 14138
diff changeset
96 %! __printf_assert__ ("\n");
5b2126a8c84f install tests and functions to run them
John W. Eaton <jwe@octave.org>
parents: 14138
diff changeset
97 %! assert (__prog_output_assert__ ("34"));
5590
1ad66ea35fe5 [project @ 2006-01-06 00:24:05 by jwe]
jwe
parents:
diff changeset
98
6587
00fad3bad2a5 [project @ 2007-04-26 20:23:31 by dbateman]
dbateman
parents: 5590
diff changeset
99 %!test
00fad3bad2a5 [project @ 2007-04-26 20:23:31 by dbateman]
dbateman
parents: 5590
diff changeset
100 %! a = [1,3;2,4];
00fad3bad2a5 [project @ 2007-04-26 20:23:31 by dbateman]
dbateman
parents: 5590
diff changeset
101 %! j = 0;
00fad3bad2a5 [project @ 2007-04-26 20:23:31 by dbateman]
dbateman
parents: 5590
diff changeset
102 %! for i = cat (3, a, 4 + a)
00fad3bad2a5 [project @ 2007-04-26 20:23:31 by dbateman]
dbateman
parents: 5590
diff changeset
103 %! assert (i, [1;2] + 2*j++)
00fad3bad2a5 [project @ 2007-04-26 20:23:31 by dbateman]
dbateman
parents: 5590
diff changeset
104 %! endfor
00fad3bad2a5 [project @ 2007-04-26 20:23:31 by dbateman]
dbateman
parents: 5590
diff changeset
105
00fad3bad2a5 [project @ 2007-04-26 20:23:31 by dbateman]
dbateman
parents: 5590
diff changeset
106 %!test
00fad3bad2a5 [project @ 2007-04-26 20:23:31 by dbateman]
dbateman
parents: 5590
diff changeset
107 %! a = {1,3;2,4};
6602
8ebd4f842715 [project @ 2007-04-30 17:12:45 by jwe]
jwe
parents: 6587
diff changeset
108 %! j = 0;
16213
b1283d4c06c2 test: Use Octave coding standards for scripts in test/ directory.
Rik <rik@octave.org>
parents: 16030
diff changeset
109 %! for i = cat (3, a, cellfun (@(x) 4 + x, a, "UniformOutput", 0))
6587
00fad3bad2a5 [project @ 2007-04-26 20:23:31 by dbateman]
dbateman
parents: 5590
diff changeset
110 %! assert (i, {1 + 2*j; 2 + 2*j++})
00fad3bad2a5 [project @ 2007-04-26 20:23:31 by dbateman]
dbateman
parents: 5590
diff changeset
111 %! endfor
16681
d3619d4d267c recognize character string at beginning of statement (bug #38926, #38958)
John W. Eaton <jwe@octave.org>
parents: 16213
diff changeset
112
d3619d4d267c recognize character string at beginning of statement (bug #38926, #38958)
John W. Eaton <jwe@octave.org>
parents: 16213
diff changeset
113 %% test parsing of single-quoted character string appearing at the
d3619d4d267c recognize character string at beginning of statement (bug #38926, #38958)
John W. Eaton <jwe@octave.org>
parents: 16213
diff changeset
114 %% beginning of a for loop
d3619d4d267c recognize character string at beginning of statement (bug #38926, #38958)
John W. Eaton <jwe@octave.org>
parents: 16213
diff changeset
115 %!test
d3619d4d267c recognize character string at beginning of statement (bug #38926, #38958)
John W. Eaton <jwe@octave.org>
parents: 16213
diff changeset
116 %! for i = 1:5
d3619d4d267c recognize character string at beginning of statement (bug #38926, #38958)
John W. Eaton <jwe@octave.org>
parents: 16213
diff changeset
117 %! 'foo';
d3619d4d267c recognize character string at beginning of statement (bug #38926, #38958)
John W. Eaton <jwe@octave.org>
parents: 16213
diff changeset
118 %! endfor
d3619d4d267c recognize character string at beginning of statement (bug #38926, #38958)
John W. Eaton <jwe@octave.org>
parents: 16213
diff changeset
119 %! assert (i, 5);