annotate test/if.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 1af8d21608b7
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: 5590
diff changeset
2 ##
93c65f2a5668 [project @ 2007-10-12 06:40:56 by jwe]
jwe
parents: 5590
diff changeset
3 ## This file is part of Octave.
93c65f2a5668 [project @ 2007-10-12 06:40:56 by jwe]
jwe
parents: 5590
diff changeset
4 ##
93c65f2a5668 [project @ 2007-10-12 06:40:56 by jwe]
jwe
parents: 5590
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: 5590
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: 5590
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: 5590
diff changeset
8 ## your option) any later version.
93c65f2a5668 [project @ 2007-10-12 06:40:56 by jwe]
jwe
parents: 5590
diff changeset
9 ##
93c65f2a5668 [project @ 2007-10-12 06:40:56 by jwe]
jwe
parents: 5590
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: 5590
diff changeset
11 ## WITHOUT ANY WARRANTY; without even the implied warranty of
93c65f2a5668 [project @ 2007-10-12 06:40:56 by jwe]
jwe
parents: 5590
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: 5590
diff changeset
13 ## General Public License for more details.
93c65f2a5668 [project @ 2007-10-12 06:40:56 by jwe]
jwe
parents: 5590
diff changeset
14 ##
93c65f2a5668 [project @ 2007-10-12 06:40:56 by jwe]
jwe
parents: 5590
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: 5590
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: 5590
diff changeset
17 ## <http://www.gnu.org/licenses/>.
93c65f2a5668 [project @ 2007-10-12 06:40:56 by jwe]
jwe
parents: 5590
diff changeset
18
5590
1ad66ea35fe5 [project @ 2006-01-06 00:24:05 by jwe]
jwe
parents:
diff changeset
19 %% test/octave.test/if/if-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 %! i = 0;
1ad66ea35fe5 [project @ 2006-01-06 00:24:05 by jwe]
jwe
parents:
diff changeset
22 %! if (i == 0)
14131
c3309e1ec50d test: Use Octave coding and spacing conventions for fixed test scripts
Rik <octave@nomad.inbox5.com>
parents: 11523
diff changeset
23 %! i++;
16019
5b2126a8c84f install tests and functions to run them
John W. Eaton <jwe@octave.org>
parents: 14138
diff changeset
24 %! __printf_assert__ ("%d\n", i);
5590
1ad66ea35fe5 [project @ 2006-01-06 00:24:05 by jwe]
jwe
parents:
diff changeset
25 %! endif
16019
5b2126a8c84f install tests and functions to run them
John W. Eaton <jwe@octave.org>
parents: 14138
diff changeset
26 %! assert (__prog_output_assert__ ("1"));
5590
1ad66ea35fe5 [project @ 2006-01-06 00:24:05 by jwe]
jwe
parents:
diff changeset
27
1ad66ea35fe5 [project @ 2006-01-06 00:24:05 by jwe]
jwe
parents:
diff changeset
28 %% test/octave.test/if/if-2.m
1ad66ea35fe5 [project @ 2006-01-06 00:24:05 by jwe]
jwe
parents:
diff changeset
29 %!test
1ad66ea35fe5 [project @ 2006-01-06 00:24:05 by jwe]
jwe
parents:
diff changeset
30 %! if (eye (2))
16019
5b2126a8c84f install tests and functions to run them
John W. Eaton <jwe@octave.org>
parents: 14138
diff changeset
31 %! __printf_assert__ ("fail\n");
5590
1ad66ea35fe5 [project @ 2006-01-06 00:24:05 by jwe]
jwe
parents:
diff changeset
32 %! else
16019
5b2126a8c84f install tests and functions to run them
John W. Eaton <jwe@octave.org>
parents: 14138
diff changeset
33 %! __printf_assert__ ("pass\n");
5590
1ad66ea35fe5 [project @ 2006-01-06 00:24:05 by jwe]
jwe
parents:
diff changeset
34 %! end
16019
5b2126a8c84f install tests and functions to run them
John W. Eaton <jwe@octave.org>
parents: 14138
diff changeset
35 %! assert (__prog_output_assert__ ("pass"));
5590
1ad66ea35fe5 [project @ 2006-01-06 00:24:05 by jwe]
jwe
parents:
diff changeset
36
1ad66ea35fe5 [project @ 2006-01-06 00:24:05 by jwe]
jwe
parents:
diff changeset
37 %% test/octave.test/if/if-3.m
1ad66ea35fe5 [project @ 2006-01-06 00:24:05 by jwe]
jwe
parents:
diff changeset
38 %!test
1ad66ea35fe5 [project @ 2006-01-06 00:24:05 by jwe]
jwe
parents:
diff changeset
39 %! x = 2;
1ad66ea35fe5 [project @ 2006-01-06 00:24:05 by jwe]
jwe
parents:
diff changeset
40 %! if (eye (2))
16019
5b2126a8c84f install tests and functions to run them
John W. Eaton <jwe@octave.org>
parents: 14138
diff changeset
41 %! __printf_assert__ ("fail\n");
5590
1ad66ea35fe5 [project @ 2006-01-06 00:24:05 by jwe]
jwe
parents:
diff changeset
42 %! elseif (x)
16019
5b2126a8c84f install tests and functions to run them
John W. Eaton <jwe@octave.org>
parents: 14138
diff changeset
43 %! __printf_assert__ ("pass\n");
5590
1ad66ea35fe5 [project @ 2006-01-06 00:24:05 by jwe]
jwe
parents:
diff changeset
44 %! endif
16019
5b2126a8c84f install tests and functions to run them
John W. Eaton <jwe@octave.org>
parents: 14138
diff changeset
45 %! assert (__prog_output_assert__ ("pass"));
5590
1ad66ea35fe5 [project @ 2006-01-06 00:24:05 by jwe]
jwe
parents:
diff changeset
46
1ad66ea35fe5 [project @ 2006-01-06 00:24:05 by jwe]
jwe
parents:
diff changeset
47 %% test/octave.test/if/if-4.m
1ad66ea35fe5 [project @ 2006-01-06 00:24:05 by jwe]
jwe
parents:
diff changeset
48 %!test
1ad66ea35fe5 [project @ 2006-01-06 00:24:05 by jwe]
jwe
parents:
diff changeset
49 %! x = 0;
1ad66ea35fe5 [project @ 2006-01-06 00:24:05 by jwe]
jwe
parents:
diff changeset
50 %! y = -2;
1ad66ea35fe5 [project @ 2006-01-06 00:24:05 by jwe]
jwe
parents:
diff changeset
51 %! if (eye (2))
16019
5b2126a8c84f install tests and functions to run them
John W. Eaton <jwe@octave.org>
parents: 14138
diff changeset
52 %! __printf_assert__ ("fail\n");
5590
1ad66ea35fe5 [project @ 2006-01-06 00:24:05 by jwe]
jwe
parents:
diff changeset
53 %! elseif (x)
16019
5b2126a8c84f install tests and functions to run them
John W. Eaton <jwe@octave.org>
parents: 14138
diff changeset
54 %! __printf_assert__ ("fail\n");
5590
1ad66ea35fe5 [project @ 2006-01-06 00:24:05 by jwe]
jwe
parents:
diff changeset
55 %! elseif (y)
16019
5b2126a8c84f install tests and functions to run them
John W. Eaton <jwe@octave.org>
parents: 14138
diff changeset
56 %! __printf_assert__ ("pass\n");
5590
1ad66ea35fe5 [project @ 2006-01-06 00:24:05 by jwe]
jwe
parents:
diff changeset
57 %! end
16019
5b2126a8c84f install tests and functions to run them
John W. Eaton <jwe@octave.org>
parents: 14138
diff changeset
58 %! assert (__prog_output_assert__ ("pass"));
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/if/if-5.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 %! x = 0;
1ad66ea35fe5 [project @ 2006-01-06 00:24:05 by jwe]
jwe
parents:
diff changeset
63 %! y = -2;
1ad66ea35fe5 [project @ 2006-01-06 00:24:05 by jwe]
jwe
parents:
diff changeset
64 %! if (eye (2))
16019
5b2126a8c84f install tests and functions to run them
John W. Eaton <jwe@octave.org>
parents: 14138
diff changeset
65 %! __printf_assert__ ("fail\n");
5590
1ad66ea35fe5 [project @ 2006-01-06 00:24:05 by jwe]
jwe
parents:
diff changeset
66 %! elseif (x)
16019
5b2126a8c84f install tests and functions to run them
John W. Eaton <jwe@octave.org>
parents: 14138
diff changeset
67 %! __printf_assert__ ("fail\n");
5590
1ad66ea35fe5 [project @ 2006-01-06 00:24:05 by jwe]
jwe
parents:
diff changeset
68 %! elseif (x)
16019
5b2126a8c84f install tests and functions to run them
John W. Eaton <jwe@octave.org>
parents: 14138
diff changeset
69 %! __printf_assert__ ("fail\n");
5590
1ad66ea35fe5 [project @ 2006-01-06 00:24:05 by jwe]
jwe
parents:
diff changeset
70 %! else
16019
5b2126a8c84f install tests and functions to run them
John W. Eaton <jwe@octave.org>
parents: 14138
diff changeset
71 %! __printf_assert__ ("pass\n");
5590
1ad66ea35fe5 [project @ 2006-01-06 00:24:05 by jwe]
jwe
parents:
diff changeset
72 %! endif
16019
5b2126a8c84f install tests and functions to run them
John W. Eaton <jwe@octave.org>
parents: 14138
diff changeset
73 %! assert (__prog_output_assert__ ("pass"));
5590
1ad66ea35fe5 [project @ 2006-01-06 00:24:05 by jwe]
jwe
parents:
diff changeset
74
1ad66ea35fe5 [project @ 2006-01-06 00:24:05 by jwe]
jwe
parents:
diff changeset
75 %% test/octave.test/if/if-6.m
1ad66ea35fe5 [project @ 2006-01-06 00:24:05 by jwe]
jwe
parents:
diff changeset
76 %!test
1ad66ea35fe5 [project @ 2006-01-06 00:24:05 by jwe]
jwe
parents:
diff changeset
77 %! x = 0;
1ad66ea35fe5 [project @ 2006-01-06 00:24:05 by jwe]
jwe
parents:
diff changeset
78 %! y = -2;
1ad66ea35fe5 [project @ 2006-01-06 00:24:05 by jwe]
jwe
parents:
diff changeset
79 %! if (y)
16019
5b2126a8c84f install tests and functions to run them
John W. Eaton <jwe@octave.org>
parents: 14138
diff changeset
80 %! __printf_assert__ ("pass\n");
5590
1ad66ea35fe5 [project @ 2006-01-06 00:24:05 by jwe]
jwe
parents:
diff changeset
81 %! elseif (x)
16019
5b2126a8c84f install tests and functions to run them
John W. Eaton <jwe@octave.org>
parents: 14138
diff changeset
82 %! __printf_assert__ ("fail\n");
5590
1ad66ea35fe5 [project @ 2006-01-06 00:24:05 by jwe]
jwe
parents:
diff changeset
83 %! elseif (x)
16019
5b2126a8c84f install tests and functions to run them
John W. Eaton <jwe@octave.org>
parents: 14138
diff changeset
84 %! __printf_assert__ ("fail\n");
5590
1ad66ea35fe5 [project @ 2006-01-06 00:24:05 by jwe]
jwe
parents:
diff changeset
85 %! end
16019
5b2126a8c84f install tests and functions to run them
John W. Eaton <jwe@octave.org>
parents: 14138
diff changeset
86 %! assert (__prog_output_assert__ ("pass"));
5590
1ad66ea35fe5 [project @ 2006-01-06 00:24:05 by jwe]
jwe
parents:
diff changeset
87
16681
d3619d4d267c recognize character string at beginning of statement (bug #38926, #38958)
John W. Eaton <jwe@octave.org>
parents: 16030
diff changeset
88 %% 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: 16030
diff changeset
89 %% beginning of an if condition
d3619d4d267c recognize character string at beginning of statement (bug #38926, #38958)
John W. Eaton <jwe@octave.org>
parents: 16030
diff changeset
90 %!test
d3619d4d267c recognize character string at beginning of statement (bug #38926, #38958)
John W. Eaton <jwe@octave.org>
parents: 16030
diff changeset
91 %! if (1)
d3619d4d267c recognize character string at beginning of statement (bug #38926, #38958)
John W. Eaton <jwe@octave.org>
parents: 16030
diff changeset
92 %! 'foo';
d3619d4d267c recognize character string at beginning of statement (bug #38926, #38958)
John W. Eaton <jwe@octave.org>
parents: 16030
diff changeset
93 %! x = 13;
d3619d4d267c recognize character string at beginning of statement (bug #38926, #38958)
John W. Eaton <jwe@octave.org>
parents: 16030
diff changeset
94 %! endif
d3619d4d267c recognize character string at beginning of statement (bug #38926, #38958)
John W. Eaton <jwe@octave.org>
parents: 16030
diff changeset
95 %! assert (x, 13);
d3619d4d267c recognize character string at beginning of statement (bug #38926, #38958)
John W. Eaton <jwe@octave.org>
parents: 16030
diff changeset
96
d3619d4d267c recognize character string at beginning of statement (bug #38926, #38958)
John W. Eaton <jwe@octave.org>
parents: 16030
diff changeset
97 %% 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: 16030
diff changeset
98 %% beginning of an if condition
d3619d4d267c recognize character string at beginning of statement (bug #38926, #38958)
John W. Eaton <jwe@octave.org>
parents: 16030
diff changeset
99 %!test
d3619d4d267c recognize character string at beginning of statement (bug #38926, #38958)
John W. Eaton <jwe@octave.org>
parents: 16030
diff changeset
100 %! if (0)
d3619d4d267c recognize character string at beginning of statement (bug #38926, #38958)
John W. Eaton <jwe@octave.org>
parents: 16030
diff changeset
101 %! x = 42;
d3619d4d267c recognize character string at beginning of statement (bug #38926, #38958)
John W. Eaton <jwe@octave.org>
parents: 16030
diff changeset
102 %! elseif (1)
d3619d4d267c recognize character string at beginning of statement (bug #38926, #38958)
John W. Eaton <jwe@octave.org>
parents: 16030
diff changeset
103 %! 'foo';
d3619d4d267c recognize character string at beginning of statement (bug #38926, #38958)
John W. Eaton <jwe@octave.org>
parents: 16030
diff changeset
104 %! x = 13;
d3619d4d267c recognize character string at beginning of statement (bug #38926, #38958)
John W. Eaton <jwe@octave.org>
parents: 16030
diff changeset
105 %! endif
d3619d4d267c recognize character string at beginning of statement (bug #38926, #38958)
John W. Eaton <jwe@octave.org>
parents: 16030
diff changeset
106 %! assert (x, 13);