Search in sources :

Example 21 with FindReplaceDocumentAdapter

use of org.eclipse.jface.text.FindReplaceDocumentAdapter in project eclipse.platform.text by eclipse.

the class FindReplaceDocumentAdapterTest method testRegexRetainCase.

/*
	 * @since 3.4
	 */
@Test
public void testRegexRetainCase() throws Exception {
    FindReplaceDocumentAdapter findReplaceDocumentAdapter = new FindReplaceDocumentAdapter(fDocument);
    fDocument.set("foo");
    regexReplace("foo", "xyz\\Cbar\\Cfar", findReplaceDocumentAdapter);
    assertEquals("xyzbarfar", fDocument.get());
    fDocument.set("FOO");
    regexReplace("FOO", "xyz\\Cbar\\Cfar", findReplaceDocumentAdapter);
    assertEquals("xyzBARFAR", fDocument.get());
    fDocument.set("Foo");
    regexReplace("Foo", "xyz\\Cbar\\Cfar", findReplaceDocumentAdapter);
    assertEquals("xyzBarFar", fDocument.get());
    /* Current behavior - may seem strange but it's expected
		 * Retain case does not apply inside groups for now.
		 */
    fDocument.set("Foox");
    regexReplace("F(oo)x", "\\C$1", findReplaceDocumentAdapter);
    assertEquals("oo", fDocument.get());
    fDocument.set("Foo");
    regexReplace("Foo", "xyz\\Cna\\u00EFve\\xFF\\C\\xFF", findReplaceDocumentAdapter);
    assertEquals("xyzNa\u00EFve\u00FF\u0178", fDocument.get());
    fDocument.set("FOO");
    regexReplace("FOO", "xyz\\Cna\\u00EFve\\xFF", findReplaceDocumentAdapter);
    assertEquals("xyzNA\u00CFVE\u0178", fDocument.get());
    fDocument.set("A");
    regexReplace("A", "\\Ci", findReplaceDocumentAdapter);
    assertEquals("I", fDocument.get());
    Locale currentLocale = Locale.getDefault();
    try {
        Locale.setDefault(new Locale("tr"));
        fDocument.set("A");
        regexReplace("A", "\\Ci", findReplaceDocumentAdapter);
        assertEquals("\u0130", fDocument.get());
        fDocument.set("a");
        regexReplace("a", "\\CI", findReplaceDocumentAdapter);
        assertEquals("\u0131", fDocument.get());
    } finally {
        Locale.setDefault(currentLocale);
    }
}
Also used : Locale(java.util.Locale) FindReplaceDocumentAdapter(org.eclipse.jface.text.FindReplaceDocumentAdapter) Test(org.junit.Test)

Example 22 with FindReplaceDocumentAdapter

use of org.eclipse.jface.text.FindReplaceDocumentAdapter in project eclipse.platform.text by eclipse.

the class FindReplaceDocumentAdapterTest method _testRegexReplace.

@Test
@Ignore
public void _testRegexReplace() throws Exception {
    fDocument.set("UnixWindowsMacInferred\n" + "Chars");
    FindReplaceDocumentAdapter findReplaceDocumentAdapter = new FindReplaceDocumentAdapter(fDocument);
    regexReplace("Unix", "$0\\n", findReplaceDocumentAdapter);
    regexReplace("(Windows)", "$1\\r\\n", findReplaceDocumentAdapter);
    regexReplace("(M)ac", "\\0\\r", findReplaceDocumentAdapter);
    regexReplace("(Inferred)", "\\1\\R", findReplaceDocumentAdapter);
    regexReplace("Chars", "\\\\, \\xF6, \\u00F6, \\t, \\n, \\r, \\f, \\a, \\e, \\cF", findReplaceDocumentAdapter);
    String text = "Unix\nWindows\r\nMac\rInferred\n\n\\, \u00F6, \u00F6, \t, \n, \r, \f, \u0007, \u001B, \u0006";
    assertEquals(text, fDocument.get());
}
Also used : FindReplaceDocumentAdapter(org.eclipse.jface.text.FindReplaceDocumentAdapter) Ignore(org.junit.Ignore) Test(org.junit.Test)

Example 23 with FindReplaceDocumentAdapter

use of org.eclipse.jface.text.FindReplaceDocumentAdapter in project eclipse.platform.text by eclipse.

the class FindReplaceDocumentAdapterTest method testRegexReplace2.

@Test
public void testRegexReplace2() throws Exception {
    FindReplaceDocumentAdapter findReplaceDocumentAdapter = new FindReplaceDocumentAdapter(fDocument);
    fDocument.set("foo");
    regexReplace("foo", "\\00", findReplaceDocumentAdapter);
    assertEquals("foo0", fDocument.get());
    fDocument.set("foo");
    regexReplace("foo", "\\010", findReplaceDocumentAdapter);
    assertEquals("foo10", fDocument.get());
    fDocument.set("foo");
    regexReplace("foo", "$00", findReplaceDocumentAdapter);
    assertEquals("foo0", fDocument.get());
    fDocument.set("foo");
    regexReplace("foo", "$010", findReplaceDocumentAdapter);
    assertEquals("foo10", fDocument.get());
}
Also used : FindReplaceDocumentAdapter(org.eclipse.jface.text.FindReplaceDocumentAdapter) Test(org.junit.Test)

Example 24 with FindReplaceDocumentAdapter

use of org.eclipse.jface.text.FindReplaceDocumentAdapter in project eclipse.platform.text by eclipse.

the class FindReplaceDocumentAdapterTest method testRegexReplace3.

@Test
public void testRegexReplace3() throws Exception {
    FindReplaceDocumentAdapter findReplaceDocumentAdapter = new FindReplaceDocumentAdapter(fDocument);
    fDocument.set("foo");
    regexReplace("(f)oo", "\\10", findReplaceDocumentAdapter);
    assertEquals("f0", fDocument.get());
    fDocument.set("foo");
    regexReplace("(f)oo", "$10", findReplaceDocumentAdapter);
    assertEquals("f0", fDocument.get());
}
Also used : FindReplaceDocumentAdapter(org.eclipse.jface.text.FindReplaceDocumentAdapter) Test(org.junit.Test)

Example 25 with FindReplaceDocumentAdapter

use of org.eclipse.jface.text.FindReplaceDocumentAdapter in project eclipse.platform.text by eclipse.

the class FindReplaceDocumentAdapterTest method testFindCaretInMiddleOfWord.

@Test
public void testFindCaretInMiddleOfWord() {
    FindReplaceDocumentAdapter findReplaceDocumentAdapter = new FindReplaceDocumentAdapter(fDocument);
    try {
        // Find forward when caret is inside word
        // $NON-NLS-1$
        IRegion r = findReplaceDocumentAdapter.find(12, "TestPackage", true, false, false, false);
        assertNull(r);
        // Find backward when caret is inside word
        // $NON-NLS-1$
        r = findReplaceDocumentAdapter.find(12, "TestPackage", false, false, false, false);
        assertNull(r);
    } 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)

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