KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > netbeans > lib > lexer > test > inc > OriginalTextTest


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-2007 Sun
17  * Microsystems, Inc. All Rights Reserved.
18  */

19
20 package org.netbeans.lib.lexer.test.inc;
21
22 import junit.framework.TestCase;
23 import org.netbeans.lib.lexer.inc.OriginalText;
24
25 /**
26  * Test for the text that emulates state of a mutable text input
27  * before a particular modification.
28  *
29  * @author mmetelka
30  */

31 public class OriginalTextTest extends TestCase {
32
33     public OriginalTextTest(String JavaDoc testName) {
34         super(testName);
35     }
36
37     public void test() throws Exception JavaDoc {
38         String JavaDoc orig = "abcdef";
39         check(orig, 0, 2, "xyz");
40         check(orig, 0, 2, "x");
41         check(orig, 0, 0, "");
42         check(orig, 0, 0, "klmnopqrst");
43         check(orig, orig.length(), 0, "");
44         check(orig, orig.length(), 0, "klmnopqrst");
45         check(orig, orig.length(), 0, "x");
46         check(orig, 3, 0, "x");
47         check(orig, 3, 1, "xyz");
48         check(orig, 3, 3, "xy");
49         check(orig, 1, 0, "x");
50         check(orig, 1, 1, "xyz");
51         check(orig, 1, 3, "xy");
52         check(orig, 4, 0, "x");
53         check(orig, 4, 1, "xy");
54         check(orig, 4, 2, "x");
55     }
56
57     private void check(String JavaDoc text, int removeIndex, int removeLength, String JavaDoc insertText) {
58         String JavaDoc modText = text.substring(0, removeIndex) + insertText + text.substring(removeIndex + removeLength);
59         OriginalText ot = new OriginalText(modText, removeIndex, text.substring(removeIndex, removeIndex + removeLength), insertText.length());
60         assertEquals(text.length(), ot.length());
61         for (int i = 0; i < text.length(); i++) {
62             assertEquals(String.valueOf(i), text.charAt(i), ot.charAt(i));
63         }
64         for (int i = 0; i < text.length(); i++) {
65             for (int j = i; j < text.length(); j++) {
66                 assertEquals(text.substring(i, j), String.valueOf(ot.toCharArray(i, j)));
67             }
68         }
69         assertEquals(text, ot.toString());
70     }
71     
72 }
73
Popular Tags