KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > javacc > parser > OptionsTest


1 package org.javacc.parser;
2
3 import java.io.File JavaDoc;
4
5 import junit.framework.TestCase;
6
7 /**
8  * Test cases to prod at the valitity of Options a little.
9  *
10  * @author Kees Jan Koster <kjkoster@kjkoster.org>
11  */

12 public final class OptionsTest extends TestCase {
13     public void testDefaults() {
14         Options.init();
15         JavaCCErrors.reInit();
16
17         assertEquals(23, Options.optionValues.size());
18
19         assertEquals(true, Options.getBuildParser());
20         assertEquals(true, Options.getBuildTokenManager());
21         assertEquals(false, Options.getCacheTokens());
22         assertEquals(false, Options.getCommonTokenAction());
23         assertEquals(false, Options.getDebugLookahead());
24         assertEquals(false, Options.getDebugParser());
25         assertEquals(false, Options.getDebugTokenManager());
26         assertEquals(true, Options.getErrorReporting());
27         assertEquals(false, Options.getForceLaCheck());
28         assertEquals(false, Options.getIgnoreCase());
29         assertEquals(false, Options.getJavaUnicodeEscape());
30         assertEquals(true, Options.getKeepLineColumn());
31         assertEquals(true, Options.getSanityCheck());
32         assertEquals(true, Options.getStatic());
33         assertEquals(false, Options.getUnicodeInput());
34         assertEquals(false, Options.getUserCharStream());
35         assertEquals(false, Options.getUserTokenManager());
36         assertEquals(false, Options.getTokenManagerUsesParser());
37
38         assertEquals(2, Options.getChoiceAmbiguityCheck());
39         assertEquals(1, Options.getLookahead());
40         assertEquals(1, Options.getOtherAmbiguityCheck());
41
42         assertEquals("1.4", Options.getJdkVersion());
43
44         assertEquals(new File JavaDoc("."), Options.getOutputDirectory());
45
46         assertEquals(0, JavaCCErrors.get_warning_count());
47         assertEquals(0, JavaCCErrors.get_error_count());
48         assertEquals(0, JavaCCErrors.get_parse_error_count());
49         assertEquals(0, JavaCCErrors.get_semantic_error_count());
50     }
51
52     public void testSetBooleanOption() {
53         Options.init();
54         JavaCCErrors.reInit();
55
56         assertEquals(true, Options.getStatic());
57         Options.setCmdLineOption("-NOSTATIC");
58         assertEquals(false, Options.getStatic());
59
60         assertEquals(false, Options.getJavaUnicodeEscape());
61         Options.setCmdLineOption("-JAVA_UNICODE_ESCAPE:true");
62         assertEquals(true, Options.getJavaUnicodeEscape());
63
64         assertEquals(true, Options.getSanityCheck());
65         Options.setCmdLineOption("-SANITY_CHECK=false");
66         assertEquals(false, Options.getSanityCheck());
67
68         assertEquals(0, JavaCCErrors.get_warning_count());
69         assertEquals(0, JavaCCErrors.get_error_count());
70         assertEquals(0, JavaCCErrors.get_parse_error_count());
71         assertEquals(0, JavaCCErrors.get_semantic_error_count());
72     }
73
74     public void testSetNonexistentOption() {
75         Options.init();
76         JavaCCErrors.reInit();
77
78         assertEquals(0, JavaCCErrors.get_warning_count());
79         Options.setInputFileOption(null, null, "OPTION", true);
80         assertEquals(1, JavaCCErrors.get_warning_count());
81
82         assertEquals(0, JavaCCErrors.get_error_count());
83         assertEquals(0, JavaCCErrors.get_parse_error_count());
84         assertEquals(0, JavaCCErrors.get_semantic_error_count());
85     }
86
87     public void testSetWrongTypeForOption() {
88         Options.init();
89         JavaCCErrors.reInit();
90
91         assertEquals(0, JavaCCErrors.get_warning_count());
92         assertEquals(0, JavaCCErrors.get_error_count());
93         Options.setInputFileOption(null, null, "STATIC", 8);
94         assertEquals(1, JavaCCErrors.get_warning_count());
95
96         assertEquals(0, JavaCCErrors.get_error_count());
97         assertEquals(0, JavaCCErrors.get_parse_error_count());
98         assertEquals(0, JavaCCErrors.get_semantic_error_count());
99     }
100
101     public void testNormalize() {
102         Options.init();
103         JavaCCErrors.reInit();
104
105         assertEquals(false, Options.getDebugLookahead());
106         assertEquals(false, Options.getDebugParser());
107
108         Options.setCmdLineOption("-DEBUG_LOOKAHEAD=TRUE");
109         Options.normalize();
110
111         assertEquals(true, Options.getDebugLookahead());
112         assertEquals(true, Options.getDebugParser());
113
114         assertEquals(0, JavaCCErrors.get_warning_count());
115         assertEquals(0, JavaCCErrors.get_error_count());
116         assertEquals(0, JavaCCErrors.get_parse_error_count());
117         assertEquals(0, JavaCCErrors.get_semantic_error_count());
118     }
119 }
Popular Tags