File: plcontrolflow.sql

package info (click to toggle)
hsqldb1.8.0 1.8.0.10%2Bdfsg-10
  • links: PTS
  • area: main
  • in suites: buster
  • size: 13,432 kB
  • sloc: java: 75,802; xml: 11,392; sql: 1,556; sh: 847; makefile: 57
file content (215 lines) | stat: -rw-r--r-- 4,652 bytes parent folder | download | duplicates (10)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
/*
 * $Id: plcontrolflow.sql,v 1.1 2007/08/09 03:28:37 unsaved Exp $
 *
 * Tests PL control flow.  if, foreach statements, etc.
 */

*if (*UNSET)
    \q Failed boolean test of an unset variable
*end if
*if (astring)
   * y = something
*end if
*if (*X)
    \q Failed boolean test of a simple string constant
*end if
*if (0)
    \q Failed boolean test of zero constant
*end if
*if (! x)
/* Note that there must be white space to separate the two tokens above. */
    \q Failed boolean test of a plain constant
*end if


/* Nested if tests */
* if (1)
    * L1 = true
    * if (2)
        * L2 = true
    * end if
    * L11 = true
* end if
*if (! *L1)
    \q Pre-nest failure
*end if
*if (! *L2)
    \q Inside-nest failure
*end if
*if (! *L11)
    \q Post-nest failure
*end if
* L1 =
* L2 =
* L11 =
* if (1)
    * L1 = true
    * if (2)
        * L2 = true
    * end if
    * L11 = true
* end if
*if (! *L1)
    \q Pre-nest failure
*end if
*if (! *L2)
    \q Inside-nest failure
*end if
*if (! *L11)
    \q Post-nest failure
*end if
/* Test deep nesting of IFs, including negatives. */
* if (1)
    * L1 = true
    * if (0)
        * N2 = true
    * end if
    * if (2)
        * L2 = true
        * if (3)
            * L3 = true
            * if (4)
                * L4 = true
                * if (0)
                    * N5 = true
                * end if
                * if (5)
                    * L5 = true
                    * if (0)
                        * N6 = true
                    * end if
                    * if (6)
                        * L6 = true
                        * if (0)
                            * N7 = true
                        * end if
                    * end if
                    * L51 = true
                * end if
            * end if
            * if (0)
                * N4 = true
            * end if
            * L31 = true
        * end if
        * if (0)
            * N3 = true
        * end if
    * end if
    * L11 = true
* end if
*if (! *L1)
    \q Pre-deep-nest failure 1
*end if
*if (! *L2)
    \q Inside-deep-nest failure 2
*end if
*if (! *L11)
    \q Post-deep-nest failure 11
*end if
*if (! *L3)
    \q Pre-deep-nest failure 3
*end if
*if (! *L4)
    \q Inside-deep-nest failure 4
*end if
*if (! *L31)
    \q Post-deep-nest failure 31
*end if
*if (! *L5)
    \q Pre-deep-nest failure 5
*end if
*if (! *L6)
    \q Inside-deep-nest failure 6
*end if
*if (! *L51)
    \q Post-deep-nest failure 51
*end if
*if (*N2)
    \q Negative deep-nest failure 2
*end if
*if (*N3)
    \q Negative deep-nest failure 3
*end if
*if (*N4)
    \q Negative deep-nest failure 4
*end if
*if (*N5)
    \q Negative deep-nest failure 5
*end if
*if (*N6)
    \q Negative deep-nest failure 6
*end if
*if (*N7)
    \q Negative deep-nest failure 7
*end if

/* Nested foreach tests */
/* Initialize Results  to I */
* R = I
*foreach L1 (A B C)
  *foreach L2 (1 2 3 4)
      *foreach L3 (a b)
	      * R = *{R}:*{L1}*{L2}*{L3}
	  *end foreach
  *end foreach
*end foreach
*if (*R != I:A1a:A1b:A2a:A2b:A3a:A3b:A4a:A4b:B1a:B1b:B2a:B2b:B3a:B3b:B4a:B4b:C1a:C1b:C2a:C2b:C3a:C3b:C4a:C4b)
    \q nested foreach result unexpected: *{R}
*end if
/* Initialize Results  to I */
* R = I
*foreach L1 (A B C)
  *if (*L1 != A)
	  *foreach L2 (1 2 3 4)
		  *if (*L2 != 3)
			  *foreach L3 (a b c)
				  *if (*L3 != b)
					  * R = *{R}:*{L1}*{L2}*{L3}
				  *end if
			  *end foreach
		  *end if
	  *end foreach
  *end if
*end foreach
*if (*R != I:B1a:B1c:B2a:B2c:B4a:B4c:C1a:C1c:C2a:C2c:C4a:C4c)
    \q nested conditional foreach result unexpected: *{R}
*end if

/* Test break and continue */
/* Initialize Results  to I */
* R = I
*foreach L1 (A B C)
  *foreach L2 (1 2 3 4)
      *foreach L3 (a b)
          *if (*L3 == a)
            *continue
          *end if
	      * R = *{R}:*{L1}*{L2}*{L3}
	  *end foreach
      *if (*L2 == 3)
        *break foreach
      *end if
  *end foreach
*end foreach
*if (*R != I:A1b:A2b:A3b:B1b:B2b:B3b:C1b:C2b:C3b)
    \q nested foreach result unexpected: *{R}
*end if

/* If something doesn't work right, could get into infinite loop below. */
* accum=L
*while (1)
   * accum = *{accum}P
   * subcum = M
   *while (*subcum < MQQ)
       * subcum = *{subcum}Q
   *end while
   * accum = *{accum}*{subcum}
   *if (*accum == LPMQQPMQQ)
       *break while
    *end if
*end while

*if (*accum != LPMQQPMQQ)
    \p Wrong value accumulated by nested while loops (*{accum})
*end if