1 19 20 package org.netbeans.test.web.core.syntax; 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.editor.ext.java.JavaSyntax; 30 import org.netbeans.junit.NbTestCase; 31 32 import org.netbeans.modules.web.core.syntax.deprecated.Jsp11Syntax; 33 import org.openide.ErrorManager; 34 35 39 public class JspMultiSyntaxTest extends NbTestCase { 40 41 private static Jsp11Syntax syntax = new Jsp11Syntax(new HTMLSyntax(), new JavaSyntax()); 43 44 public JspMultiSyntaxTest() { 45 super("jspmultisyntaxtest"); 46 } 47 48 public void setUp() { 49 getRef().println("'token image' [offset, length]; tokenID name; tokenID id; token category name; <list of token context names>\n--------------------\n"); 51 } 52 53 public void tearDown() { 54 compareReferenceFiles(); 55 } 56 57 59 public void testHtml() { 60 dumpTokensForContent("<html>\n<body>\n<h1>hello</h1>\n</body>\n</html>"); 61 } 62 63 public void testJavaScripting() { 64 dumpTokensForContent("<html><%! int a = 1; %>\n\n<br>\n<%=\"hello\"%>\n<br>\n<% String s = \"world\"; %>\n</html>"); 65 } 66 67 public void testJspDeclaration() { 68 dumpTokensForContent("<%@page contentType=\"text/html\"%>\n"+ 69 "<%@page pageEncoding=\"UTF-8\"%>" + 70 "<%@taglib uri=\"http://java.sun.com/jsp/jstl/core\" prefix=\"c\"%>"); 71 } 72 73 public void testExpressionLanguage() { 74 dumpTokensForContent("<html>${pageContext.request.contextPath}\n<br>" + 75 "${pageContext.request.contextPath}\n " + 76 "${header[\"host\"]} <br>\n" + 77 "${requestScope['javax.servlet.forward.servlet_path']}\n</html>"); 78 } 79 80 public void testBug53102() { 81 dumpTokensForContent("<html>\n<head />\n<he"); 82 } 83 84 public void testBug52942() { 85 dumpTokensForContent("<a HREF=\"<%= 1 %>\" >Destination</a>"); 86 } 87 88 public void testBugWrongJsptagType() { 89 dumpTokensForContent("\n<a >\n"); 90 } 91 92 public void test50283_1() { 93 dumpTokensForContent("< /jsp:element >"); } 95 96 public void test50283_2() { 97 dumpTokensForContent("</ jsp:element >"); } 99 100 public void testJspComment() { 101 dumpTokensForContent("<html><%-- text \n new line --%></html>\n"); 102 } 103 104 public void testSimpleJspTag() { 105 dumpTokensForContent("</jsp:useBean id=\"sss\">"); 106 } 107 108 110 private void dumpTokensForContent(String content) { 111 loadContentToSyntax(content); 112 dumpTokensData(getRef()); } 114 115 private void dumpTokensData(PrintStream out) { 116 TokenID tokenID = null; 117 char[] buffer = syntax.getBuffer(); 118 String tokenImage = null; 119 TokenContextPath tcp = null; 120 do { 121 tokenID = syntax.nextToken(); 123 124 if( tokenID == null ) break; 125 126 tokenImage = new String (buffer, syntax.getTokenOffset(), syntax.getTokenLength()); 127 tcp = syntax.getTokenContextPath(); 128 129 out.print("'" + SyntaxUtils.normalize(tokenImage) + "' ["+syntax.getTokenOffset() + ", " + syntax.getTokenLength() + "]; " + tokenID.getName() + "; " + tokenID.getNumericID() + "; "+ (tokenID.getCategory() != null ? tokenID.getCategory().getName() : "-") + "; "); 131 SyntaxUtils.dumpTokenContextPath(tcp, out); 132 out.println(); 133 134 } 135 while(true); 136 } 137 138 private void loadContentToSyntax(String content) { 139 char[] buffer = content.toCharArray(); 141 syntax.load(null, buffer, 0, buffer.length, true); 142 } 143 144 } 145 | Popular Tags |