svn-gvsig-desktop / trunk / org.gvsig.desktop / org.gvsig.desktop.library / org.gvsig.expressionevaluator / org.gvsig.expressionevaluator.lib / org.gvsig.expressionevaluator.lib.impl / src / test / java / org / gvsig / expresionevaluator / impl / TestGrammarCompiler.java @ 47734
History | View | Annotate | Download (18.6 KB)
1 |
package org.gvsig.expresionevaluator.impl; |
---|---|
2 |
|
3 |
import java.util.Objects; |
4 |
import junit.framework.TestCase; |
5 |
import static junit.framework.TestCase.assertEquals; |
6 |
import org.gvsig.expressionevaluator.Code; |
7 |
import org.gvsig.expressionevaluator.Compiler; |
8 |
import org.gvsig.expressionevaluator.ExpressionEvaluatorLocator; |
9 |
import org.gvsig.expressionevaluator.ExpressionEvaluatorManager; |
10 |
import org.gvsig.expressionevaluator.Interpreter; |
11 |
import org.gvsig.expressionevaluator.LexicalAnalyzer; |
12 |
import org.gvsig.expressionevaluator.MutableSymbolTable; |
13 |
import org.gvsig.expressionevaluator.SymbolTable; |
14 |
import org.gvsig.tools.library.impl.DefaultLibrariesInitializer; |
15 |
|
16 |
/**
|
17 |
*
|
18 |
* @author jjdelcerro
|
19 |
*/
|
20 |
public class TestGrammarCompiler extends TestCase { |
21 |
|
22 |
public TestGrammarCompiler(String testName) { |
23 |
super(testName);
|
24 |
} |
25 |
|
26 |
@Override
|
27 |
protected void setUp() throws Exception { |
28 |
super.setUp();
|
29 |
new DefaultLibrariesInitializer().fullInitialize();
|
30 |
} |
31 |
|
32 |
@Override
|
33 |
protected void tearDown() throws Exception { |
34 |
super.tearDown();
|
35 |
} |
36 |
|
37 |
// TODO add test methods here. The name must begin with 'test'. For example:
|
38 |
// public void testHello() {}
|
39 |
|
40 |
protected LexicalAnalyzer createLexicalAnalyzer() {
|
41 |
ExpressionEvaluatorManager manager = ExpressionEvaluatorLocator.getManager(); |
42 |
LexicalAnalyzer lexer = manager.createLexicalAnalyzer(); |
43 |
return lexer;
|
44 |
} |
45 |
|
46 |
protected org.gvsig.expressionevaluator.Compiler createCompiler() {
|
47 |
ExpressionEvaluatorManager manager = ExpressionEvaluatorLocator.getManager(); |
48 |
Compiler compiler = manager.createCompiler();
|
49 |
compiler.setLexicalAnalyzer(createLexicalAnalyzer()); |
50 |
return compiler;
|
51 |
} |
52 |
|
53 |
protected SymbolTable createSymbolTable() {
|
54 |
ExpressionEvaluatorManager manager = ExpressionEvaluatorLocator.getManager(); |
55 |
MutableSymbolTable symbolTable = manager.createSymbolTable(); |
56 |
symbolTable.setVar("precio", 200); |
57 |
symbolTable.setVar("1990", 0.168873933773767); |
58 |
return symbolTable;
|
59 |
} |
60 |
|
61 |
protected Interpreter createInterpreter(SymbolTable symbolTable) {
|
62 |
ExpressionEvaluatorManager manager = ExpressionEvaluatorLocator.getManager(); |
63 |
Interpreter interpreter = manager.createInterpreter(); |
64 |
interpreter.setSymbolTable(symbolTable); |
65 |
return interpreter;
|
66 |
} |
67 |
|
68 |
private void link(Code code) { |
69 |
code.link(createSymbolTable()); |
70 |
} |
71 |
|
72 |
private void dump(String testname, Object expected, Object actual) { |
73 |
System.out.println("### ---------------------"); |
74 |
System.out.println("### "+testname); |
75 |
System.out.println("### expected: ["+Objects.toString(expected)+"]"); |
76 |
System.out.println("### actual : ["+Objects.toString(actual)+"]"); |
77 |
} |
78 |
|
79 |
private void checkEquals(String testname, Object expected, Object actual) { |
80 |
dump(testname,expected,actual); |
81 |
assertEquals(expected, actual); |
82 |
} |
83 |
|
84 |
private void checkEquals(Object expected, Object actual) { |
85 |
try {
|
86 |
throw new RuntimeException(); |
87 |
} catch(Throwable t) { |
88 |
String testname = t.getStackTrace()[1].getMethodName(); |
89 |
checkEquals(testname,expected,actual); |
90 |
} |
91 |
} |
92 |
|
93 |
public void testLet() { |
94 |
String source = "LET V1 = 23"; |
95 |
|
96 |
Compiler compiler = createCompiler();
|
97 |
|
98 |
Code code = compiler.compileExpression(source); |
99 |
checkEquals("LET('V1', 23)", code.toString());
|
100 |
} |
101 |
|
102 |
public void testVar() { |
103 |
String source = "VAR V1 DEFAULT 23"; |
104 |
|
105 |
Compiler compiler = createCompiler();
|
106 |
|
107 |
Code code = compiler.compileExpression(source); |
108 |
checkEquals("VAR(\"V1\", 23)", code.toString());
|
109 |
} |
110 |
|
111 |
public void testVar2() { |
112 |
String source = "VAR V1 DEFAULT 23"; |
113 |
|
114 |
Compiler compiler = createCompiler();
|
115 |
|
116 |
Code code = compiler.compileExpression(source); |
117 |
link(code); |
118 |
checkEquals("VAR \"V1\" DEFAULT 23", code.toString());
|
119 |
} |
120 |
|
121 |
public void testBlock() { |
122 |
String source = "BEGIN LET V1 = 23; END"; |
123 |
|
124 |
Compiler compiler = createCompiler();
|
125 |
|
126 |
Code code = compiler.compileExpression(source); |
127 |
checkEquals("BLOCK(LET('V1', 23))", code.toString());
|
128 |
} |
129 |
|
130 |
public void testBlockExcept() { |
131 |
String source = "BEGIN LET V1 = 23; EXCEPT NULL; END"; |
132 |
|
133 |
Compiler compiler = createCompiler();
|
134 |
|
135 |
Code code = compiler.compileExpression(source); |
136 |
checkEquals("BLOCK_EXCEPT(LET('V1', 23), NULL)", code.toString());
|
137 |
} |
138 |
|
139 |
public void testBlock2() { |
140 |
String source = "BEGIN LET V1 = 11; LET V2 = 22; END"; |
141 |
|
142 |
Compiler compiler = createCompiler();
|
143 |
|
144 |
Code code = compiler.compileExpression(source); |
145 |
link(code); |
146 |
checkEquals("BEGIN \"V1\" := 11; \"V2\" := 22; END ", code.toString());
|
147 |
} |
148 |
|
149 |
public void testBlockExcept2() { |
150 |
String source = "BEGIN LET V1 = 11; LET V2 = 22; EXCEPT -1; END"; |
151 |
|
152 |
Compiler compiler = createCompiler();
|
153 |
|
154 |
Code code = compiler.compileExpression(source); |
155 |
link(code); |
156 |
checkEquals("BEGIN \"V1\" := 11; \"V2\" := 22; EXCEPT -1 END ", code.toString());
|
157 |
} |
158 |
|
159 |
public void testBlock3() { |
160 |
Compiler compiler = createCompiler();
|
161 |
|
162 |
String source = "BEGIN LET V1 = 11; LET V2 = 22; END"; |
163 |
Code code = compiler.compileExpression(source); |
164 |
link(code); |
165 |
checkEquals("BEGIN \"V1\" := 11; \"V2\" := 22; END ", code.toString());
|
166 |
|
167 |
source = "BEGIN LET V1 = 11;; LET V2 = 22;;; END";
|
168 |
code = compiler.compileExpression(source); |
169 |
link(code); |
170 |
checkEquals("BEGIN \"V1\" := 11; \"V2\" := 22; END ", code.toString());
|
171 |
} |
172 |
|
173 |
public void testIfThen() { |
174 |
String source = "IF V1 = 11 THEN LET V2 = 22; END IF"; |
175 |
|
176 |
Compiler compiler = createCompiler();
|
177 |
|
178 |
Code code = compiler.compileExpression(source); |
179 |
link(code); |
180 |
checkEquals("IF (\"V1\" = 11) THEN \"V2\" := 22 END IF", code.toString());
|
181 |
} |
182 |
|
183 |
public void testIfThenElse() { |
184 |
String source = "IF V1 = 11 THEN LET V2 = 11; ELSE LET V2 = 22; END IF"; |
185 |
|
186 |
Compiler compiler = createCompiler();
|
187 |
|
188 |
Code code = compiler.compileExpression(source); |
189 |
link(code); |
190 |
checkEquals("IF (\"V1\" = 11) THEN \"V2\" := 11; ELSE \"V2\" := 22; END IF", code.toString());
|
191 |
} |
192 |
|
193 |
public void testIfThenPassElsePass() { |
194 |
String source = "IF V1 = 11 THEN PASS; ELSE PASS; END IF"; |
195 |
|
196 |
Compiler compiler = createCompiler();
|
197 |
|
198 |
Code code = compiler.compileExpression(source); |
199 |
link(code); |
200 |
checkEquals("IF (\"V1\" = 11) THEN PASS; ELSE PASS; END IF", code.toString());
|
201 |
} |
202 |
|
203 |
public void testIfThenBlock() { |
204 |
String source = "IF V1 = 11 THEN LET V2 = 22; LET V1 = 10; END IF"; |
205 |
|
206 |
Compiler compiler = createCompiler();
|
207 |
|
208 |
Code code = compiler.compileExpression(source); |
209 |
link(code); |
210 |
checkEquals("IF (\"V1\" = 11) THEN \"V2\" := 22; \"V1\" := 10; END IF", code.toString());
|
211 |
} |
212 |
|
213 |
public void testWhile() { |
214 |
String source = "WHILE n < 10 BEGIN LET n = n + 1; END WHILE"; |
215 |
|
216 |
Compiler compiler = createCompiler();
|
217 |
|
218 |
Code code = compiler.compileExpression(source); |
219 |
link(code); |
220 |
checkEquals("WHILE (\"n\" < 10) LOOP \"n\" := (\"n\" + 1) END LOOP ", code.toString());
|
221 |
} |
222 |
|
223 |
public void testWhileBlock() { |
224 |
String source = "WHILE n < 10 BEGIN LET n = n + 1; print(n); END WHILE"; |
225 |
|
226 |
Compiler compiler = createCompiler();
|
227 |
|
228 |
Code code = compiler.compileExpression(source); |
229 |
link(code); |
230 |
checkEquals("WHILE (\"n\" < 10) LOOP \"n\" := (\"n\" + 1); print(\"n\"); END LOOP ", code.toString());
|
231 |
} |
232 |
|
233 |
public void testWhileBreak() { |
234 |
String source = "WHILE n < 10 BEGIN LET n = n + 1; print(n); BREAK; END WHILE"; |
235 |
|
236 |
Compiler compiler = createCompiler();
|
237 |
|
238 |
Code code = compiler.compileExpression(source); |
239 |
link(code); |
240 |
checkEquals("WHILE (\"n\" < 10) LOOP \"n\" := (\"n\" + 1); print(\"n\"); BREAK; END LOOP ", code.toString());
|
241 |
} |
242 |
|
243 |
public void testCast() { |
244 |
String source = "CAST(V1 AS INTEGER)"; |
245 |
|
246 |
Compiler compiler = createCompiler();
|
247 |
|
248 |
Code code = compiler.compileExpression(source); |
249 |
link(code); |
250 |
checkEquals("CAST(\"V1\" AS INTEGER)", code.toString());
|
251 |
} |
252 |
|
253 |
public void testCast2() { |
254 |
String source = "CAST V1 AS INTEGER"; |
255 |
|
256 |
Compiler compiler = createCompiler();
|
257 |
|
258 |
Code code = compiler.compileExpression(source); |
259 |
link(code); |
260 |
checkEquals("CAST(\"V1\" AS INTEGER)", code.toString());
|
261 |
} |
262 |
|
263 |
public void testMatch() { |
264 |
Compiler compiler = createCompiler();
|
265 |
String source;
|
266 |
Code code; |
267 |
|
268 |
source = "MATCH 'Hola', '[Hh]ola'";
|
269 |
code = compiler.compileExpression(source); |
270 |
link(code); |
271 |
checkEquals("~('Hola', '[Hh]ola')", code.toString());
|
272 |
|
273 |
source = "MATCH 'Hola' '[Hh]ola'";
|
274 |
code = compiler.compileExpression(source); |
275 |
link(code); |
276 |
checkEquals("~('Hola', '[Hh]ola')", code.toString());
|
277 |
|
278 |
source = "MATCH('Hola', '[Hh]ola')";
|
279 |
code = compiler.compileExpression(source); |
280 |
link(code); |
281 |
checkEquals("~('Hola', '[Hh]ola')", code.toString());
|
282 |
} |
283 |
|
284 |
public void testForEach() { |
285 |
String source = "FOR n in RANGE(10) LOOP print(n); END LOOP"; |
286 |
|
287 |
Compiler compiler = createCompiler();
|
288 |
|
289 |
Code code = compiler.compileExpression(source); |
290 |
link(code); |
291 |
checkEquals("FOR \"n\" IN RANGE(10) LOOP print(\"n\") END LOOP", code.toString());
|
292 |
} |
293 |
|
294 |
public void testForEachBreak() { |
295 |
String source = "FOR n in RANGE(10) LOOP print(n); BREAK; END LOOP"; |
296 |
|
297 |
Compiler compiler = createCompiler();
|
298 |
|
299 |
Code code = compiler.compileExpression(source); |
300 |
link(code); |
301 |
checkEquals("FOR \"n\" IN RANGE(10) LOOP print(\"n\"); BREAK; END LOOP", code.toString());
|
302 |
Code code2 = compiler.compileExpression(code.toString()); |
303 |
link(code2); |
304 |
checkEquals("FOR \"n\" IN RANGE(10) LOOP print(\"n\"); BREAK; END LOOP", code2.toString());
|
305 |
} |
306 |
|
307 |
public void testForEach2() { |
308 |
String source = "FOR n in RANGE(10)\nLOOP\n print(n);\nEND LOOP"; |
309 |
|
310 |
Compiler compiler = createCompiler();
|
311 |
|
312 |
Code code = compiler.compileExpression(source); |
313 |
link(code); |
314 |
checkEquals("FOR \"n\" IN RANGE(10) LOOP print(\"n\") END LOOP", code.toString());
|
315 |
} |
316 |
|
317 |
// public void testFor() {
|
318 |
// String source = "FOR LET n = 0 ; n < 10 ; LET n = n + 1 print(n)";
|
319 |
//
|
320 |
// Compiler compiler = createCompiler();
|
321 |
//
|
322 |
// Code code = compiler.compileExpression(source);
|
323 |
// checkEquals("FOR(LET('n', 0), <(\"n\", 10), LET('n', +(\"n\", 1)), print(\"n\"))", code.toString());
|
324 |
// }
|
325 |
|
326 |
public void testCase() { |
327 |
String source = "CASE WHEN software LIKE '%gvSIG%' THEN 'gvSIG'; ELSE 'Other'; END CASE"; // ;) |
328 |
|
329 |
Compiler compiler = createCompiler();
|
330 |
|
331 |
Code code = compiler.compileExpression(source); |
332 |
link(code); |
333 |
checkEquals("CASE WHEN (\"software\" LIKE '%gvSIG%') THEN 'gvSIG'; ELSE 'Other'; END", code.toString());
|
334 |
} |
335 |
|
336 |
public void testCase1() { |
337 |
String source = "CASE WHEN software LIKE '%gvSIG%' THEN 10; 'gvSIG'; ELSE 20;'Other'; END CASE"; // ;) |
338 |
|
339 |
Compiler compiler = createCompiler();
|
340 |
|
341 |
Code code = compiler.compileExpression(source); |
342 |
link(code); |
343 |
checkEquals("CASE WHEN (\"software\" LIKE '%gvSIG%') THEN 10; 'gvSIG'; ELSE 20; 'Other'; END", code.toString());
|
344 |
} |
345 |
|
346 |
public void testCase2() { |
347 |
String source = "CASE WHEN Field_1 >= 75 AND Field_1 <=79 THEN 100; WHEN Field_1 >=80 AND Field_1 <=84 THEN 110; END CASE"; // ;) |
348 |
|
349 |
Compiler compiler = createCompiler();
|
350 |
|
351 |
Code code = compiler.compileExpression(source); |
352 |
link(code); |
353 |
checkEquals("CASE WHEN ((\"Field_1\" >= 75) AND (\"Field_1\" <= 79)) THEN 100; WHEN ((\"Field_1\" >= 80) AND (\"Field_1\" <= 84)) THEN 110; END", code.toString());
|
354 |
} |
355 |
|
356 |
public void testCase3() { |
357 |
String source = "CASE WHEN Field_1 >= 75 AND Field_1 <=79 THEN 100; WHEN Field_1 >=80 AND Field_1 <=84 THEN 110; ELSE 120; END CASE"; // ;) |
358 |
|
359 |
Compiler compiler = createCompiler();
|
360 |
|
361 |
Code code = compiler.compileExpression(source); |
362 |
link(code); |
363 |
checkEquals("CASE WHEN ((\"Field_1\" >= 75) AND (\"Field_1\" <= 79)) THEN 100; WHEN ((\"Field_1\" >= 80) AND (\"Field_1\" <= 84)) THEN 110; ELSE 120; END", code.toString());
|
364 |
} |
365 |
|
366 |
public void testCase3b() { |
367 |
String source = "CASE WHEN Field_1 >= 75 AND Field_1 <=79 THEN 100; WHEN Field_1 >=80 AND Field_1 <=84 THEN 110; ELSE 120; END CASE"; // ;) |
368 |
|
369 |
Compiler compiler = createCompiler();
|
370 |
Code code = compiler.compileExpression(source); |
371 |
link(code); |
372 |
checkEquals("CASE WHEN ((\"Field_1\" >= 75) AND (\"Field_1\" <= 79)) THEN 100; WHEN ((\"Field_1\" >= 80) AND (\"Field_1\" <= 84)) THEN 110; ELSE 120; END", code.toString());
|
373 |
code = compiler.compileExpression(code.toString()); |
374 |
link(code); |
375 |
checkEquals("CASE WHEN ((\"Field_1\" >= 75) AND (\"Field_1\" <= 79)) THEN 100; WHEN ((\"Field_1\" >= 80) AND (\"Field_1\" <= 84)) THEN 110; ELSE 120; END", code.toString());
|
376 |
} |
377 |
|
378 |
public void testDef1() { |
379 |
String source = "CREATE PROCEDURE test1 AS BEGIN print('Hola'); END PROCEDURE"; |
380 |
|
381 |
Compiler compiler = createCompiler();
|
382 |
|
383 |
Code code = compiler.compileExpression(source); |
384 |
link(code); |
385 |
checkEquals("CREATE_FUNCTION('test1', NULL, print('Hola'), NULL, NULL, NULL, NULL, NULL)", code.toString());
|
386 |
|
387 |
} |
388 |
|
389 |
public void testDef2() { |
390 |
String source = "CREATE PROCEDURE test1 nombre AS BEGIN print('Hola '+nombre); END PROCEDURE"; |
391 |
|
392 |
Compiler compiler = createCompiler();
|
393 |
|
394 |
Code code = compiler.compileExpression(source); |
395 |
link(code); |
396 |
checkEquals("CREATE_FUNCTION('test1', ARRAY[ 'nombre' ], print(('Hola ' + \"nombre\")), NULL, NULL, NULL, NULL, NULL)", code.toString());
|
397 |
} |
398 |
|
399 |
public void testDef3() { |
400 |
String source = "CREATE PROCEDURE test1 nombre AS BEGIN RETURN 'Hola '||nombre; END PROCEDURE"; |
401 |
|
402 |
Compiler compiler = createCompiler();
|
403 |
|
404 |
Code code = compiler.compileExpression(source); |
405 |
link(code); |
406 |
checkEquals("CREATE_FUNCTION('test1', ARRAY[ 'nombre' ], RETURN ('Hola ' || \"nombre\"), NULL, NULL, NULL, NULL, NULL)", code.toString());
|
407 |
} |
408 |
|
409 |
public void testDef4() { |
410 |
String source = "CREATE PROCEDURE test1 nombre AS BEGIN RETURN; END PROCEDURE"; |
411 |
|
412 |
Compiler compiler = createCompiler();
|
413 |
|
414 |
Code code = compiler.compileExpression(source); |
415 |
link(code); |
416 |
checkEquals("CREATE_FUNCTION('test1', ARRAY[ 'nombre' ], RETURN NULL, NULL, NULL, NULL, NULL, NULL)", code.toString());
|
417 |
} |
418 |
|
419 |
public void testDef5() { |
420 |
String source = "CREATE PROCEDURE test1(nombre) IS DECLARE hola:='Hola'; BEGIN RETURN hola||' '||nombre; END PROCEDURE"; |
421 |
|
422 |
Compiler compiler = createCompiler();
|
423 |
|
424 |
Code code = compiler.compileExpression(source); |
425 |
link(code); |
426 |
checkEquals("CREATE_FUNCTION('test1', ARRAY[ 'nombre' ], RETURN ((\"hola\" || ' ') || \"nombre\"), NULL, NULL, NULL, NULL, \"hola\" := 'Hola')", code.toString());
|
427 |
} |
428 |
|
429 |
public void testCreateFunctionExtern1() { |
430 |
String source = "CREATE FUNCTION test1(nombre) AS 'addons/test/test', 'test1' LANGUAGE 'cosa'"; |
431 |
|
432 |
Compiler compiler = createCompiler();
|
433 |
|
434 |
Code code = compiler.compileExpression(source); |
435 |
link(code); |
436 |
checkEquals("CREATE_FUNCTION('test1', ARRAY[ 'nombre' ], NULL, 'addons/test/test', 'test1', 'cosa', NULL, NULL)", code.toString());
|
437 |
} |
438 |
|
439 |
public void testList() { |
440 |
String source = "set x TO [ 'hola','adios','fin' ]"; |
441 |
|
442 |
Compiler compiler = createCompiler();
|
443 |
|
444 |
Code code = compiler.compileExpression(source); |
445 |
link(code); |
446 |
checkEquals("\"x\" := ARRAY[ 'hola', 'adios', 'fin' ]", code.toString());
|
447 |
} |
448 |
|
449 |
public void testList2() { |
450 |
String source = "set x TO LIST('hola','adios','fin')"; |
451 |
|
452 |
Compiler compiler = createCompiler();
|
453 |
|
454 |
Code code = compiler.compileExpression(source); |
455 |
link(code); |
456 |
checkEquals("\"x\" := ARRAY[ 'hola', 'adios', 'fin' ]", code.toString());
|
457 |
} |
458 |
|
459 |
public void testEmptyList() { |
460 |
String source = "set x TO [ ]"; |
461 |
|
462 |
Compiler compiler = createCompiler();
|
463 |
|
464 |
Code code = compiler.compileExpression(source); |
465 |
link(code); |
466 |
checkEquals("\"x\" := ARRAY[ ]", code.toString());
|
467 |
} |
468 |
|
469 |
public void testEmptyDict() { |
470 |
String source = "set x TO { }"; |
471 |
|
472 |
Compiler compiler = createCompiler();
|
473 |
|
474 |
Code code = compiler.compileExpression(source); |
475 |
link(code); |
476 |
checkEquals("\"x\" := { }", code.toString());
|
477 |
} |
478 |
|
479 |
public void testTuple() { |
480 |
String source = "set x TO TUPLE('hola','adios','fin')"; |
481 |
|
482 |
Compiler compiler = createCompiler();
|
483 |
|
484 |
Code code = compiler.compileExpression(source); |
485 |
link(code); |
486 |
checkEquals("\"x\" := TUPLE('hola', 'adios', 'fin')", code.toString());
|
487 |
} |
488 |
|
489 |
public void testArray() { |
490 |
String source = "set x TO ARRAY['hola','adios','fin']"; |
491 |
|
492 |
Compiler compiler = createCompiler();
|
493 |
|
494 |
Code code = compiler.compileExpression(source); |
495 |
link(code); |
496 |
checkEquals("\"x\" := ARRAY[ 'hola', 'adios', 'fin' ]", code.toString());
|
497 |
} |
498 |
|
499 |
public void testUseCase1() { |
500 |
String source = "begin set x = ''; for n in ARRAY['hola','adios','fin'] loop let x = x || ' ' || n; end loop; end"; |
501 |
|
502 |
Compiler compiler = createCompiler();
|
503 |
|
504 |
Code code = compiler.compileExpression(source); |
505 |
link(code); |
506 |
checkEquals("BEGIN \"x\" := ''; FOR \"n\" IN ARRAY[ 'hola', 'adios', 'fin' ] LOOP \"x\" := ((\"x\" || ' ') || \"n\") END LOOP; END ", code.toString());
|
507 |
} |
508 |
|
509 |
public void testUseCase2() { |
510 |
String source = "begin s := ''; x := ARRAY[ 'hola','adios','fin' ]; FOR n in RANGE(3) LOOP set s = s || ' ' || x[n]; end loop; end"; |
511 |
|
512 |
Compiler compiler = createCompiler();
|
513 |
|
514 |
Code code = compiler.compileExpression(source); |
515 |
link(code); |
516 |
checkEquals("BEGIN \"s\" := ''; \"x\" := ARRAY[ 'hola', 'adios', 'fin' ]; FOR \"n\" IN RANGE(3) LOOP \"s\" := ((\"s\" || ' ') || \"x\"[\"n\"]) END LOOP; END ", code.toString());
|
517 |
} |
518 |
|
519 |
public void testPass1() { |
520 |
String source = "pass"; |
521 |
|
522 |
Compiler compiler = createCompiler();
|
523 |
|
524 |
Code code = compiler.compileExpression(source); |
525 |
link(code); |
526 |
checkEquals("PASS", code.toString());
|
527 |
} |
528 |
|
529 |
public void test$Constant1() { |
530 |
// String source = "set x = :'hola'";
|
531 |
String source = "set x = <%='hola'%>"; |
532 |
|
533 |
Compiler compiler = createCompiler();
|
534 |
|
535 |
Code code = compiler.compileExpression(source); |
536 |
link(code); |
537 |
checkEquals("\"x\" := :IN ('hola')", code.toString());
|
538 |
} |
539 |
|
540 |
|
541 |
} |