use of org.eclipse.jface.text.FindReplaceDocumentAdapter in project eclipse.platform.text by eclipse.
the class FindReplaceDocumentAdapterTest method testIllegalState.
@Test
public void testIllegalState() {
FindReplaceDocumentAdapter findReplaceDocumentAdapter = new FindReplaceDocumentAdapter(fDocument);
try {
// $NON-NLS-1$
findReplaceDocumentAdapter.replace("TestPackage", false);
} catch (IllegalStateException e) {
Assert.assertTrue(true);
} catch (BadLocationException e) {
Assert.assertTrue(false);
}
findReplaceDocumentAdapter = new FindReplaceDocumentAdapter(fDocument);
try {
// $NON-NLS-1$
findReplaceDocumentAdapter.replace("TestPackage", true);
} catch (IllegalStateException e) {
Assert.assertTrue(true);
} catch (BadLocationException e) {
Assert.assertTrue(false);
}
}
use of org.eclipse.jface.text.FindReplaceDocumentAdapter in project eclipse.platform.text by eclipse.
the class FindReplaceDocumentAdapterTest method _testRegexFindLinebreak2.
@Test
@Ignore
public void _testRegexFindLinebreak2() throws Exception {
FindReplaceDocumentAdapter adapter = new FindReplaceDocumentAdapter(fDocument);
String contents = "+[\\R]\\R\r\n";
fDocument.set(contents);
int n = contents.indexOf("[");
int rn = contents.indexOf("\r\n");
IRegion region = adapter.find(0, "[a-zA-Z\\t{\\\\R}]*\\{?\\R", true, false, false, true);
assertEquals(new Region(0, n - 1), region);
region = adapter.find(n, "\\Q[\\R]\\R\\E{0,1}(\\R)", true, false, false, true);
assertEquals(new Region(n, rn + 2 - n), region);
adapter.replace("Win\\1$1", true);
assertEquals("+Win\r\n\r\n", fDocument.get());
}
use of org.eclipse.jface.text.FindReplaceDocumentAdapter in project eclipse.platform.text by eclipse.
the class FindReplaceDocumentAdapterTest method testFindCaretAtWordStart.
@Test
public void testFindCaretAtWordStart() {
FindReplaceDocumentAdapter findReplaceDocumentAdapter = new FindReplaceDocumentAdapter(fDocument);
try {
// Find forward when caret is just before a word
// $NON-NLS-1$
IRegion r = findReplaceDocumentAdapter.find(8, "TestPackage", true, false, false, false);
assertEquals(new Region(8, 11), 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 testRegexFindLinebreak.
@Test
public void testRegexFindLinebreak() throws Exception {
FindReplaceDocumentAdapter adapter = new FindReplaceDocumentAdapter(fDocument);
String contents = "Unix\nWindows\r\nMac\rEnd";
fDocument.set(contents);
int n = contents.indexOf("\n");
int rn = contents.indexOf("\r\n");
int r = contents.indexOf("\rEnd");
IRegion region = adapter.find(0, "\\R", true, false, false, true);
assertEquals(new Region(n, 1), region);
region = adapter.find(n + 1, "\\R", true, false, false, true);
assertEquals(new Region(rn, 2), region);
region = adapter.find(rn + 2, "\\R", true, false, false, true);
assertEquals(new Region(r, 1), region);
region = adapter.find(r + 1, "\\R", true, false, false, true);
assertNull(region);
}
use of org.eclipse.jface.text.FindReplaceDocumentAdapter in project eclipse.platform.text by eclipse.
the class FindReplaceDocumentAdapterTest method testRegexFindLinebreak2_fail.
@Test
public void testRegexFindLinebreak2_fail() throws Exception {
FindReplaceDocumentAdapter adapter = new FindReplaceDocumentAdapter(fDocument);
String contents = "Unix\n[\\R]\\R\r\n";
fDocument.set(contents);
int n = contents.indexOf("\n");
int rn = contents.indexOf("\r\n");
IRegion region = adapter.find(0, "[a-zA-Z\\t{\\\\R}]*\\{?\\R", true, false, false, true);
assertEquals(new Region(0, n + 1), region);
region = adapter.find(n + 1, "\\Q[\\R]\\R\\E{0,1}(\\R)", true, false, false, true);
assertEquals(new Region(n + 1, rn + 2 - (n + 1)), region);
try {
adapter.replace("Win\\1$1", true);
} catch (PatternSyntaxException ex) {
return;
}
fail();
}
Aggregations