1 19 20 package org.netbeans.editor.ext.html; 21 22 import java.io.File ; 23 import junit.framework.*; 24 import org.netbeans.editor.BaseDocument; 25 import org.netbeans.editor.ext.html.test.TestBase; 26 import org.netbeans.modules.editor.html.HTMLKit; 27 28 32 public class HTMLFormatterTest extends TestBase { 33 36 public final static String LINE_BREAK_METATAG = "|"; 37 38 public HTMLFormatterTest(String testName) { 39 super(testName); 40 } 41 42 public static Test suite() { 43 TestSuite suite = new TestSuite(HTMLFormatterTest.class); 44 45 return suite; 46 } 47 48 public void testReformatSample1(){ 49 testReformat("netbeans_front_page.html"); 50 } 51 52 public void testReformatSample2(){ 53 testReformat("java_sun_com.html"); 54 } 55 61 62 private String extractCRMetatag(String text){ 63 int indexOfMetatag = text.indexOf(LINE_BREAK_METATAG); 64 65 if (indexOfMetatag == -1){ 66 return text; 67 } 68 69 String firstPart = text.substring(0, indexOfMetatag); 70 String secondPart = text.substring(indexOfMetatag + LINE_BREAK_METATAG.length()); 71 72 if (secondPart.indexOf(LINE_BREAK_METATAG) > -1){ 73 throw new IllegalArgumentException ("text contains more than one line break tag"); 74 } 75 76 return firstPart + secondPart; 77 } 78 79 private void testReformat(String testFileName) { 80 System.out.println("testReformat(" + testFileName + ")"); 81 HTMLFormatter formatter = new HTMLFormatter(HTMLKit.class); 82 BaseDocument doc = createDocument(); 83 84 try{ 85 String txtRawHTML = Utils.readFileContentToString(new File (new File ( 86 getTestFilesDir(), "testReformat"), testFileName)); 87 88 doc.insertString(0, txtRawHTML, null); 89 formatter.reformat(doc, 0, doc.getLength(), false); 90 getRef().print(doc.getText(0, doc.getLength())); 91 } 92 catch (Exception e){ 93 fail(e.getMessage()); } 95 96 compareReferenceFiles(); 97 } 98 99 100 private File getTestFilesDir(){ 101 return new File (new File (getDataDir(), "input"), "HTMLFormatterTest"); 102 } 103 104 } 105 | Popular Tags |