aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authormclay2008-11-12 16:27:37 (EST)
committersefftinge2008-11-12 16:27:37 (EST)
commitb8e68f9789f585175fc7637f49c77ad5dad6e594 (patch)
tree66ab8d4c35b57852b7c9b29dceca04087ec42b86
parent714b492d6b098165292cad4d3fdd7f905297326d (diff)
downloadorg.eclipse.xtext-b8e68f9789f585175fc7637f49c77ad5dad6e594.zip
org.eclipse.xtext-b8e68f9789f585175fc7637f49c77ad5dad6e594.tar.gz
org.eclipse.xtext-b8e68f9789f585175fc7637f49c77ad5dad6e594.tar.bz2
add: testComputeCompletionProposalsText
-rw-r--r--tests/org.eclipse.xtext.ui.common.tests/src/org/eclipse/xtext/ui/common/AbstractUiTest.java9
-rw-r--r--tests/org.eclipse.xtext.ui.common.tests/src/org/eclipse/xtext/ui/common/editor/codecompletion/DefaultContentAssistProcessorTest.java47
2 files changed, 52 insertions, 4 deletions
diff --git a/tests/org.eclipse.xtext.ui.common.tests/src/org/eclipse/xtext/ui/common/AbstractUiTest.java b/tests/org.eclipse.xtext.ui.common.tests/src/org/eclipse/xtext/ui/common/AbstractUiTest.java
index 8b3ec1e..11d1649 100644
--- a/tests/org.eclipse.xtext.ui.common.tests/src/org/eclipse/xtext/ui/common/AbstractUiTest.java
+++ b/tests/org.eclipse.xtext.ui.common.tests/src/org/eclipse/xtext/ui/common/AbstractUiTest.java
@@ -34,9 +34,12 @@ public class AbstractUiTest extends AbstractGeneratorTest {
Method registrationsMethod = uiConfig.getMethod("registrations");
Set<IServiceRegistration> uiServiceRegistrationSet = (Set<IServiceRegistration>) registrationsMethod
.invoke(uiConfig.newInstance());
- for (IServiceRegistration serviceRegistration : uiServiceRegistrationSet) {
- ServiceRegistry.registerFactory(serviceRegistration.scope(), serviceRegistration.serviceFactory(),
- serviceRegistration.priority());
+ try {
+ for (IServiceRegistration serviceRegistration : uiServiceRegistrationSet) {
+ ServiceRegistry.registerFactory(serviceRegistration.scope(), serviceRegistration.serviceFactory(),
+ serviceRegistration.priority());
+ }
}
+ catch (Exception e) {}
}
}
diff --git a/tests/org.eclipse.xtext.ui.common.tests/src/org/eclipse/xtext/ui/common/editor/codecompletion/DefaultContentAssistProcessorTest.java b/tests/org.eclipse.xtext.ui.common.tests/src/org/eclipse/xtext/ui/common/editor/codecompletion/DefaultContentAssistProcessorTest.java
index ee3c5bb..3fca9a4 100644
--- a/tests/org.eclipse.xtext.ui.common.tests/src/org/eclipse/xtext/ui/common/editor/codecompletion/DefaultContentAssistProcessorTest.java
+++ b/tests/org.eclipse.xtext.ui.common.tests/src/org/eclipse/xtext/ui/common/editor/codecompletion/DefaultContentAssistProcessorTest.java
@@ -19,8 +19,10 @@ import static org.easymock.EasyMock.expect;
import static org.easymock.EasyMock.replay;
import static org.easymock.EasyMock.reset;
+import java.util.Arrays;
import java.util.HashMap;
import java.util.Iterator;
+import java.util.List;
import java.util.Map;
import org.eclipse.jface.text.ITextViewer;
@@ -43,6 +45,7 @@ import org.eclipse.xtext.ui.core.editor.model.UnitOfWork;
* @author Michael Clay - Initial contribution and API
* @see org.eclipse.xtext.ui.common.editor.codecompletion.DefaultContentAssistProcessor
*/
+@SuppressWarnings("unchecked")
public class DefaultContentAssistProcessorTest extends AbstractUiTest
{
@@ -60,7 +63,6 @@ public class DefaultContentAssistProcessorTest extends AbstractUiTest
ServiceRegistry.injectServices(getCurrentServiceScope(), defaultContentAssistProcessor);
}
- @SuppressWarnings("unchecked")
public void testComputeCompletionProposalsCount() throws Exception {
Map<String, Integer> model2ExpectedProposalCountMap = new HashMap<String, Integer>();
@@ -101,6 +103,49 @@ public class DefaultContentAssistProcessorTest extends AbstractUiTest
}
}
+
+ public void testComputeCompletionProposalsText() throws Exception {
+
+ Map<String, List<String>> model2ExpectedProposalTextMap = new HashMap<String, List<String>>();
+ model2ExpectedProposalTextMap.put("", Arrays.asList("spielplatz "));
+ model2ExpectedProposalTextMap.put("spielplatz ", Arrays.asList("0","1"));
+
+ for (Iterator<String> iterator = model2ExpectedProposalTextMap.keySet()
+ .iterator(); iterator.hasNext();) {
+
+ String testDslModel = iterator.next();
+
+ List<String> expectedTextList = model2ExpectedProposalTextMap.get(testDslModel);
+
+ CompositeNode rootNode = getRootNode(testDslModel);
+
+ reset(textViewerMock,xtextDocumentMock,textViewerMock);
+
+ expect(textViewerMock.getDocument()).andReturn(xtextDocumentMock);
+ expect(xtextDocumentMock.readOnly((UnitOfWork<CompositeNode>) anyObject())).andReturn(rootNode);
+ expect(textViewerMock.getTextWidget()).andReturn(newStyledTextWidgetMock(testDslModel));
+
+ replay(textViewerMock,xtextDocumentMock);
+
+ ICompletionProposal[] computeCompletionProposals = defaultContentAssistProcessor
+ .computeCompletionProposals(textViewerMock, testDslModel
+ .length());
+
+ assertEquals("expect only " + expectedTextList.size()+ " CompletionProposal item for model '" + testDslModel+ "'",
+ expectedTextList.size(),
+ computeCompletionProposals.length);
+
+ for (int i = 0; i < computeCompletionProposals.length; i++) {
+ ICompletionProposal completionProposal = computeCompletionProposals[i];
+ assertTrue("expect completionProposal text '"+completionProposal+"' ", expectedTextList.contains(completionProposal.getDisplayString()));
+ }
+
+
+ }
+
+ }
+
+
private StyledText newStyledTextWidgetMock(final String testDslModel) {
return new StyledText(new Shell(), SWT.NONE) {