1 | /* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
|
---|
2 | * JFlex 1.4.3 *
|
---|
3 | * Copyright (C) 1998-2009 Gerwin Klein <[email protected]> *
|
---|
4 | * All rights reserved. *
|
---|
5 | * *
|
---|
6 | * This program is free software; you can redistribute it and/or modify *
|
---|
7 | * it under the terms of the GNU General Public License. See the file *
|
---|
8 | * COPYRIGHT for more information. *
|
---|
9 | * *
|
---|
10 | * This program is distributed in the hope that it will be useful, *
|
---|
11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of *
|
---|
12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
|
---|
13 | * GNU General Public License for more details. *
|
---|
14 | * *
|
---|
15 | * You should have received a copy of the GNU General Public License along *
|
---|
16 | * with this program; if not, write to the Free Software Foundation, Inc., *
|
---|
17 | * 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA *
|
---|
18 | * *
|
---|
19 | * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
|
---|
20 | package JFlex.tests;
|
---|
21 |
|
---|
22 | import java.io.File;
|
---|
23 | import java.io.IOException;
|
---|
24 |
|
---|
25 | import JFlex.Options;
|
---|
26 | import JFlex.anttask.JFlexTask;
|
---|
27 |
|
---|
28 | import junit.framework.TestCase;
|
---|
29 |
|
---|
30 | /**
|
---|
31 | * Unit tests for the jflex ant task.
|
---|
32 | *
|
---|
33 | * @author Gerwin Klein
|
---|
34 | * @version $Revision: 433 $, $Date: 2009-01-31 19:52:34 +1100 (Sat, 31 Jan 2009) $
|
---|
35 | */
|
---|
36 | public class AntTaskTests extends TestCase {
|
---|
37 |
|
---|
38 | private JFlexTask task;
|
---|
39 |
|
---|
40 | /**
|
---|
41 | * Constructor for AntTaskTests.
|
---|
42 | *
|
---|
43 | * @param name test case name
|
---|
44 | */
|
---|
45 | public AntTaskTests(String name) {
|
---|
46 | super(name);
|
---|
47 | }
|
---|
48 |
|
---|
49 | /*
|
---|
50 | * @see TestCase#setUp()
|
---|
51 | */
|
---|
52 | protected void setUp() throws Exception {
|
---|
53 | super.setUp();
|
---|
54 | Options.setDefaults();
|
---|
55 | task = new JFlexTask();
|
---|
56 | }
|
---|
57 |
|
---|
58 | public void testPackageAndClass() throws IOException {
|
---|
59 | task.setFile(new File("src/JFlex/LexScan.flex"));
|
---|
60 | task.findPackageAndClass();
|
---|
61 | assertEquals(task.getPackage(), "JFlex");
|
---|
62 | assertEquals(task.getClassName(), "LexScan");
|
---|
63 | }
|
---|
64 |
|
---|
65 | public void testPackageAndClassDefaults() throws IOException {
|
---|
66 | task.setFile(new File("examples/simple/simple.flex"));
|
---|
67 | task.findPackageAndClass();
|
---|
68 | assertEquals(task.getPackage(), null);
|
---|
69 | assertEquals(task.getClassName(), "Yylex");
|
---|
70 | }
|
---|
71 |
|
---|
72 | public void testDestdir() throws IOException {
|
---|
73 | task.setFile(new File("src/JFlex/LexScan.flex"));
|
---|
74 | File dir = new File("src");
|
---|
75 | task.setDestdir(dir);
|
---|
76 | task.findPackageAndClass();
|
---|
77 | task.normalizeOutdir();
|
---|
78 | // not default jflex logic, but javac (uses package name)
|
---|
79 | assertEquals(Options.getDir(), new File(dir, "JFlex"));
|
---|
80 | }
|
---|
81 |
|
---|
82 | public void testOutdir() throws IOException {
|
---|
83 | task.setFile(new File("src/JFlex/LexScan.flex"));
|
---|
84 | File dir = new File("src");
|
---|
85 | task.setOutdir(dir);
|
---|
86 | task.findPackageAndClass();
|
---|
87 | task.normalizeOutdir();
|
---|
88 | // this should be default jflex logic
|
---|
89 | assertEquals(Options.getDir(), dir);
|
---|
90 | }
|
---|
91 |
|
---|
92 | public void testDefaultDir() throws IOException {
|
---|
93 | task.setFile(new File("src/JFlex/LexScan.flex"));
|
---|
94 | task.findPackageAndClass();
|
---|
95 | task.normalizeOutdir();
|
---|
96 | // this should be default jflex logic
|
---|
97 | assertEquals(Options.getDir(), new File("src/JFlex"));
|
---|
98 | }
|
---|
99 |
|
---|
100 | public void testNomin() {
|
---|
101 | assertTrue(!Options.no_minimize);
|
---|
102 | task.setNomin(true);
|
---|
103 | assertTrue(Options.no_minimize);
|
---|
104 | }
|
---|
105 |
|
---|
106 | public void testSkipMinimization() {
|
---|
107 | assertTrue(!Options.no_minimize);
|
---|
108 | task.setSkipMinimization(true);
|
---|
109 | assertTrue(Options.no_minimize);
|
---|
110 | }
|
---|
111 |
|
---|
112 | public void testNobak() {
|
---|
113 | assertTrue(!Options.no_backup);
|
---|
114 | task.setNobak(true);
|
---|
115 | assertTrue(Options.no_backup);
|
---|
116 | }
|
---|
117 |
|
---|
118 | public void testCodeGen() {
|
---|
119 | task.setSwitch(true);
|
---|
120 | assertEquals(Options.gen_method, Options.SWITCH);
|
---|
121 | task.setTable(true);
|
---|
122 | assertEquals(Options.gen_method, Options.TABLE);
|
---|
123 | task.setPack(true);
|
---|
124 | assertEquals(Options.gen_method, Options.PACK);
|
---|
125 | }
|
---|
126 |
|
---|
127 | public void testSkel() {
|
---|
128 | task.setVerbose(false); // avoid to java console pop up
|
---|
129 | task.setSkeleton(new File("src/skeleton.nested"));
|
---|
130 | assertTrue(JFlex.Skeleton.line[3].indexOf("java.util.Stack") > 0);
|
---|
131 | }
|
---|
132 |
|
---|
133 | public void testVerbose() {
|
---|
134 | task.setVerbose(false);
|
---|
135 | assertTrue(!Options.verbose);
|
---|
136 | task.setVerbose(true);
|
---|
137 | assertTrue(Options.verbose);
|
---|
138 | }
|
---|
139 |
|
---|
140 | public void testTime() {
|
---|
141 | assertTrue(!Options.time);
|
---|
142 | task.setTimeStatistics(true);
|
---|
143 | assertTrue(Options.time);
|
---|
144 | task.setTime(false);
|
---|
145 | assertTrue(!Options.time);
|
---|
146 | }
|
---|
147 |
|
---|
148 | public void testDot() {
|
---|
149 | assertTrue(!Options.dot);
|
---|
150 | task.setDot(true);
|
---|
151 | assertTrue(Options.dot);
|
---|
152 | task.setGenerateDot(false);
|
---|
153 | assertTrue(!Options.dot);
|
---|
154 | }
|
---|
155 |
|
---|
156 | public void testDump() {
|
---|
157 | assertTrue(!Options.dump);
|
---|
158 | task.setDump(true);
|
---|
159 | assertTrue(Options.dump);
|
---|
160 | }
|
---|
161 |
|
---|
162 | public void testJlex() {
|
---|
163 | assertTrue(!Options.jlex);
|
---|
164 | task.setJLex(true);
|
---|
165 | assertTrue(Options.jlex);
|
---|
166 | }
|
---|
167 | }
|
---|