Search in sources :

Example 26 with FindReplaceDocumentAdapter

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);
    }
}
Also used : FindReplaceDocumentAdapter(org.eclipse.jface.text.FindReplaceDocumentAdapter) BadLocationException(org.eclipse.jface.text.BadLocationException) Test(org.junit.Test)

Example 27 with FindReplaceDocumentAdapter

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());
}
Also used : Region(org.eclipse.jface.text.Region) IRegion(org.eclipse.jface.text.IRegion) FindReplaceDocumentAdapter(org.eclipse.jface.text.FindReplaceDocumentAdapter) IRegion(org.eclipse.jface.text.IRegion) Ignore(org.junit.Ignore) Test(org.junit.Test)

Example 28 with FindReplaceDocumentAdapter

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);
    }
}
Also used : Region(org.eclipse.jface.text.Region) IRegion(org.eclipse.jface.text.IRegion) FindReplaceDocumentAdapter(org.eclipse.jface.text.FindReplaceDocumentAdapter) IRegion(org.eclipse.jface.text.IRegion) BadLocationException(org.eclipse.jface.text.BadLocationException) Test(org.junit.Test)

Example 29 with FindReplaceDocumentAdapter

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);
}
Also used : Region(org.eclipse.jface.text.Region) IRegion(org.eclipse.jface.text.IRegion) FindReplaceDocumentAdapter(org.eclipse.jface.text.FindReplaceDocumentAdapter) IRegion(org.eclipse.jface.text.IRegion) Test(org.junit.Test)

Example 30 with FindReplaceDocumentAdapter

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();
}
Also used : Region(org.eclipse.jface.text.Region) IRegion(org.eclipse.jface.text.IRegion) FindReplaceDocumentAdapter(org.eclipse.jface.text.FindReplaceDocumentAdapter) IRegion(org.eclipse.jface.text.IRegion) PatternSyntaxException(java.util.regex.PatternSyntaxException) Test(org.junit.Test)

Aggregations

FindReplaceDocumentAdapter (org.eclipse.jface.text.FindReplaceDocumentAdapter)35 IRegion (org.eclipse.jface.text.IRegion)24 Test (org.junit.Test)20 BadLocationException (org.eclipse.jface.text.BadLocationException)18 Region (org.eclipse.jface.text.Region)12 IDocument (org.eclipse.jface.text.IDocument)7 Document (org.eclipse.jface.text.Document)4 PatternSyntaxException (java.util.regex.PatternSyntaxException)3 Position (org.eclipse.jface.text.Position)3 IJavaProject (org.eclipse.jdt.core.IJavaProject)2 ProjectionAnnotation (org.eclipse.jface.text.source.projection.ProjectionAnnotation)2 MultiPageEditorPart (org.eclipse.ui.part.MultiPageEditorPart)2 ITextEditor (org.eclipse.ui.texteditor.ITextEditor)2 Ignore (org.junit.Ignore)2 SQLDocument (com.cubrid.common.ui.query.editor.SQLDocument)1 SQLPartitionScanner (com.cubrid.common.ui.query.editor.SQLPartitionScanner)1 SQLTextViewer (com.cubrid.common.ui.query.editor.SQLTextViewer)1 SQLViewerConfiguration (com.cubrid.common.ui.query.editor.SQLViewerConfiguration)1 HashMap (java.util.HashMap)1 Locale (java.util.Locale)1