1 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 36 public class AntTaskTests extends TestCase { 37 38 private JFlexTask task; 39 40 45 public AntTaskTests(String name) { 46 super(name); 47 } 48 49 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 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 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 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); 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 } 168 | Popular Tags |