Search in sources :

Example 6 with FindReplaceDocumentAdapter

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

Example 7 with FindReplaceDocumentAdapter

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

Example 8 with FindReplaceDocumentAdapter

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);
    }
}
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 9 with FindReplaceDocumentAdapter

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

Example 10 with FindReplaceDocumentAdapter

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);
    }
}
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)

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