use of org.eclipse.jface.text.BadLocationException 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.BadLocationException 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.BadLocationException 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);
}
}
use of org.eclipse.jface.text.BadLocationException in project eclipse.platform.text by eclipse.
the class TextUtilitiesTest method testMergeEvents2.
@Test
public void testMergeEvents2() {
IDocument reference = new Document();
LazilyMirroredDocument2 testee = new LazilyMirroredDocument2(reference);
try {
List<DocumentEvent> events = new ArrayList<>();
int currentLength = 0;
events.add(new DocumentEvent(reference, 0, 0, "foo bar goo haa"));
events.add(new DocumentEvent(reference, 0, "foo bar goo haa".length(), "foo bar goo haa"));
events.add(new DocumentEvent(reference, 4, 4, "xxxx"));
events.add(new DocumentEvent(reference, 4, 4, "yyy"));
events.add(new DocumentEvent(reference, 4, 3, "moo "));
events.add(new DocumentEvent(reference, 9, 2, "asd"));
events.add(new DocumentEvent(reference, 0, 2, "asd"));
for (Iterator<DocumentEvent> iterator = events.iterator(); iterator.hasNext(); ) {
DocumentEvent event = iterator.next();
currentLength += event.getText().length() - event.getLength();
}
for (int i = 0; i < 500; i++) {
char character = (char) (32 + i % 95);
DocumentEvent event = createRandomEvent(reference, currentLength, character);
currentLength += event.getText().length() - event.getLength();
events.add(event);
}
for (Iterator<DocumentEvent> iterator = events.iterator(); iterator.hasNext(); ) {
DocumentEvent event = iterator.next();
reference.replace(event.getOffset(), event.getLength(), event.getText());
if (Math.random() < 0.3) {
check(reference, testee);
}
}
check(reference, testee);
} catch (BadLocationException e) {
Assert.fail("bad location exception");
}
}
use of org.eclipse.jface.text.BadLocationException in project eclipse.platform.text by eclipse.
the class LinkedModeModelTest method testAddCompatibleGroups.
@Test
public void testAddCompatibleGroups() throws BadLocationException {
IDocument doc1 = new Document(GARTEN1);
// set up linked mode
LinkedPositionGroup group1 = new LinkedPositionGroup();
createLinkedPositions(group1, doc1, "MARGARETE");
LinkedPositionGroup group2 = new LinkedPositionGroup();
createLinkedPositions(group2, doc1, "FAUST");
LinkedModeModel env = new LinkedModeModel();
try {
env.addGroup(group1);
env.addGroup(group2);
} catch (BadLocationException e) {
assertFalse(true);
}
assertUnchanged(group1, group2);
}
Aggregations