KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > netbeans > modules > html > editor > folding > HTMLFoldingTest


1 /*
2  * The contents of this file are subject to the terms of the Common Development
3  * and Distribution License (the License). You may not use this file except in
4  * compliance with the License.
5  *
6  * You can obtain a copy of the License at http://www.netbeans.org/cddl.html
7  * or http://www.netbeans.org/cddl.txt.
8  *
9  * When distributing Covered Code, include this CDDL Header Notice in each file
10  * and include the License file at http://www.netbeans.org/cddl.txt.
11  * If applicable, add the following below the CDDL Header, with the fields
12  * enclosed by brackets [] replaced by your own identifying information:
13  * "Portions Copyrighted [year] [name of copyright owner]"
14  *
15  * The Original Software is NetBeans. The Initial Developer of the Original
16  * Software is Sun Microsystems, Inc. Portions Copyright 1997-2006 Sun
17  * Microsystems, Inc. All Rights Reserved.
18  */

19 package org.netbeans.modules.html.editor.folding;
20
21 import java.io.File JavaDoc;
22 import java.io.IOException JavaDoc;
23 import java.util.Iterator JavaDoc;
24 import java.util.List JavaDoc;
25 import javax.swing.text.BadLocationException JavaDoc;
26 import org.netbeans.editor.BaseDocument;
27 import org.netbeans.editor.ext.html.HTMLSyntaxSupport;
28 import org.netbeans.modules.editor.html.HTMLKit;
29 import org.netbeans.modules.html.editor.folding.HTMLFoldManager.FoldInfo;
30 import org.netbeans.modules.html.editor.test.TestBase;
31 import org.netbeans.modules.html.editor.test.Utils;
32
33 /** HTML Folding unit tests
34  *
35  * @author Marek Fukala
36  */

37 public class HTMLFoldingTest extends TestBase {
38     
39     private HTMLFoldManager fm;
40     
41     public HTMLFoldingTest() {
42         super("html-folding-test");
43          fm = new HTMLFoldManager();
44          fm.documentDirty = false;
45     }
46     
47     //--------- test methods -----------
48
public void testModelBasis() throws Exception JavaDoc /*BadLocationException, ParsingCancelledException*/ {
49         //set the document content
50
BaseDocument doc = createDocument();
51         HTMLSyntaxSupport sup = new HTMLSyntaxSupport(doc);
52         
53         doc.insertString(0,"\n <b>\n ahoj\n </b>\n ",null); //4 elements should be created
54
List JavaDoc/*<FoldInfo>*/ fis = fm.generateFolds(sup);
55         
56         assertEquals(1, fis.size()); //one fold for <b></b> created
57

58         //dumpFoldInfos(fis);
59
}
60      
61     public void testIndexHtml() throws Exception JavaDoc {
62         testFolds(new File JavaDoc(getDataDir(), "input/HTMLFoldingTest/index.html"));
63     }
64     
65     private void testFolds(File JavaDoc inputFile) throws IOException JavaDoc, BadLocationException JavaDoc, HTMLFoldManager.ParsingCancelledException {
66         String JavaDoc content = Utils.readFileContentToString(inputFile);
67         BaseDocument doc = createDocument();
68         doc.insertString(0,content,null);
69         HTMLSyntaxSupport sup = new HTMLSyntaxSupport(doc);
70         
71         List JavaDoc/*<FoldInfo>*/ fis = fm.generateFolds(sup);
72         dumpFoldInfos(fis);
73         
74         compareReferenceFiles();
75     }
76     
77     private void dumpFoldInfos(List JavaDoc/*<FoldInfo>*/ foldInfos) {
78         Iterator JavaDoc i = foldInfos.iterator();
79         while(i.hasNext()) {
80             FoldInfo fi = (FoldInfo)i.next();
81             getRef().println(fi);
82         }
83     }
84     
85 }
86
Popular Tags