1 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 31 public class OriginalTextTest extends TestCase { 32 33 public OriginalTextTest(String testName) { 34 super(testName); 35 } 36 37 public void test() throws Exception { 38 String 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 text, int removeIndex, int removeLength, String insertText) { 58 String 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 |