use of org.eclipse.jface.text.FindReplaceDocumentAdapter 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.FindReplaceDocumentAdapter 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.FindReplaceDocumentAdapter 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.FindReplaceDocumentAdapter in project eclipse.platform.text by eclipse.
the class FindReplaceDocumentAdapterTest method testRegexFindStackOverflow_fail.
@Test
public void testRegexFindStackOverflow_fail() throws Exception {
if (BUG_392594 && System.getProperty("os.name").indexOf("Mac") != -1)
// VM crash on the Mac, see https://bugs.eclipse.org/392594
return;
FindReplaceDocumentAdapter adapter = new FindReplaceDocumentAdapter(fDocument);
int len = 100000;
char[] chars = new char[len];
Arrays.fill(chars, '\n');
chars[0] = '{';
chars[len - 1] = '}';
fDocument.set(new String(chars));
try {
adapter.find(0, "\\{(.|[\\r\\n])*\\}", true, false, false, true);
} catch (PatternSyntaxException ex) {
return;
}
fail();
}
use of org.eclipse.jface.text.FindReplaceDocumentAdapter 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);
}
}
Aggregations