1 6 package tests.jfun.parsec; 7 8 import java.io.FileReader ; 9 import java.io.FileWriter ; 10 import java.io.IOException ; 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 22 public final class ColoringTestCase extends TestCase { 23 public static void main(String [] args){ 24 new java.io.File ("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 s1 = "??" + 1l + 2L + 3e5 + 0.e3 + 1.1e-3 + 0x1EE01 50 + 078.54 + 0x3fe6 + 0x5e7; 51 final String s2 = "abc\u0011\"yes"; 53 } 54 private static void color(final String in, final String out){ 55 final CharSequence src = readFile(in); 56 final String result = Java2Html.toHtml(src, 57 "blue", "gray", "gray", "gray", "yellow", "green", "red", "black"); 58 writeFile(out, result); 59 } 60 61 private static CharSequence readFile(final String name){ 62 return Utils.readFile(name); 63 } 64 private static void writeFile(final String name, final String s){ 65 try{ 66 final FileWriter fw = new FileWriter (name); 67 try{ 68 fw.write(s); 69 } 70 finally{ 71 fw.close(); 72 } 73 } 74 catch(IOException e){ 75 throw new IllegalStateException (e.getMessage()); 76 } 77 } 78 } 79 | Popular Tags |