1 19 20 package org.netbeans.editor.ext.html; 21 22 import java.io.PrintStream ; 23 import java.net.URL ; 24 import org.netbeans.editor.TokenContext; 25 import org.netbeans.editor.TokenContextPath; 26 import org.netbeans.editor.TokenID; 27 import org.netbeans.editor.TokenItem; 28 import org.netbeans.editor.ext.html.HTMLSyntax; 29 import org.netbeans.junit.NbTestCase; 30 31 import org.openide.ErrorManager; 32 33 37 public class HTMLSyntaxTest extends NbTestCase { 38 39 private static HTMLSyntax syntax = new HTMLSyntax(); 41 42 public HTMLSyntaxTest() { 43 super("htmlsyntaxtest"); 44 } 45 46 public void setUp() { 47 getRef().println("'token image' [offset, length]; tokenID name; tokenID id; token category name; <list of token context names>\n--------------------\n"); 49 } 50 51 public void tearDown() { 52 compareReferenceFiles(); 53 } 54 55 57 public void testHtml() { 58 dumpTokensForContent("<html>\n<body>\n<h1>hello</h1>\n</body>\n</html>"); 59 } 60 61 public void testErrorInTag() { 62 dumpTokensForContent("<html@><head #/></html>"); 63 } 64 65 public void testAttrs() { 66 dumpTokensForContent("<meta http-equiv=\"Content-Type\" content=\"text/html; charset=UTF-8\">"); 67 } 68 69 public void testErrorInAttrs() { 70 dumpTokensForContent("<meta 2 http-equiv=\"Content-Type\" content@=\"text/html; charset=UTF-8\">"); 71 } 72 73 public void testMultilineAttrs() { 74 dumpTokensForContent("<meta \n http-equiv=\"Content-Type\" \n content=\"text/html; charset=UTF-8\">"); 75 } 76 77 public void testSGMLEscape() { 78 dumpTokensForContent("<!DOCTYPE HTML PUBLIC \"-//W3C//DTD HTML 4.01 Transitional//EN\">"); 79 } 80 81 public void testSGMLEscapeOnMoreLines() { 82 dumpTokensForContent("<!DOCTYPE HTML \nPUBLIC \"-//W3C//DTD HTML 4.01 Transitional//EN\"\n>"); 83 } 84 85 public void testHTMLComment() { 86 dumpTokensForContent("<html>\n<!-- this is a commnent -->\n</html>"); 87 } 88 89 public void testHTMLMulitilineComment() { 90 dumpTokensForContent("<html>\n<!-- this \nis \na \ncommnent \n-->\n</html>"); 91 } 92 93 public void testEmbededCSS() { 94 dumpTokensForContent("<style type=\"text/css\">\n"+ 95 "#search {height:100%;}\n"+ 96 "#topmodule {align:right;}\n"+ 97 "</style>\n"); 98 } 99 100 public void testBug53102() { 101 dumpTokensForContent("<html>\n<head />\n<he"); 102 } 103 104 public void testBugWrongJsptagType() { 105 dumpTokensForContent("\n<a >\n"); 106 } 107 108 public void testPlainText() { 109 dumpTokensForContent("this is just a text"); 110 } 111 112 public void testEntityReference() { 113 dumpTokensForContent("<html>\n & \n </html>"); 114 } 115 116 public void testNumericReference() { 117 dumpTokensForContent("<html>\n ř \n </html>"); 118 } 119 120 122 private void dumpTokensForContent(String content) { 123 loadContentToSyntax(content); 124 dumpTokensData(getRef()); } 126 127 private void dumpTokensData(PrintStream out) { 128 TokenID tokenID = null; 129 char[] buffer = syntax.getBuffer(); 130 String tokenImage = null; 131 TokenContextPath tcp = null; 132 do { 133 tokenID = syntax.nextToken(); 135 136 if( tokenID == null ) break; 137 138 tokenImage = new String (buffer, syntax.getTokenOffset(), syntax.getTokenLength()); 139 tcp = syntax.getTokenContextPath(); 140 141 out.print("'" + SyntaxUtils.normalize(tokenImage) + "' ["+syntax.getTokenOffset() + ", " + syntax.getTokenLength() + "]; " + tokenID.getName() + "; " + tokenID.getNumericID() + "; "+ (tokenID.getCategory() != null ? tokenID.getCategory().getName() : "-") + "; "); 143 SyntaxUtils.dumpTokenContextPath(tcp, out); 144 out.println(); 145 146 } 147 while(true); 148 } 149 150 private void loadContentToSyntax(String content) { 151 char[] buffer = content.toCharArray(); 153 syntax.load(null, buffer, 0, buffer.length, true, -1); 154 } 155 156 } 157 | Popular Tags |