1 19 package org.netbeans.modules.editor.hints; 20 21 import java.util.Arrays ; 22 import javax.swing.text.DefaultStyledDocument ; 23 import javax.swing.text.Document ; 24 import org.netbeans.editor.BaseDocument; 25 import org.netbeans.editor.BaseKit; 26 import org.netbeans.junit.NbTestCase; 27 import org.netbeans.modules.editor.NbEditorDocument; 28 29 33 public class HintsControllerImplTest extends NbTestCase { 34 35 public HintsControllerImplTest(String name) { 36 super(name); 37 } 38 39 public void testComputeLineSpan() throws Exception { 40 doTestComputeLineSpan(new DocumentCreator() { 41 public Document createDocument() { 42 return new NbEditorDocument(BaseKit.class); 43 } 44 }); 45 doTestComputeLineSpan(new DocumentCreator() { 46 public Document createDocument() { 47 return new DefaultStyledDocument (); 48 } 49 }); 50 } 51 52 private void doTestComputeLineSpan(DocumentCreator creator) throws Exception { 53 Document bdoc = creator.createDocument(); 54 55 bdoc.insertString(0, " 1234 \n 567\n567 \n456", null); 56 57 assertSpan(bdoc, 1, 2, 6); 58 assertSpan(bdoc, 2, 10, 13); 59 assertSpan(bdoc, 3, 14, 17); 60 assertSpan(bdoc, 4, 19, 22); 61 62 bdoc = creator.createDocument(); 63 64 bdoc.insertString(0, "456", null); 65 66 assertSpan(bdoc, 1, 0, 3); 67 68 bdoc = creator.createDocument(); 69 70 bdoc.insertString(0, " ", null); 71 72 assertSpan(bdoc, 1, 0, 0); 73 } 74 75 private static interface DocumentCreator { 76 public Document createDocument(); 77 } 78 79 private void assertSpan(Document doc, int lineNumber, int... expectedSpan) throws Exception { 80 int[] returnedSpan = HintsControllerImpl.computeLineSpan(doc, lineNumber); 81 82 assertTrue(Arrays.toString(returnedSpan), Arrays.equals(expectedSpan, returnedSpan)); 83 } 84 } 85 | Popular Tags |