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 package name.angoca.zemucan.ui.impl.jline;
30
31 import java.io.ByteArrayOutputStream;
32 import java.io.IOException;
33 import java.io.OutputStreamWriter;
34 import java.io.PrintWriter;
35 import java.util.Iterator;
36
37 import jline.AssertionHelper;
38 import jline.Buffer;
39 import jline.Completor;
40 import jline.ConsoleOperations;
41 import jline.ConsoleReader;
42 import jline.UnixTerminal;
43 import name.angoca.zemucan.AbstractZemucanException;
44 import name.angoca.zemucan.core.lexical.impl.ImplementationLexicalAnalyzer;
45 import name.angoca.zemucan.grammarReader.api.GrammarReaderController;
46 import name.angoca.zemucan.tools.Constants;
47 import name.angoca.zemucan.tools.configurator.Configurator;
48 import name.angoca.zemucan.tools.test.RandomTestRunner;
49
50 import org.junit.After;
51 import org.junit.Before;
52 import org.junit.BeforeClass;
53 import org.junit.Test;
54 import org.junit.runner.RunWith;
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73 @RunWith(RandomTestRunner.class)
74 public final class JlineInputReaderTest {
75
76
77
78
79
80
81
82 @BeforeClass
83 public static void setUpBeforeClass() throws AbstractZemucanException {
84 System.setProperty(Constants.ZEMUCAN_CONF_XML_PROPERTY,
85 "sa_conf-test-realGrammar.xml");
86 Configurator.getInstance().setProperty(
87 Constants.GRAMMAR_READER_NAME_PROPERTY,
88 Configurator.GRAMMAR_READER_NAME_VALUE);
89
90
91 ImplementationLexicalAnalyzer.getInstance();
92 }
93
94
95
96
97
98
99
100 @Before
101 public void setUp() throws IOException {
102 AssertionHelper.setConsole(new ConsoleReader(null, new PrintWriter(
103 new OutputStreamWriter(new ByteArrayOutputStream())), null,
104 new UnixTerminal()));
105
106
107 for (@SuppressWarnings("unchecked")
108 final Iterator<Completor> iterator = AssertionHelper.getConsole()
109 .getCompletors().iterator(); iterator.hasNext();) {
110 final Completor type = iterator.next();
111 AssertionHelper.getConsole().removeCompletor(type);
112 }
113
114
115
116 AssertionHelper.getConsole().addCompletor(new ZemucanCompletor());
117 AssertionHelper.getConsole().setCompletionHandler(
118 new ZemucanCompletionHandler());
119
120 AssertionHelper.getConsole().setAutoprintThreshhold(50);
121 }
122
123
124
125
126 @After
127 public void tearDown() {
128
129 ImplementationLexicalAnalyzer.destroyInstance();
130
131
132 Configurator.destroyInstance();
133
134 GrammarReaderController.destroyInstance();
135 }
136
137
138
139
140
141
142
143 @Test
144 public void test1() throws IOException {
145 final Buffer b = new Buffer("");
146 b.op(ConsoleOperations.COMPLETE);
147
148 AssertionHelper.assertBuffer("empty", "", b);
149 }
150
151
152
153
154
155
156
157 @Test
158 public void test10() throws IOException {
159 final String command = "db2 create";
160 final Buffer b = new Buffer(command);
161 b.op(ConsoleOperations.COMPLETE);
162
163 AssertionHelper.assertBuffer(command, "db2 create table", b);
164 }
165
166
167
168
169
170
171
172 @Test
173 public void test10a() throws IOException {
174 final String command = " db2 create";
175 final Buffer b = new Buffer(command);
176 b.op(ConsoleOperations.COMPLETE);
177
178 AssertionHelper.assertBuffer(command, " db2 create table", b);
179 }
180
181
182
183
184
185
186
187
188
189 public void test11() throws IOException {
190 final String command = "db2 create ";
191 final Buffer b = new Buffer(command);
192 b.op(ConsoleOperations.COMPLETE);
193
194 AssertionHelper.assertBuffer(command, "db2 create table", b);
195 }
196
197
198
199
200
201
202
203 @Test
204 public void test12() throws IOException {
205 final String command = "db2 create t";
206 final Buffer b = new Buffer(command);
207 b.op(ConsoleOperations.COMPLETE);
208
209 AssertionHelper.assertBuffer(command, "db2 create table", b);
210 }
211
212
213
214
215
216
217
218 @Test
219 public void test13() throws IOException {
220 final String command = "db2 create tables";
221 final Buffer b = new Buffer(command);
222 b.op(ConsoleOperations.COMPLETE);
223
224 AssertionHelper.assertBuffer(command, "db2 create tablespace", b);
225 }
226
227
228
229
230
231
232
233 @Test
234 public void test14() throws IOException {
235 final String command = "db2 create tablespace";
236 final Buffer b = new Buffer(command);
237 b.op(ConsoleOperations.COMPLETE);
238
239 AssertionHelper.assertBuffer(command, "db2 create tablespace", b);
240 }
241
242
243
244
245
246
247
248 @Test
249 public void test15() throws IOException {
250 final String command = "db2 create ta";
251 final Buffer b = new Buffer(command);
252 b.op(ConsoleOperations.COMPLETE);
253
254 AssertionHelper.assertBuffer(command, "db2 create table", b);
255 }
256
257
258
259
260
261
262
263 @Test
264 public void test16() throws IOException {
265 final String command = "db2 create table";
266 final Buffer b = new Buffer(command);
267 b.op(ConsoleOperations.COMPLETE);
268
269 AssertionHelper.assertBuffer(command, "db2 create table", b);
270 }
271
272
273
274
275
276
277
278 @Test
279 public void test17() throws IOException {
280 final String command = "db2 create table ";
281 final Buffer b = new Buffer(command);
282 b.op(ConsoleOperations.COMPLETE);
283
284 AssertionHelper.assertBuffer(command, "db2 create table ", b);
285 }
286
287
288
289
290
291
292
293 @Test
294 public void test18() throws IOException {
295 final String command = "db2 create table t1";
296 final Buffer b = new Buffer(command);
297 b.op(ConsoleOperations.COMPLETE);
298
299 AssertionHelper.assertBuffer(command, "db2 create table t1 (", b);
300 }
301
302
303
304
305
306
307
308 @Test
309 public void test19() throws IOException {
310 final String command = "db2 create table t1 ";
311 final Buffer b = new Buffer(command);
312 b.op(ConsoleOperations.COMPLETE);
313
314 AssertionHelper.assertBuffer(command, "db2 create table t1 (", b);
315 }
316
317
318
319
320
321
322
323 @Test
324 public void test2() throws IOException {
325 final String command = "d";
326 final Buffer b = new Buffer(command);
327 b.op(ConsoleOperations.COMPLETE);
328
329 AssertionHelper.assertBuffer(command, "db2", b);
330 }
331
332
333
334
335
336
337
338 @Test
339 public void test20() throws IOException {
340 final String command = "db2 create table t1 (";
341 final Buffer b = new Buffer(command);
342 b.op(ConsoleOperations.COMPLETE);
343
344 AssertionHelper.assertBuffer(command, "db2 create table t1 ( ", b);
345 }
346
347
348
349
350
351
352
353 @Test
354 public void test21() throws IOException {
355 final String command = "db2 create table t1(";
356 final Buffer b = new Buffer(command);
357 b.op(ConsoleOperations.COMPLETE);
358
359 AssertionHelper.assertBuffer(command, "db2 create table t1( ", b);
360 }
361
362
363
364
365
366
367
368 @Test
369 public void test22() throws IOException {
370 final String command = "db2 create table t1(c1";
371 final Buffer b = new Buffer(command);
372 b.op(ConsoleOperations.COMPLETE);
373
374 AssertionHelper.assertBuffer(command, "db2 create table t1(c1 ", b);
375 }
376
377
378
379
380
381
382
383 @Test
384 public void test23() throws IOException {
385 final String command = "db2 create table t1( c1";
386 final Buffer b = new Buffer(command);
387 b.op(ConsoleOperations.COMPLETE);
388
389 AssertionHelper.assertBuffer(command, "db2 create table t1( c1 ", b);
390 }
391
392
393
394
395
396
397
398 @Test
399 public void test24() throws IOException {
400 final String command = "db2 create table t1 ( c1 int )";
401 final Buffer b = new Buffer(command);
402 b.op(ConsoleOperations.COMPLETE);
403
404 AssertionHelper.assertBuffer(command, "db2 create table t1 ( c1 int )",
405 b);
406 }
407
408
409
410
411
412
413
414 @Test
415 public void test25() throws IOException {
416 final String command = " db2";
417 final Buffer b = new Buffer(command);
418 b.op(ConsoleOperations.COMPLETE);
419
420 AssertionHelper.assertBuffer(command, " db2", b);
421 }
422
423
424
425
426
427
428
429 @Test
430 public void test25a() throws IOException {
431 final String command = " db2";
432 final Buffer b = new Buffer(command);
433 b.op(ConsoleOperations.COMPLETE);
434
435 AssertionHelper.assertBuffer(command, " db2", b);
436 }
437
438
439
440
441
442
443
444 @Test
445 public void test26() throws IOException {
446 final String command = "DB";
447 final Buffer b = new Buffer(command);
448 b.op(ConsoleOperations.COMPLETE);
449
450 AssertionHelper.assertBuffer(command, "DB2", b);
451 }
452
453
454
455
456
457
458
459 @Test
460 public void test26a() throws IOException {
461 final String command = " DB";
462 final Buffer b = new Buffer(command);
463 b.op(ConsoleOperations.COMPLETE);
464
465 AssertionHelper.assertBuffer(command, " DB2", b);
466 }
467
468
469
470
471
472
473
474 @Test
475 public void test27() throws IOException {
476 final String command = "DB2 CREA";
477 final Buffer b = new Buffer(command);
478 b.op(ConsoleOperations.COMPLETE);
479
480 AssertionHelper.assertBuffer(command, "DB2 CREAte", b);
481 }
482
483
484
485
486
487
488
489 @Test
490 public void test27a() throws IOException {
491 final String command = " DB2 CREA";
492 final Buffer b = new Buffer(command);
493 b.op(ConsoleOperations.COMPLETE);
494
495 AssertionHelper.assertBuffer(command, " DB2 CREAte", b);
496 }
497
498
499
500
501
502
503
504 @Test
505 public void test3() throws IOException {
506 final String command = "db";
507 final Buffer b = new Buffer(command);
508 b.op(ConsoleOperations.COMPLETE);
509
510 AssertionHelper.assertBuffer(command, "db2", b);
511 }
512
513
514
515
516
517
518
519 @Test
520 public void test4() throws IOException {
521 final String command = "db2";
522 final Buffer b = new Buffer(command);
523 b.op(ConsoleOperations.COMPLETE);
524
525 AssertionHelper.assertBuffer(command, "db2", b);
526 }
527
528
529
530
531
532
533
534 @Test
535 public void test5() throws IOException {
536 final String command = "db2 ";
537 final Buffer b = new Buffer(command);
538 b.op(ConsoleOperations.COMPLETE);
539
540 AssertionHelper.assertBuffer(command, "db2 ", b);
541 }
542
543
544
545
546
547
548
549 @Test
550 public void test5a() throws IOException {
551 final String command = "db2 ";
552 final Buffer b = new Buffer(command);
553 b.op(ConsoleOperations.COMPLETE);
554
555 AssertionHelper.assertBuffer(command, "db2 ", b);
556 }
557
558
559
560
561
562
563
564 @Test
565 public void test6() throws IOException {
566 final String command = "db2 a";
567 final Buffer b = new Buffer(command);
568 b.op(ConsoleOperations.COMPLETE);
569
570 AssertionHelper.assertBuffer(command, "db2 attach", b);
571 }
572
573
574
575
576
577
578
579 @Test
580 public void test6a() throws IOException {
581 final String command = "db2 c";
582 final Buffer b = new Buffer(command);
583 b.op(ConsoleOperations.COMPLETE);
584
585 AssertionHelper.assertBuffer(command, "db2 c", b);
586 }
587
588
589
590
591
592
593
594 @Test
595 public void test7() throws IOException {
596 final String command = "db2 cr";
597 final Buffer b = new Buffer(command);
598 b.op(ConsoleOperations.COMPLETE);
599
600 AssertionHelper.assertBuffer(command, "db2 create", b);
601 }
602
603
604
605
606
607
608
609 @Test
610 public void test8() throws IOException {
611 final String command = "db2 crea";
612 final Buffer b = new Buffer(command);
613 b.op(ConsoleOperations.COMPLETE);
614
615 AssertionHelper.assertBuffer(command, "db2 create", b);
616 }
617
618
619
620
621
622
623
624 @Test
625 public void test8a() throws IOException {
626 final String command = " db2 crea";
627 final Buffer b = new Buffer(command);
628 b.op(ConsoleOperations.COMPLETE);
629
630 AssertionHelper.assertBuffer(command, " db2 create", b);
631 }
632
633
634
635
636
637
638
639 @Test
640 public void test9() throws IOException {
641 final String command = "db2 crea ";
642 final Buffer b = new Buffer(command);
643 b.op(ConsoleOperations.COMPLETE);
644
645 AssertionHelper.assertBuffer(command, "db2 crea ", b);
646 }
647 }