mirror of
https://github.com/eclipse-cdt/cdt
synced 2025-07-24 09:25:31 +02:00
Add tests for bugs 180885 and 180883
This commit is contained in:
parent
10e8d1fba1
commit
9bce2681b6
4 changed files with 129 additions and 3 deletions
|
@ -20,6 +20,7 @@ import java.util.Set;
|
|||
|
||||
import org.eclipse.core.resources.IFile;
|
||||
import org.eclipse.core.resources.IProject;
|
||||
import org.eclipse.jface.text.IDocument;
|
||||
import org.eclipse.jface.text.contentassist.ContentAssistant;
|
||||
import org.eclipse.jface.text.contentassist.ICompletionProposal;
|
||||
import org.eclipse.jface.text.contentassist.IContextInformation;
|
||||
|
@ -49,8 +50,8 @@ public abstract class AbstractContentAssistTest extends BaseUITestCase {
|
|||
public static final int COMPARE_REP_STRINGS = 2;
|
||||
|
||||
private ICProject fCProject;
|
||||
protected IFile fCFile;
|
||||
private ITextEditor fEditor;
|
||||
private IFile fCFile;
|
||||
protected ITextEditor fEditor;
|
||||
|
||||
private final static Set fgAllKeywords= new HashSet();
|
||||
|
||||
|
@ -213,6 +214,14 @@ public abstract class AbstractContentAssistTest extends BaseUITestCase {
|
|||
* @return the content of the editor buffer
|
||||
*/
|
||||
protected String getBuffer() {
|
||||
return EditorTestHelper.getDocument(fEditor).get();
|
||||
return getDocument().get();
|
||||
}
|
||||
|
||||
/**
|
||||
* @return the editor document
|
||||
*/
|
||||
protected IDocument getDocument() {
|
||||
return EditorTestHelper.getDocument(fEditor);
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -15,6 +15,7 @@ import junit.framework.Test;
|
|||
|
||||
import org.eclipse.core.resources.IFile;
|
||||
import org.eclipse.core.resources.IProject;
|
||||
import org.eclipse.jface.text.IDocument;
|
||||
|
||||
import org.eclipse.cdt.core.testplugin.util.BaseTestCase;
|
||||
|
||||
|
@ -685,4 +686,23 @@ public class CompletionTests extends AbstractContentAssistTest {
|
|||
assertCompletionResults(fCursorOffset, expected,
|
||||
AbstractContentAssistTest.COMPARE_REP_STRINGS);
|
||||
}
|
||||
|
||||
//// to_be_replaced_
|
||||
//void gfunc(){aNew/*cursor*/
|
||||
public void _testGlobalVariableBeforeSave_Bug180883() throws Exception {
|
||||
String replace= "// to_be_replaced_";
|
||||
String globalVar= "int aNewGlobalVar;";
|
||||
IDocument doc= getDocument();
|
||||
int idx= doc.get().indexOf(replace);
|
||||
doc.replace(idx, replace.length(), globalVar);
|
||||
|
||||
// succeeds when buffer is saved
|
||||
// fEditor.doSave(new NullProgressMonitor());
|
||||
// EditorTestHelper.joinBackgroundActivities((AbstractTextEditor)fEditor);
|
||||
|
||||
final String[] expected= {
|
||||
"aNewGlobalVar"
|
||||
};
|
||||
assertCompletionResults(fCursorOffset, expected, AbstractContentAssistTest.COMPARE_ID_STRINGS);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -0,0 +1,96 @@
|
|||
/*******************************************************************************
|
||||
* Copyright (c) 2007 Wind River Systems, Inc. and others.
|
||||
* All rights reserved. This program and the accompanying materials
|
||||
* are made available under the terms of the Eclipse Public License v1.0
|
||||
* which accompanies this distribution, and is available at
|
||||
* http://www.eclipse.org/legal/epl-v10.html
|
||||
*
|
||||
* Contributors:
|
||||
* Anton Leherbauer (Wind River Systems) - initial API and implementation
|
||||
*******************************************************************************/
|
||||
|
||||
package org.eclipse.cdt.ui.tests.text.contentassist2;
|
||||
|
||||
import junit.framework.Test;
|
||||
|
||||
import org.eclipse.core.resources.IFile;
|
||||
import org.eclipse.core.resources.IProject;
|
||||
|
||||
import org.eclipse.cdt.core.testplugin.util.BaseTestCase;
|
||||
|
||||
/**
|
||||
* Completion tests for plain C.
|
||||
*
|
||||
* @since 4.0
|
||||
*/
|
||||
public class CompletionTests_PlainC extends AbstractContentAssistTest {
|
||||
|
||||
private static final String HEADER_FILE_NAME = "CompletionTest.h";
|
||||
private static final String SOURCE_FILE_NAME = "CompletionTest.c";
|
||||
private static final String CURSOR_LOCATION_TAG = "/*cursor*/";
|
||||
|
||||
protected int fCursorOffset;
|
||||
|
||||
//{CompletionTest.h}
|
||||
//int gGlobalInt;
|
||||
|
||||
public static Test suite() {
|
||||
return BaseTestCase.suite(CompletionTests_PlainC.class, "_");
|
||||
}
|
||||
|
||||
/**
|
||||
* @param name
|
||||
*/
|
||||
public CompletionTests_PlainC(String name) {
|
||||
super(name);
|
||||
}
|
||||
|
||||
/*
|
||||
* @see org.eclipse.cdt.ui.tests.text.contentassist2.AbstractContentAssistTest#setUpProjectContent(org.eclipse.core.resources.IProject)
|
||||
*/
|
||||
protected IFile setUpProjectContent(IProject project) throws Exception {
|
||||
String headerContent= readTaggedComment(HEADER_FILE_NAME);
|
||||
StringBuffer sourceContent= getContentsForTest(1)[0];
|
||||
sourceContent.insert(0, "#include \""+HEADER_FILE_NAME+"\"\n");
|
||||
fCursorOffset= sourceContent.indexOf(CURSOR_LOCATION_TAG);
|
||||
assertTrue("No cursor location specified", fCursorOffset >= 0);
|
||||
sourceContent.delete(fCursorOffset, fCursorOffset+CURSOR_LOCATION_TAG.length());
|
||||
assertNotNull(createFile(project, HEADER_FILE_NAME, headerContent));
|
||||
return createFile(project, SOURCE_FILE_NAME, sourceContent.toString());
|
||||
}
|
||||
|
||||
protected void assertCompletionResults(String[] expected) throws Exception {
|
||||
assertContentAssistResults(fCursorOffset, expected, true, AbstractContentAssistTest.COMPARE_ID_STRINGS);
|
||||
}
|
||||
|
||||
//void test() {
|
||||
// int myvar;
|
||||
// (my/*cursor*/
|
||||
public void _testLocalVariableAfterOpeningParen_Bug180885() throws Exception {
|
||||
final String[] expected= {
|
||||
"myvar"
|
||||
};
|
||||
assertCompletionResults(expected);
|
||||
}
|
||||
|
||||
//void test() {
|
||||
// int myvar;
|
||||
// int x = my/*cursor*/
|
||||
public void testLocalVariableInAssignment() throws Exception {
|
||||
final String[] expected= {
|
||||
"myvar"
|
||||
};
|
||||
assertCompletionResults(expected);
|
||||
}
|
||||
|
||||
//void test() {
|
||||
// int myvar;
|
||||
// my/*cursor*/
|
||||
public void testLocalVariableOnLHS() throws Exception {
|
||||
final String[] expected= {
|
||||
"myvar"
|
||||
};
|
||||
assertCompletionResults(expected);
|
||||
}
|
||||
|
||||
}
|
|
@ -67,6 +67,7 @@ public class ContentAssist2TestSuite extends TestSuite {
|
|||
addTest(CompletionTest_VariableType_Prefix.suite());
|
||||
|
||||
addTest(CompletionTests.suite());
|
||||
addTest(CompletionTests_PlainC.suite());
|
||||
addTest(ParameterHintTests.suite());
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Add table
Reference in a new issue