KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > tests > jfun > parsec > ColoringTestCase


1 /*
2  * Created on Dec 7, 2004
3  *
4  * Author Ben Yu
5  */

6 package tests.jfun.parsec;
7
8 import java.io.FileReader JavaDoc;
9 import java.io.FileWriter JavaDoc;
10 import java.io.IOException JavaDoc;
11
12 import tests.jfun.parsec.coloring.Java2Html;
13 import tests.jfun.utils.Utils;
14
15 import junit.framework.TestCase;
16 import junit.framework.TestSuite;
17 /**
18  * @author Ben Yu
19  *
20  * Dec 7, 2004
21  */

22 public final class ColoringTestCase extends TestCase {
23   public static void main(String JavaDoc[] args){
24     new java.io.File JavaDoc("test/output").mkdirs();
25     junit.textui.TestRunner.run(suite());
26   }
27   private static TestSuite suite(){
28     return new TestSuite(ColoringTestCase.class);
29   }
30   public void test1(){
31     color("test/src/tests/jfun/parsec/ColoringTestCase.java", "test/output/TestColoring.html");
32   }
33   public void test2(){
34     color("src/jfun/parsec/Parsers.java", "test/output/Parsers.html");
35   }
36   public void test3(){
37     color("src/jfun/parsec/Parser.java", "test/output/Parser.html");
38   }
39   public void test4(){
40     color("src/jfun/parsec/pattern/Patterns.java", "test/output/Patterns.html");
41   }
42   public void test5(){
43     color("src/jfun/parsec/Expressions.java", "test/output/Expressions.html");
44   }
45   public void test6(){
46     color("src/jfun/parsec/Terms.java", "test/output/Terms.html");
47   }
48   private static void _testChinese(){
49     final String JavaDoc s1 = "??" + 1l + 2L + 3e5 + 0.e3 + 1.1e-3 + 0x1EE01
50       + 078.54 + 0x3fe6 + 0x5e7;
51     //final int ?? = 0;
52
final String JavaDoc s2 = "abc\u0011\"yes";
53   }
54   private static void color(final String JavaDoc in, final String JavaDoc out){
55     final CharSequence JavaDoc src = readFile(in);
56     final String JavaDoc result = Java2Html.toHtml(src,
57         "blue", "gray", "gray", "gray", "yellow", "green", "red", "black");
58     writeFile(out, result);
59   }
60
61   private static CharSequence JavaDoc readFile(final String JavaDoc name){
62     return Utils.readFile(name);
63   }
64   private static void writeFile(final String JavaDoc name, final String JavaDoc s){
65     try{
66       final FileWriter JavaDoc fw = new FileWriter JavaDoc(name);
67       try{
68         fw.write(s);
69       }
70       finally{
71         fw.close();
72       }
73     }
74     catch(IOException JavaDoc e){
75       throw new IllegalStateException JavaDoc(e.getMessage());
76     }
77   }
78 }
79
Popular Tags