1 19 20 package org.netbeans.editor.ext.html; 21 22 import java.io.File ; 23 import java.io.IOException ; 24 import java.io.PrintStream ; 25 import java.net.URL ; 26 import java.util.Iterator ; 27 import java.util.List ; 28 import javax.swing.JEditorPane ; 29 import javax.swing.text.BadLocationException ; 30 import javax.swing.text.JTextComponent ; 31 import org.netbeans.editor.BaseDocument; 32 import org.netbeans.editor.TokenContext; 33 import org.netbeans.editor.TokenContextPath; 34 import org.netbeans.editor.TokenID; 35 import org.netbeans.editor.TokenItem; 36 import org.netbeans.editor.ext.CompletionQuery; 37 import org.netbeans.editor.ext.html.HTMLSyntax; 38 import org.netbeans.editor.ext.html.dtd.DTD; 39 import org.netbeans.editor.ext.html.test.TestBase; 40 import org.netbeans.junit.NbTestCase; 41 import org.netbeans.modules.editor.html.HTMLKit; 42 import org.netbeans.modules.editor.html.NbReaderProvider; 43 44 import org.openide.ErrorManager; 45 46 51 public class HTMLCompletionQueryTest extends TestBase { 52 53 public HTMLCompletionQueryTest() throws IOException , BadLocationException { 54 super("htmlsyntaxsupporttest"); 55 NbReaderProvider.setupReaders(); } 57 58 public void setUp() { 59 } 60 61 public void tearDown() { 62 } 63 64 public void testIndexHtml() throws IOException , BadLocationException { 66 testCompletionResults(new File (getDataDir(), "input/HTMLCompletionQueryTest/index.html")); 67 } 68 69 74 private void testCompletionResults(File inputFile) throws IOException , BadLocationException { 76 String content = Utils.readFileContentToString(inputFile); 77 BaseDocument doc = createDocument(); 78 doc.insertString(0,content,null); 79 HTMLSyntaxSupport sup = new HTMLSyntaxSupport(doc); 80 HTMLCompletionQuery query = new HTMLCompletionQuery(); 81 82 JEditorPane component = new JEditorPane (); 83 for(int i = 0; i < doc.getLength(); i++) { 84 CompletionQuery.Result result = query.query(component, HTMLKit.class, doc, i, sup); 85 if(result == null) { 86 getRef().println(i+" => NO RESULT"); 87 } else { 88 List data = result.getData(); 89 if(data == null) { 90 getRef().println(i + " => NO RESULT"); 91 } else { 92 StringBuffer sb = new StringBuffer (); 93 sb.append('['); 94 Iterator itr = data.iterator(); 95 while(itr.hasNext()) { 96 sb.append(itr.next()); 97 if(itr.hasNext()) sb.append(','); 98 } 99 sb.append(']'); 100 getRef().println(sb.toString()); 101 } 102 } 103 104 } 105 106 compareReferenceFiles(); 107 } 108 109 } 110 | Popular Tags |