1 19 20 package org.netbeans.editor.ext.html; 21 22 import org.netbeans.editor.ext.html.parser.SyntaxElement; 23 import java.io.File ; 24 import java.io.IOException ; 25 import javax.swing.text.BadLocationException ; 26 import org.netbeans.editor.BaseDocument; 27 import org.netbeans.editor.ext.html.dtd.DTD; 28 import org.netbeans.editor.ext.html.test.TestBase; 29 import org.netbeans.modules.editor.html.HTMLKit; 30 import org.netbeans.modules.editor.html.NbReaderProvider; 31 32 33 38 public class HTMLSyntaxSupportTest extends TestBase { 39 40 static HTMLSyntaxSupport sup; 41 static BaseDocument doc; 42 43 public HTMLSyntaxSupportTest() throws IOException , BadLocationException { 44 super("htmlsyntaxsupporttest"); 45 setUpSuite(); 46 } 47 48 private void setUpSuite() throws IOException , BadLocationException { 49 File inputFile = new File (getDataDir(), "input/HTMLSyntaxSupportTest/index.html"); 50 String content = Utils.readFileContentToString(inputFile); 51 doc = createDocument(); 52 doc.insertString(0,content,null); 53 sup = new HTMLSyntaxSupport(doc); 54 NbReaderProvider.setupReaders(); } 56 57 public void tearDown() { 58 } 59 60 62 public void testBasis() { 63 assertNotNull(sup.getDocument()); 64 assertEquals(sup.getDocument(), doc); 65 66 assertNotNull(sup.getDocType()); 67 assertEquals("-//W3C//DTD HTML 4.01 Transitional//EN", sup.getDocType()); 68 69 DTD dtd = sup.getDTD(); 70 assertNotNull(dtd); 71 } 72 73 public void testSyntaxElementsBasis() throws BadLocationException { 74 SyntaxElement se = sup.getElementChain(0); 75 76 assertNotNull(se); 77 assertNull(se.getPrevious()); 79 SyntaxElement next = se.getNext(); 80 assertNotNull(next); 81 82 SyntaxElement prev = next.getPrevious(); 83 assertNotNull(next); 84 assertEquals(prev, se); 85 } 86 87 88 public void testSyntaxElementsForEveryPositionInDocument() throws BadLocationException { 89 for(int i = 0; i < doc.getLength(); i++) { 90 SyntaxElement se = sup.getElementChain(i); 91 assertNotNull(se); 92 getRef().println(i+":"+se); 93 } 94 compareReferenceFiles(); 95 } 96 97 public void testWalkThroughSyntaxElements() throws BadLocationException { 98 SyntaxElement se = sup.getElementChain(0); 99 do { 100 getRef().println(se); 101 102 SyntaxElement next = se.getNext(); 103 104 assertNotSame(next, se); 105 se = next; 106 } while(se != null); 107 108 compareReferenceFiles(); 109 } 110 111 public void testWalkBackwartThroughtSyntaxElements() throws BadLocationException { 112 SyntaxElement se = sup.getElementChain(doc.getLength() - 1); 113 do { 114 getRef().println(se); 115 116 SyntaxElement prev = se.getPrevious(); 117 118 assertNotSame(prev, se); 119 se = prev; 120 } while(se != null); 121 122 compareReferenceFiles(); 123 } 124 125 141 public void testFindMatchingBlock() throws BadLocationException { 142 for(int i = 0; i < doc.getLength(); i++) { 143 int[] match = sup.findMatchingBlock(i, false); 144 if(match == null) { 145 getRef().println(i + " => NO MATCH"); 146 } else { 147 getRef().println(i + " => " + "[" + match[0] + ";" + match[1] + "]"); 148 } 149 } 150 151 compareReferenceFiles(); 152 } 153 154 private static HTMLSyntaxSupport createSupportForText(String text) throws BadLocationException { 155 BaseDocument bd = new BaseDocument(HTMLKit.class, false); 156 bd.insertString(0,text,null); 157 return new HTMLSyntaxSupport(bd); 158 } 159 160 private static final String TEXT1 = "<html><body bgcolor=\"green\">hello<br/></body></html>"; 163 164 } 165 | Popular Tags |