1
0
Fork 0
mirror of https://github.com/eclipse-cdt/cdt synced 2025-07-23 17:05:26 +02:00

Bug 537031 - Test case for cursor position after completing zero-argument function

Change-Id: I55a4580c0746534c391300346df53ad2d0784abe
This commit is contained in:
Nathan Ridge 2018-07-14 02:48:52 -04:00
parent c7ddddc339
commit 836db69fb8
2 changed files with 21 additions and 0 deletions

View file

@ -13,6 +13,7 @@ import static org.eclipse.cdt.ui.tests.text.contentassist2.AbstractContentAssist
import org.eclipse.core.resources.IFile;
import org.eclipse.core.resources.IProject;
import org.eclipse.jface.preference.IPreferenceStore;
import org.eclipse.jface.text.contentassist.ICompletionProposal;
import org.eclipse.cdt.internal.ui.text.contentassist.ContentAssistPreference;
@ -70,6 +71,15 @@ public class CompletionTestBase extends AbstractContentAssistTest {
assertContentAssistResults(fCursorOffset, expected, AbstractContentAssistTest.DEFAULT_FLAGS, CONTEXT);
}
protected void assertCursorPositionsAfterReplacement(int[] expected) throws Exception {
Object[] results = invokeContentAssist(fCursorOffset, 0, true, false, true).results;
assertEquals(expected.length, results.length);
for (int i = 0; i < results.length; ++i) {
assertInstance(results[i], ICompletionProposal.class);
assertEquals(expected[i], ((ICompletionProposal) results[i]).getSelection(getDocument()).x);
}
}
protected void assertDotReplacedWithArrow() throws Exception {
assertEquals("->", getDocument().get(fCursorOffset - 1, 2));
}

View file

@ -2040,4 +2040,15 @@ public class CompletionTests extends CompletionTestBase {
public void testNonTypeTemplateParameterCompletion_522010() throws Exception {
assertCompletionResults(new String[] { "TestParam" });
}
// void find();
// void waldo() {
// fin/*cursor*/
// }
public void testCursorPositionForZeroArgFunction_537031() throws Exception {
// Test that the cursor ends up after the closing parenthesis.
// The 6 below is 4 for "find" + 2 for opening AND closing parentheses.
int expectedPos = getDocument().get().lastIndexOf("fin") + 6;
assertCursorPositionsAfterReplacement(new int[] { expectedPos });
}
}