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.core.syntactic.impl;
30
31 import java.util.ArrayList;
32 import java.util.List;
33
34 import name.angoca.zemucan.AbstractZemucanException;
35 import name.angoca.zemucan.core.lexical.model.Token;
36 import name.angoca.zemucan.core.syntactic.model.GraphAnswer;
37 import name.angoca.zemucan.grammarReader.api.GrammarReaderController;
38 import name.angoca.zemucan.tools.Constants;
39 import name.angoca.zemucan.tools.configurator.Configurator;
40 import name.angoca.zemucan.tools.test.RandomTestRunner;
41
42 import org.junit.AfterClass;
43 import org.junit.Assert;
44 import org.junit.BeforeClass;
45 import org.junit.Test;
46 import org.junit.runner.RunWith;
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 @RunWith(RandomTestRunner.class)
81 public final class ImplementationSyntacticAnalyzerTest {
82
83
84
85
86 private static final String ABOUT = "about";
87
88
89
90
91 private static final String C1 = "c1";
92
93
94
95
96 private static final String CLOSE_PARENTHESIS = ")";
97
98
99
100 private static final String COL_NAME = "<colName>";
101
102
103
104 private static final String CREATE = "create";
105
106
107
108 private static final String HELP = "?";
109
110
111
112 private static final String INT = "int";
113
114
115
116 private static final String LICENSE = "license";
117
118
119
120 private static final String OPEN_PARENTHESIS = "(";
121
122
123
124 private static final String T1 = "t1";
125
126
127
128 private static final String TABLE = "table";
129
130
131
132 private static final String TABLE_NAME = "<tableName>";
133
134
135
136 private static final String TABLESPACE = "tablespace";
137
138
139
140 private static final String TOTO = "toto";
141
142
143
144
145
146
147
148 @BeforeClass
149 public static void setUpBeforeClass() throws AbstractZemucanException {
150 System.setProperty(Constants.ZEMUCAN_CONF_XML_PROPERTY,
151 "sa_conf-test.xml");
152 Configurator.getInstance().setProperty(
153 Constants.GRAMMAR_READER_NAME_PROPERTY,
154 Configurator.GRAMMAR_READER_NAME_VALUE);
155 Configurator.getInstance()
156 .setProperty(Constants.GRAMMAR_FILE_DESCRIPTORS_PROPERTY,
157 "grammar-test.xml");
158
159
160 ImplementationSyntacticAnalyzer.destroyInstance();
161 ImplementationSyntacticAnalyzer.getInstance();
162 }
163
164
165
166
167 @AfterClass
168 public static void tearDownAfterClass() {
169 ImplementationSyntacticAnalyzer.destroyInstance();
170 GrammarReaderController.destroyInstance();
171 Configurator.destroyInstance();
172 System.clearProperty(Constants.ZEMUCAN_CONF_XML_PROPERTY);
173 }
174
175
176
177
178 public ImplementationSyntacticAnalyzerTest() {
179
180 }
181
182
183
184
185
186
187
188 @Test
189 public void testGetOptions0() throws AbstractZemucanException {
190
191
192 final String option1 = ImplementationSyntacticAnalyzerTest.CREATE;
193 final String option2 = ImplementationSyntacticAnalyzerTest.ABOUT;
194 final String option3 = ImplementationSyntacticAnalyzerTest.HELP;
195 final String option4 = ImplementationSyntacticAnalyzerTest.LICENSE;
196
197 final List<Token> phraseIn = new ArrayList<Token>();
198 final boolean endsWithSpace = false;
199
200 final GraphAnswer actual = ImplementationSyntacticAnalyzer
201 .getInstance().analyzeTokens(phraseIn, endsWithSpace);
202
203 final List<Token> phraseOut = new ArrayList<Token>();
204 final List<Token> options = new ArrayList<Token>();
205 options.add(new Token(option1, true));
206 options.add(new Token(option2, true));
207 options.add(new Token(option3, true));
208 options.add(new Token(option4, true));
209 final GraphAnswer expected = new GraphAnswer(phraseOut, options);
210
211 Assert.assertEquals("Empty command.", expected, actual);
212 }
213
214
215
216
217
218
219
220 @Test
221 public void testGetOptions0options() throws AbstractZemucanException {
222
223
224 final String option1 = ImplementationSyntacticAnalyzerTest.CREATE;
225 final String option2 = ImplementationSyntacticAnalyzerTest.ABOUT;
226 final String option3 = ImplementationSyntacticAnalyzerTest.HELP;
227 final String option4 = ImplementationSyntacticAnalyzerTest.LICENSE;
228
229 final List<Token> phraseIn = new ArrayList<Token>();
230 final boolean endsWithSpace = false;
231 final GraphAnswer graph = ImplementationSyntacticAnalyzer.getInstance()
232 .analyzeTokens(phraseIn, endsWithSpace);
233 final List<Token> actual = graph.getOptions();
234
235 final List<Token> expected = new ArrayList<Token>();
236 expected.add(new Token(option2, true));
237 expected.add(new Token(option3, true));
238 expected.add(new Token(option4, true));
239 expected.add(new Token(option1, true));
240
241 Assert.assertEquals("Options for an empty command", expected,
242 actual);
243 }
244
245
246
247
248
249
250
251 @Test
252 public void testGetOptions0phrase() throws AbstractZemucanException {
253
254
255 final List<Token> phraseIn = new ArrayList<Token>();
256 final boolean endsWithSpace = false;
257 final GraphAnswer graph = ImplementationSyntacticAnalyzer.getInstance()
258 .analyzeTokens(phraseIn, endsWithSpace);
259 final List<Token> actual = graph.getPhrases();
260
261 final List<Token> expected = new ArrayList<Token>();
262
263 Assert.assertEquals("Phrases for an empty command", expected,
264 actual);
265 }
266
267
268
269
270
271
272
273 @Test
274 public void testGetOptions1() throws AbstractZemucanException {
275 final String tokenIn1 = ImplementationSyntacticAnalyzerTest.CREATE;
276
277 final String option1 = ImplementationSyntacticAnalyzerTest.TABLE;
278 final String option2 = ImplementationSyntacticAnalyzerTest.TABLESPACE;
279
280 final List<Token> phraseIn = new ArrayList<Token>();
281 phraseIn.add(new Token(tokenIn1, true));
282 final boolean endsWithSpace = false;
283 final GraphAnswer actual = ImplementationSyntacticAnalyzer
284 .getInstance().analyzeTokens(phraseIn, endsWithSpace);
285
286 final List<Token> phraseOut = new ArrayList<Token>();
287 final List<Token> options = new ArrayList<Token>();
288 options.add(new Token(option1, true));
289 options.add(new Token(option2, true));
290 final GraphAnswer expected = new GraphAnswer(phraseOut, options);
291
292 Assert.assertEquals("'create' command", expected, actual);
293 }
294
295
296
297
298
299
300
301 @Test
302 public void testGetOptions1options() throws AbstractZemucanException {
303 final String tokenIn1 = ImplementationSyntacticAnalyzerTest.CREATE;
304
305 final String option1 = ImplementationSyntacticAnalyzerTest.TABLE;
306 final String option2 = ImplementationSyntacticAnalyzerTest.TABLESPACE;
307
308 final List<Token> phraseIn = new ArrayList<Token>();
309 phraseIn.add(new Token(tokenIn1, true));
310 final boolean endsWithSpace = false;
311 final GraphAnswer graph = ImplementationSyntacticAnalyzer.getInstance()
312 .analyzeTokens(phraseIn, endsWithSpace);
313
314 final List<Token> actual = graph.getOptions();
315 final List<Token> expected = new ArrayList<Token>();
316 expected.add(new Token(option1, true));
317 expected.add(new Token(option2, true));
318
319 Assert.assertEquals("Options for 'create' command", expected,
320 actual);
321 }
322
323
324
325
326
327
328
329 @Test
330 public void testGetOptions1phrase() throws AbstractZemucanException {
331 final String tokenIn1 = ImplementationSyntacticAnalyzerTest.CREATE;
332
333 final List<Token> phraseIn = new ArrayList<Token>();
334 phraseIn.add(new Token(tokenIn1, true));
335 final boolean endsWithSpace = false;
336 final GraphAnswer graph = ImplementationSyntacticAnalyzer.getInstance()
337 .analyzeTokens(phraseIn, endsWithSpace);
338 final List<Token> actual = graph.getPhrases();
339
340 final List<Token> expected = new ArrayList<Token>();
341
342 Assert.assertEquals("Phrases for 'create' command", expected,
343 actual);
344 }
345
346
347
348
349
350
351
352 @Test
353 public void testGetOptions1WithSpace() throws AbstractZemucanException {
354 final String tokenIn1 = ImplementationSyntacticAnalyzerTest.CREATE;
355
356 final String option1 = ImplementationSyntacticAnalyzerTest.TABLE;
357 final String option2 = ImplementationSyntacticAnalyzerTest.TABLESPACE;
358
359 final List<Token> phraseIn = new ArrayList<Token>();
360 phraseIn.add(new Token(tokenIn1, true));
361 final boolean endsWithSpace = true;
362 final GraphAnswer actual = ImplementationSyntacticAnalyzer
363 .getInstance().analyzeTokens(phraseIn, endsWithSpace);
364
365 final List<Token> phraseOut = new ArrayList<Token>();
366 final List<Token> options = new ArrayList<Token>();
367 options.add(new Token(option1, true));
368 options.add(new Token(option2, true));
369 final GraphAnswer expected = new GraphAnswer(phraseOut, options);
370
371 Assert.assertEquals("'create ' command", expected, actual);
372 }
373
374
375
376
377
378
379
380 @Test
381 public void testGetOptions2() throws AbstractZemucanException {
382 final String tokenIn1 = ImplementationSyntacticAnalyzerTest.CREATE;
383 final String tokenIn2 = ImplementationSyntacticAnalyzerTest.TABLE;
384
385 final String tokenOut1 = ImplementationSyntacticAnalyzerTest.TABLESPACE;
386
387 final String option1 = ImplementationSyntacticAnalyzerTest.TABLE_NAME;
388
389 final List<Token> phraseIn = new ArrayList<Token>();
390 phraseIn.add(new Token(tokenIn1, true));
391 phraseIn.add(new Token(tokenIn2, true));
392 final boolean endsWithSpace = false;
393 final GraphAnswer actual = ImplementationSyntacticAnalyzer
394 .getInstance().analyzeTokens(phraseIn, endsWithSpace);
395
396 final List<Token> phraseOut = new ArrayList<Token>();
397 phraseOut.add(new Token(tokenOut1, true));
398 final List<Token> options = new ArrayList<Token>();
399 options.add(new Token(option1, true));
400 final GraphAnswer expected = new GraphAnswer(phraseOut, options);
401
402 Assert.assertEquals("'create table' command", expected, actual);
403 }
404
405
406
407
408
409
410
411 @Test
412 public void testGetOptions2options() throws AbstractZemucanException {
413 final String tokenIn1 = ImplementationSyntacticAnalyzerTest.CREATE;
414 final String tokenIn2 = ImplementationSyntacticAnalyzerTest.TABLE;
415
416 final String option1 = ImplementationSyntacticAnalyzerTest.TABLE_NAME;
417
418 final List<Token> phraseIn = new ArrayList<Token>();
419 phraseIn.add(new Token(tokenIn1, true));
420 phraseIn.add(new Token(tokenIn2, true));
421 final boolean endsWithSpace = false;
422 final GraphAnswer graph = ImplementationSyntacticAnalyzer.getInstance()
423 .analyzeTokens(phraseIn, endsWithSpace);
424 final List<Token> actual = graph.getOptions();
425
426 final List<Token> expected = new ArrayList<Token>();
427 expected.add(new Token(option1, true));
428
429 Assert.assertEquals("Options for 'create table' command",
430 expected, actual);
431 }
432
433
434
435
436
437
438
439 @Test
440 public void testGetOptions2phrase() throws AbstractZemucanException {
441 final String tokenIn1 = ImplementationSyntacticAnalyzerTest.CREATE;
442 final String tokenIn2 = ImplementationSyntacticAnalyzerTest.TABLE;
443
444 final String tokenOut1 = ImplementationSyntacticAnalyzerTest.TABLESPACE;
445
446 final List<Token> phraseIn = new ArrayList<Token>();
447 phraseIn.add(new Token(tokenIn1, true));
448 phraseIn.add(new Token(tokenIn2, true));
449 final boolean endsWithSpace = false;
450 final GraphAnswer graph = ImplementationSyntacticAnalyzer.getInstance()
451 .analyzeTokens(phraseIn, endsWithSpace);
452 final List<Token> actual = graph.getPhrases();
453
454 final List<Token> expected = new ArrayList<Token>();
455 expected.add(new Token(tokenOut1, true));
456
457 Assert.assertEquals("Phrases for 'create table' command",
458 expected, actual);
459 }
460
461
462
463
464
465
466
467 @Test
468 public void testGetOptions2WithSpace() throws AbstractZemucanException {
469 final String tokenIn1 = ImplementationSyntacticAnalyzerTest.CREATE;
470 final String tokenIn2 = ImplementationSyntacticAnalyzerTest.TABLE;
471
472 final String option1 = ImplementationSyntacticAnalyzerTest.TABLE_NAME;
473
474 final List<Token> phraseIn = new ArrayList<Token>();
475 phraseIn.add(new Token(tokenIn1, true));
476 phraseIn.add(new Token(tokenIn2, true));
477 final boolean endsWithSpace = true;
478 final GraphAnswer actual = ImplementationSyntacticAnalyzer
479 .getInstance().analyzeTokens(phraseIn, endsWithSpace);
480
481 final List<Token> phraseOut = new ArrayList<Token>();
482 final List<Token> options = new ArrayList<Token>();
483 options.add(new Token(option1, true));
484 final GraphAnswer expected = new GraphAnswer(phraseOut, options);
485
486 Assert.assertEquals("'create table ' command", expected, actual);
487 }
488
489
490
491
492
493
494
495 @Test
496 public void testGetOptions3() throws AbstractZemucanException {
497 final String tokenIn1 = ImplementationSyntacticAnalyzerTest.CREATE;
498 final String tokenIn2 = ImplementationSyntacticAnalyzerTest.TABLE;
499 final String tokenIn3 = ImplementationSyntacticAnalyzerTest.T1;
500
501 final String option1 = ImplementationSyntacticAnalyzerTest.OPEN_PARENTHESIS;
502
503 final List<Token> phraseIn = new ArrayList<Token>();
504 phraseIn.add(new Token(tokenIn1, true));
505 phraseIn.add(new Token(tokenIn2, true));
506 phraseIn.add(new Token(tokenIn3, true));
507 final boolean endsWithSpace = false;
508 final GraphAnswer actual = ImplementationSyntacticAnalyzer
509 .getInstance().analyzeTokens(phraseIn, endsWithSpace);
510
511 final List<Token> phraseOut = new ArrayList<Token>();
512 final List<Token> options = new ArrayList<Token>();
513 options.add(new Token(option1, true));
514 final GraphAnswer expected = new GraphAnswer(phraseOut, options);
515
516 Assert.assertEquals("'create table t1' command", expected,
517 actual);
518 }
519
520
521
522
523
524
525
526 @Test
527 public void testGetOptions3options() throws AbstractZemucanException {
528 final String tokenIn1 = ImplementationSyntacticAnalyzerTest.CREATE;
529 final String tokenIn2 = ImplementationSyntacticAnalyzerTest.TABLE;
530 final String tokenIn3 = ImplementationSyntacticAnalyzerTest.T1;
531
532 final String option1 = ImplementationSyntacticAnalyzerTest.OPEN_PARENTHESIS;
533
534 final List<Token> phraseIn = new ArrayList<Token>();
535 phraseIn.add(new Token(tokenIn1, true));
536 phraseIn.add(new Token(tokenIn2, true));
537 phraseIn.add(new Token(tokenIn3, true));
538 final boolean endsWithSpace = false;
539 final GraphAnswer graph = ImplementationSyntacticAnalyzer.getInstance()
540 .analyzeTokens(phraseIn, endsWithSpace);
541 final List<Token> actual = graph.getOptions();
542
543 final List<Token> expected = new ArrayList<Token>();
544 expected.add(new Token(option1, true));
545
546 Assert.assertEquals("Options for 'create table t1' command",
547 expected, actual);
548 }
549
550
551
552
553
554
555
556 @Test
557 public void testGetOptions3phrase() throws AbstractZemucanException {
558 final String tokenIn1 = ImplementationSyntacticAnalyzerTest.CREATE;
559 final String tokenIn2 = ImplementationSyntacticAnalyzerTest.TABLE;
560 final String tokenIn3 = ImplementationSyntacticAnalyzerTest.T1;
561
562 final List<Token> phraseIn = new ArrayList<Token>();
563 phraseIn.add(new Token(tokenIn1, true));
564 phraseIn.add(new Token(tokenIn2, true));
565 phraseIn.add(new Token(tokenIn3, true));
566 final boolean endsWithSpace = false;
567 final GraphAnswer graph = ImplementationSyntacticAnalyzer.getInstance()
568 .analyzeTokens(phraseIn, endsWithSpace);
569 final List<Token> actual = graph.getPhrases();
570
571 final List<Token> expected = new ArrayList<Token>();
572
573 Assert.assertEquals("Phrase for 'create table t1' command",
574 expected, actual);
575 }
576
577
578
579
580
581
582
583 @Test
584 public void testGetOptions4() throws AbstractZemucanException {
585 final String tokenIn1 = ImplementationSyntacticAnalyzerTest.CREATE;
586 final String tokenIn2 = ImplementationSyntacticAnalyzerTest.TABLE;
587 final String tokenIn3 = ImplementationSyntacticAnalyzerTest.T1;
588 final String tokenIn4 = ImplementationSyntacticAnalyzerTest.OPEN_PARENTHESIS;
589
590 final String option1 = ImplementationSyntacticAnalyzerTest.COL_NAME;
591
592 final List<Token> phraseIn = new ArrayList<Token>();
593 phraseIn.add(new Token(tokenIn1, true));
594 phraseIn.add(new Token(tokenIn2, true));
595 phraseIn.add(new Token(tokenIn3, true));
596 phraseIn.add(new Token(tokenIn4, true));
597 final boolean endsWithSpace = false;
598 final GraphAnswer actual = ImplementationSyntacticAnalyzer
599 .getInstance().analyzeTokens(phraseIn, endsWithSpace);
600
601 final List<Token> phraseOut = new ArrayList<Token>();
602 final List<Token> options = new ArrayList<Token>();
603 options.add(new Token(option1, true));
604 final GraphAnswer expected = new GraphAnswer(phraseOut, options);
605
606 Assert.assertEquals("Phrases for 'create table t1' command",
607 expected, actual);
608 }
609
610
611
612
613
614
615
616
617 @Test
618 public void testGetOptions4options() throws AbstractZemucanException {
619 final String tokenIn1 = ImplementationSyntacticAnalyzerTest.CREATE;
620 final String tokenIn2 = ImplementationSyntacticAnalyzerTest.TABLE;
621 final String tokenIn3 = ImplementationSyntacticAnalyzerTest.T1;
622 final String tokenIn4 = ImplementationSyntacticAnalyzerTest.OPEN_PARENTHESIS;
623
624 final String option1 = ImplementationSyntacticAnalyzerTest.COL_NAME;
625
626 final List<Token> phraseIn = new ArrayList<Token>();
627 phraseIn.add(new Token(tokenIn1, true));
628 phraseIn.add(new Token(tokenIn2, true));
629 phraseIn.add(new Token(tokenIn3, true));
630 phraseIn.add(new Token(tokenIn4, true));
631 final boolean endsWithSpace = false;
632 final GraphAnswer graph = ImplementationSyntacticAnalyzer.getInstance()
633 .analyzeTokens(phraseIn, endsWithSpace);
634 final List<Token> actual = graph.getOptions();
635
636 final List<Token> expected = new ArrayList<Token>();
637 expected.add(new Token(option1, true));
638
639 Assert.assertEquals("Options for 'create table t1 (' command",
640 expected, actual);
641 }
642
643
644
645
646
647
648
649 @Test
650 public void testGetOptions4phrase() throws AbstractZemucanException {
651 final String tokenIn1 = ImplementationSyntacticAnalyzerTest.CREATE;
652 final String tokenIn2 = ImplementationSyntacticAnalyzerTest.TABLE;
653 final String tokenIn3 = ImplementationSyntacticAnalyzerTest.T1;
654 final String tokenIn4 = ImplementationSyntacticAnalyzerTest.OPEN_PARENTHESIS;
655
656 final List<Token> phraseIn = new ArrayList<Token>();
657 phraseIn.add(new Token(tokenIn1, true));
658 phraseIn.add(new Token(tokenIn2, true));
659 phraseIn.add(new Token(tokenIn3, true));
660 phraseIn.add(new Token(tokenIn4, true));
661 final boolean endsWithSpace = false;
662 final GraphAnswer graph = ImplementationSyntacticAnalyzer.getInstance()
663 .analyzeTokens(phraseIn, endsWithSpace);
664 final List<Token> actual = graph.getPhrases();
665
666 final List<Token> expected = new ArrayList<Token>();
667
668 Assert.assertEquals("Phrase for 'create table t1 (' command",
669 expected, actual);
670 }
671
672
673
674
675
676
677
678
679 @Test
680 public void testGetOptions5() throws AbstractZemucanException {
681 final String tokenIn1 = ImplementationSyntacticAnalyzerTest.CREATE;
682 final String tokenIn2 = ImplementationSyntacticAnalyzerTest.TABLE;
683 final String tokenIn3 = ImplementationSyntacticAnalyzerTest.T1;
684 final String tokenIn4 = ImplementationSyntacticAnalyzerTest.OPEN_PARENTHESIS;
685 final String tokenIn5 = ImplementationSyntacticAnalyzerTest.C1;
686 final String tokenIn6 = ImplementationSyntacticAnalyzerTest.INT;
687 final String tokenIn7 = ImplementationSyntacticAnalyzerTest.CLOSE_PARENTHESIS;
688
689 final List<Token> phraseIn = new ArrayList<Token>();
690 phraseIn.add(new Token(tokenIn1, true));
691 phraseIn.add(new Token(tokenIn2, true));
692 phraseIn.add(new Token(tokenIn3, true));
693 phraseIn.add(new Token(tokenIn4, true));
694 phraseIn.add(new Token(tokenIn5, true));
695 phraseIn.add(new Token(tokenIn6, true));
696 phraseIn.add(new Token(tokenIn7, true));
697 final boolean endsWithSpace = false;
698 final GraphAnswer actual = ImplementationSyntacticAnalyzer
699 .getInstance().analyzeTokens(phraseIn, endsWithSpace);
700
701 final List<Token> phraseOut = new ArrayList<Token>();
702 final List<Token> options = new ArrayList<Token>();
703 final GraphAnswer expected = new GraphAnswer(phraseOut, options);
704
705 Assert.assertEquals("'create table t1 (c1 int)' command",
706 expected, actual);
707 }
708
709
710
711
712
713
714
715 @Test
716 public void testGetOptions6() throws AbstractZemucanException {
717 final String tokenIn1 = ImplementationSyntacticAnalyzerTest.CREATE;
718 final String tokenIn2 = ImplementationSyntacticAnalyzerTest.TABLE;
719 final String tokenIn3 = ImplementationSyntacticAnalyzerTest.T1;
720 final String tokenIn4 = ImplementationSyntacticAnalyzerTest.OPEN_PARENTHESIS;
721 final String tokenIn5 = ImplementationSyntacticAnalyzerTest.C1;
722 final String tokenIn6 = ImplementationSyntacticAnalyzerTest.INT;
723 final String tokenIn7 = ImplementationSyntacticAnalyzerTest.CLOSE_PARENTHESIS;
724 final String tokenIn8 = "in";
725 final String tokenIn9 = "ts1";
726
727 final List<Token> phraseIn = new ArrayList<Token>();
728
729 phraseIn.add(new Token(tokenIn1, true));
730 phraseIn.add(new Token(tokenIn2, true));
731 phraseIn.add(new Token(tokenIn3, true));
732 phraseIn.add(new Token(tokenIn4, true));
733 phraseIn.add(new Token(tokenIn5, true));
734 phraseIn.add(new Token(tokenIn6, true));
735 phraseIn.add(new Token(tokenIn7, true));
736 phraseIn.add(new Token(tokenIn8, true));
737 phraseIn.add(new Token(tokenIn9, true));
738 final boolean endsWithSpace = false;
739 final GraphAnswer actual = ImplementationSyntacticAnalyzer
740 .getInstance().analyzeTokens(phraseIn, endsWithSpace);
741
742 final List<Token> phraseOut = new ArrayList<Token>();
743 final List<Token> options = new ArrayList<Token>();
744 final GraphAnswer expected = new GraphAnswer(phraseOut, options);
745
746 Assert.assertEquals("'create table t1 (c1 int) in ts1' command",
747 expected, actual);
748 }
749
750
751
752
753
754
755
756 @Test
757 public void testGetOptions7() throws AbstractZemucanException {
758 final String tokenIn1 = ImplementationSyntacticAnalyzerTest.CREATE;
759 final String tokenIn2 = ImplementationSyntacticAnalyzerTest.TABLE;
760 final String tokenIn3 = ImplementationSyntacticAnalyzerTest.T1;
761 final String tokenIn4 = ImplementationSyntacticAnalyzerTest.OPEN_PARENTHESIS;
762 final String tokenIn5 = ImplementationSyntacticAnalyzerTest.C1;
763 final String tokenIn6 = ImplementationSyntacticAnalyzerTest.INT;
764 final String tokenIn7 = ImplementationSyntacticAnalyzerTest.CLOSE_PARENTHESIS;
765 final String tokenIn8 = "in";
766
767 final List<Token> phraseIn = new ArrayList<Token>();
768
769 phraseIn.add(new Token(tokenIn1, true));
770 phraseIn.add(new Token(tokenIn2, true));
771 phraseIn.add(new Token(tokenIn3, true));
772 phraseIn.add(new Token(tokenIn4, true));
773 phraseIn.add(new Token(tokenIn5, true));
774 phraseIn.add(new Token(tokenIn6, true));
775 phraseIn.add(new Token(tokenIn7, true));
776 phraseIn.add(new Token(tokenIn8, true));
777 final boolean endsWithSpace = false;
778 final GraphAnswer actual = ImplementationSyntacticAnalyzer
779 .getInstance().analyzeTokens(phraseIn, endsWithSpace);
780
781 final List<Token> phraseOut = new ArrayList<Token>();
782 final List<Token> options = new ArrayList<Token>();
783 final GraphAnswer expected = new GraphAnswer(phraseOut, options);
784
785 Assert.assertEquals("'create table t1 (c1 int) in' command",
786 expected, actual);
787 }
788
789
790
791
792
793
794
795 @Test
796 public void testGetOptions8() throws AbstractZemucanException {
797 final String tokenIn1 = ImplementationSyntacticAnalyzerTest.CREATE;
798 final String tokenIn2 = "tab";
799
800 final String tokenOut1 = ImplementationSyntacticAnalyzerTest.TABLE;
801 final String tokenOut2 = ImplementationSyntacticAnalyzerTest.TABLESPACE;
802
803 final List<Token> phraseIn = new ArrayList<Token>();
804 phraseIn.add(new Token(tokenIn1, true));
805 phraseIn.add(new Token(tokenIn2, true));
806 final boolean endsWithSpace = false;
807 final GraphAnswer actual = ImplementationSyntacticAnalyzer
808 .getInstance().analyzeTokens(phraseIn, endsWithSpace);
809
810 final List<Token> phraseOut = new ArrayList<Token>();
811 phraseOut.add(new Token(tokenOut1, true));
812 phraseOut.add(new Token(tokenOut2, true));
813 final List<Token> options = new ArrayList<Token>();
814 final GraphAnswer expected = new GraphAnswer(phraseOut, options);
815
816 Assert.assertEquals("'create tab' command", expected, actual);
817 }
818
819
820
821
822
823
824
825 @Test
826 public void testInvalidFirstToken() throws AbstractZemucanException {
827 final String tokenIn1 = ImplementationSyntacticAnalyzerTest.TOTO;
828
829 final List<Token> phraseIn = new ArrayList<Token>();
830 phraseIn.add(new Token(tokenIn1, true));
831 final boolean endsWithSpace = false;
832 final GraphAnswer actual = ImplementationSyntacticAnalyzer
833 .getInstance().analyzeTokens(phraseIn, endsWithSpace);
834
835 final List<Token> phraseOut = new ArrayList<Token>();
836 final List<Token> options = new ArrayList<Token>();
837 final GraphAnswer expected = new GraphAnswer(phraseOut, options);
838
839 Assert.assertEquals("'toto' phrase", expected, actual);
840 }
841
842
843
844
845
846
847
848 @Test
849 public void testInvalidSecondToken() throws AbstractZemucanException {
850 final String tokenIn1 = ImplementationSyntacticAnalyzerTest.CREATE;
851 final String tokenIn2 = ImplementationSyntacticAnalyzerTest.TOTO;
852
853 final List<Token> phraseIn = new ArrayList<Token>();
854 phraseIn.add(new Token(tokenIn1, true));
855 phraseIn.add(new Token(tokenIn2, true));
856 final boolean endsWithSpace = false;
857 final GraphAnswer actual = ImplementationSyntacticAnalyzer
858 .getInstance().analyzeTokens(phraseIn, endsWithSpace);
859
860 final List<Token> phraseOut = new ArrayList<Token>();
861 final List<Token> options = new ArrayList<Token>();
862 final GraphAnswer expected = new GraphAnswer(phraseOut, options);
863
864 Assert.assertEquals("'create toto' phrase", expected, actual);
865 }
866
867
868
869
870
871
872
873 @Test(expected = AssertionError.class)
874 public void testNullGetOption() throws AbstractZemucanException {
875 ImplementationSyntacticAnalyzer.getInstance()
876 .analyzeTokens(null, false);
877 }
878
879
880
881
882
883
884
885 @Test(expected = AssertionError.class)
886 public void testNullTokenGetOption() throws AbstractZemucanException {
887 final List<Token> phraseIn = new ArrayList<Token>();
888 phraseIn.add(null);
889
890 ImplementationSyntacticAnalyzer.getInstance().analyzeTokens(phraseIn,
891 false);
892 }
893 }