use of org.eclipse.jface.text.IRegion in project eclipse.platform.text by eclipse.
the class FindReplaceDocumentAdapterTest method testReplace.
@Test
public void testReplace() {
FindReplaceDocumentAdapter findReplaceDocumentAdapter = new FindReplaceDocumentAdapter(fDocument);
try {
// $NON-NLS-1$
findReplaceDocumentAdapter.find(0, "public", true, true, false, false);
// $NON-NLS-1$
IRegion r = findReplaceDocumentAdapter.replace("private", false);
assertNotNull(r);
// $NON-NLS-1$
findReplaceDocumentAdapter.find(0, "public", true, true, false, false);
// $NON-NLS-1$
r = findReplaceDocumentAdapter.replace("private", false);
assertNotNull(r);
// $NON-NLS-1$
findReplaceDocumentAdapter.find(0, "public", true, true, false, false);
// $NON-NLS-1$
r = findReplaceDocumentAdapter.replace("private", false);
assertNotNull(r);
// Search again: there will be no match
// $NON-NLS-1$
findReplaceDocumentAdapter.find(0, "public", true, true, false, false);
try {
// $NON-NLS-1$
findReplaceDocumentAdapter.replace("private", false);
} catch (IllegalStateException e) {
assertTrue(true);
}
String text = // $NON-NLS-1$
"package TestPackage;\n" + // $NON-NLS-1$
"/*\n" + // $NON-NLS-1$
"* comment\n" + // $NON-NLS-1$
"*/\n" + // $NON-NLS-1$
" private class Class {\n" + // $NON-NLS-1$
" // comment1\n" + // $NON-NLS-1$
" private void method1() {\n" + // $NON-NLS-1$
" }\n" + // $NON-NLS-1$
" // comment2\n" + // $NON-NLS-1$
" private void method2() {\n" + // $NON-NLS-1$
" }\n" + // $NON-NLS-1$
" }\n" + // $NON-NLS-1$S
"// Gel\u00f6st";
assertEquals(text, fDocument.get());
} catch (BadLocationException e) {
Assert.assertTrue(false);
}
}
use of org.eclipse.jface.text.IRegion in project eclipse.platform.text by eclipse.
the class FindReplaceDocumentAdapterTest method testRegexFindLinebreakIllegal.
@Test
public void testRegexFindLinebreakIllegal() throws Exception {
FindReplaceDocumentAdapter adapter = new FindReplaceDocumentAdapter(fDocument);
fDocument.set("\n");
IRegion region = null;
try {
region = adapter.find(0, "[\\R]", true, false, false, true);
} catch (PatternSyntaxException e) {
// expected
}
assertNull(region);
try {
region = adapter.find(0, "[\\s&&[^\\R]]", true, false, false, true);
} catch (PatternSyntaxException e) {
// expected
}
assertNull(region);
try {
region = adapter.find(0, "\\p{\\R}", true, false, false, true);
} catch (PatternSyntaxException e) {
// expected
}
assertNull(region);
}
use of org.eclipse.jface.text.IRegion in project eclipse.platform.text by eclipse.
the class FindReplaceDocumentAdapterTest method testUTF8Pattern.
@Test
public void testUTF8Pattern() {
FindReplaceDocumentAdapter findReplaceDocumentAdapter = new FindReplaceDocumentAdapter(fDocument);
try {
IRegion result = new Region(153, 6);
// Find case-sensitive
// $NON-NLS-1$
IRegion r = findReplaceDocumentAdapter.find(0, "Gel\u00F6st", true, true, false, false);
assertEquals(result, r);
// $NON-NLS-1$
r = findReplaceDocumentAdapter.find(0, "Gel\u00F6st", true, true, false, false);
assertEquals(result, r);
// Find non-case-sensitive
// $NON-NLS-1$
r = findReplaceDocumentAdapter.find(0, "Gel\u00D6st", true, false, false, false);
assertEquals(result, r);
// $NON-NLS-1$
r = findReplaceDocumentAdapter.find(0, "Gel\u00D6st", true, false, false, false);
assertEquals(result, r);
} catch (BadLocationException e) {
Assert.assertTrue(false);
}
}
use of org.eclipse.jface.text.IRegion in project eclipse.platform.text by eclipse.
the class FindReplaceDocumentAdapterTest method testBug74993.
/**
* Test case for: https://bugs.eclipse.org/bugs/show_bug.cgi?id=74993
*/
@Test
public void testBug74993() {
FindReplaceDocumentAdapter findReplaceDocumentAdapter = new FindReplaceDocumentAdapter(fDocument);
try {
// $NON-NLS-1$
IRegion r = findReplaceDocumentAdapter.find(12, "\\w+", false, false, false, true);
assertEquals(new Region(6, 1), r);
} catch (BadLocationException e) {
Assert.assertTrue(false);
}
}
use of org.eclipse.jface.text.IRegion in project eclipse.platform.text by eclipse.
the class LineTrackerTest3 method testFunnyLastLineCompatibility.
@Test
public void testFunnyLastLineCompatibility() throws Exception {
/* empty last line */
set("x\n");
int[] offsets = { 0, 2 };
int[] lengths = { 1, 0 };
assertEquals("invalid number of lines, ", lengths.length, fTracker.getNumberOfLines());
assertEquals("invalid number of lines, ", lengths.length, fTracker.getNumberOfLines(0, fText.getLength()));
for (int i = 0; i < lengths.length; i++) {
IRegion line = fTracker.getLineInformation(i);
assertEquals("line: " + i, lengths[i], line.getLength());
assertEquals("line: " + i, offsets[i], line.getOffset());
}
try {
fTracker.getLineInformation(lengths.length);
fail();
} catch (Exception e) {
}
try {
fTracker.getLineInformationOfOffset(offsets[offsets.length] + 1);
fail();
} catch (Exception e) {
}
/* phantom last line when the last line is not empty */
set("x\nx");
offsets = new int[] { 0, 2, 3 };
lengths = new int[] { 1, 1, 0 };
assertEquals("invalid number of lines, ", lengths.length - 1, /* !!!! */
fTracker.getNumberOfLines());
assertEquals("invalid number of lines, ", lengths.length - 1, /* !!!! */
fTracker.getNumberOfLines(0, fText.getLength()));
for (int i = 0; i < lengths.length; i++) {
IRegion line = fTracker.getLineInformation(i);
int len = lengths[i];
int offset = offsets[i];
assertEquals("length of line: " + i, len, line.getLength());
assertEquals("offset of line: " + i, offset, line.getOffset());
line = fTracker.getLineInformationOfOffset(offset);
if (i == lengths.length - 1) {
// phantom line cannot be queried by offset
len = lengths[i - 1];
offset = offsets[i - 1];
}
assertEquals("length of line: " + i, len, line.getLength());
assertEquals("offset of line: " + i, offset, line.getOffset());
}
try {
fTracker.getLineInformation(lengths.length);
fail();
} catch (Exception e) {
}
try {
fTracker.getLineInformationOfOffset(offsets[offsets.length] + 1);
fail();
} catch (Exception e) {
}
}
Aggregations