summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authormclay2008-11-27 16:04:23 (EST)
committer sefftinge2008-11-27 16:04:23 (EST)
commitbaf15411ca9eda7664ed4fbe73bea36b34b79ec4 (patch)
tree846d093ccdf20547f1925298b068117411862cbf
parentf91081f7ab83bb0203af9bb0a6fd85ab85aea03c (diff)
downloadorg.eclipse.xtext-baf15411ca9eda7664ed4fbe73bea36b34b79ec4.zip
org.eclipse.xtext-baf15411ca9eda7664ed4fbe73bea36b34b79ec4.tar.gz
org.eclipse.xtext-baf15411ca9eda7664ed4fbe73bea36b34b79ec4.tar.bz2
NEW - bug 253707: [UI] Content Assist - Unittests
https://bugs.eclipse.org/bugs/show_bug.cgi?id=253707
-rw-r--r--plugins/org.eclipse.xtext.ui.common/src/org/eclipse/xtext/ui/common/editor/codecompletion/AbstractProposalProvider.java46
-rw-r--r--plugins/org.eclipse.xtext.ui.common/src/org/eclipse/xtext/ui/common/editor/codecompletion/DefaultContentAssistProcessor.java14
-rw-r--r--plugins/org.eclipse.xtext.ui.common/src/org/eclipse/xtext/ui/common/editor/codecompletion/XtextCompletionProposal.java14
-rw-r--r--tests/org.eclipse.xtext.ui.common.tests/src/org/eclipse/xtext/ui/common/editor/codecompletion/ContentAssistProcessorTestBuilder.java225
-rw-r--r--tests/org.eclipse.xtext.ui.common.tests/src/org/eclipse/xtext/ui/common/editor/codecompletion/DefaultContentAssistProcessorTest.java193
5 files changed, 330 insertions, 162 deletions
diff --git a/plugins/org.eclipse.xtext.ui.common/src/org/eclipse/xtext/ui/common/editor/codecompletion/AbstractProposalProvider.java b/plugins/org.eclipse.xtext.ui.common/src/org/eclipse/xtext/ui/common/editor/codecompletion/AbstractProposalProvider.java
index fcb923a..9ea6391 100644
--- a/plugins/org.eclipse.xtext.ui.common/src/org/eclipse/xtext/ui/common/editor/codecompletion/AbstractProposalProvider.java
+++ b/plugins/org.eclipse.xtext.ui.common/src/org/eclipse/xtext/ui/common/editor/codecompletion/AbstractProposalProvider.java
@@ -244,23 +244,47 @@ public abstract class AbstractProposalProvider implements IProposalProvider {
if (model != null) {
- CompositeNode parserNode = NodeUtil.getRootNode(model);
+ // filter by prefix
+ // TODO: this works only if we have access to the corresponding grammarelement
+ if (completionProposal instanceof XtextCompletionProposal) {
- LeafNode currentLeafNode = ParseTreeUtil.getCurrentNodeByOffset(parserNode, offset);
+ XtextCompletionProposal xtextCompletionProposal = (XtextCompletionProposal) completionProposal;
- boolean isCursorAtTheEndOfTheLastElement = offset == (currentLeafNode.getTotalOffset() + currentLeafNode
- .getTotalLength());
+ AbstractElement abstractElement = null;
- if (isCursorAtTheEndOfTheLastElement && completionProposal instanceof XtextCompletionProposal) {
+ if (xtextCompletionProposal.getAbstractElement() instanceof Keyword ||
+ xtextCompletionProposal.getAbstractElement() instanceof CrossReference) {
+ abstractElement = GrammarUtil.containingAssignment(xtextCompletionProposal.getAbstractElement());
+ }
+
+ if (null==abstractElement) {
+ abstractElement = xtextCompletionProposal.getAbstractElement();
+ }
+
+ CompositeNode rootNode = NodeUtil.getRootNode(model);
- XtextCompletionProposal xtextCompletionProposal = (XtextCompletionProposal) completionProposal;
+ AbstractNode lastCompleteNode = ParseTreeUtil.getLastCompleteNodeByOffset(rootNode, offset);
- AbstractElement abstractElement = xtextCompletionProposal.getAbstractElement();
+ LeafNode currentLeafNode = ParseTreeUtil.getCurrentNodeByOffset(rootNode, offset);
- EObject grammarElement = currentLeafNode.getGrammarElement();
- // at the end of the last element we want to filter only the CompletionProposal for the same grammar element
- if (((isCursorAtTheEndOfTheLastElement && abstractElement.equals(grammarElement)) || !isCursorAtTheEndOfTheLastElement)
- && !completionProposal.getDisplayString().startsWith(currentLeafNode.getText())) {
+ EObject grammarElement = GrammarUtil.containingAssignment(currentLeafNode.getGrammarElement());
+
+ if (null==grammarElement) {
+ grammarElement = currentLeafNode.getGrammarElement();
+ }
+
+ boolean atTheEndOfTheLastCompleteNode = currentLeafNode == lastCompleteNode;
+
+ boolean candidateToCompare = false;
+
+ // means if we are at the end of a complete token we want to filter only equal grammarelements (not the 'next' ones)
+ if (atTheEndOfTheLastCompleteNode && abstractElement.equals(grammarElement)) {
+ candidateToCompare = true;
+ } else if (!atTheEndOfTheLastCompleteNode ) {
+ candidateToCompare = true;
+ }
+
+ if ( candidateToCompare && (!"".equals(prefix.trim()) && !completionProposal.getDisplayString().toUpperCase().startsWith(prefix.toUpperCase()))) {
if (logger.isDebugEnabled()) {
logger.debug("filter completionProposal '" + completionProposal + "'");
}
diff --git a/plugins/org.eclipse.xtext.ui.common/src/org/eclipse/xtext/ui/common/editor/codecompletion/DefaultContentAssistProcessor.java b/plugins/org.eclipse.xtext.ui.common/src/org/eclipse/xtext/ui/common/editor/codecompletion/DefaultContentAssistProcessor.java
index 29d06bc..8a08ed6 100644
--- a/plugins/org.eclipse.xtext.ui.common/src/org/eclipse/xtext/ui/common/editor/codecompletion/DefaultContentAssistProcessor.java
+++ b/plugins/org.eclipse.xtext.ui.common/src/org/eclipse/xtext/ui/common/editor/codecompletion/DefaultContentAssistProcessor.java
@@ -18,10 +18,12 @@ import org.eclipse.jface.text.contentassist.IContextInformation;
import org.eclipse.jface.text.contentassist.IContextInformationValidator;
import org.eclipse.swt.custom.StyledText;
import org.eclipse.xtext.AbstractElement;
+import org.eclipse.xtext.Assignment;
import org.eclipse.xtext.CrossReference;
import org.eclipse.xtext.EcoreUtil2;
import org.eclipse.xtext.GrammarUtil;
import org.eclipse.xtext.Keyword;
+import org.eclipse.xtext.RuleCall;
import org.eclipse.xtext.crossref.ILinkingService;
import org.eclipse.xtext.parser.IParseResult;
import org.eclipse.xtext.parsetree.AbstractNode;
@@ -107,9 +109,15 @@ public class DefaultContentAssistProcessor implements IContentAssistProcessor {
* 'right-to-left-backtracking' cases (e.g. for keyword 'kind' kind>|< |=cursorpos)
*/
else if (currentLeafNode == lastCompleteNode) {
- nextValidElementSet = ParseTreeUtil
- .getElementSetValidFromOffset(rootNode, lastCompleteNode, offset);
- nextValidElementSet.add((AbstractElement) lastCompleteNode.getGrammarElement());
+ Assignment containingAssignment = GrammarUtil.containingAssignment(lastCompleteNode.getGrammarElement());
+
+ if (lastCompleteNode.getGrammarElement() instanceof RuleCall && containingAssignment!=null) {
+ nextValidElementSet.add(containingAssignment);
+ nextValidElementSet.addAll(ParseTreeUtil.getElementSetValidFromOffset(rootNode, lastCompleteNode, offset));
+ } else {
+ nextValidElementSet = ParseTreeUtil.getElementSetValidFromOffset(rootNode, lastCompleteNode, offset);
+ nextValidElementSet.add((AbstractElement) lastCompleteNode.getGrammarElement());
+ }
}
else {
nextValidElementSet = ParseTreeUtil
diff --git a/plugins/org.eclipse.xtext.ui.common/src/org/eclipse/xtext/ui/common/editor/codecompletion/XtextCompletionProposal.java b/plugins/org.eclipse.xtext.ui.common/src/org/eclipse/xtext/ui/common/editor/codecompletion/XtextCompletionProposal.java
index e909030..58dc0d1 100644
--- a/plugins/org.eclipse.xtext.ui.common/src/org/eclipse/xtext/ui/common/editor/codecompletion/XtextCompletionProposal.java
+++ b/plugins/org.eclipse.xtext.ui.common/src/org/eclipse/xtext/ui/common/editor/codecompletion/XtextCompletionProposal.java
@@ -217,7 +217,11 @@ public class XtextCompletionProposal implements ICompletionProposal,
IDocument document = viewer.getDocument();
+ int offsetToApply = this.offset;
+
if (model != null) {
+
+
CompositeNode parserNode = NodeUtil.getRootNode(model);
LeafNode currentLeafNode=ParseTreeUtil.getCurrentNodeByOffset(parserNode, offset);
@@ -227,14 +231,14 @@ public class XtextCompletionProposal implements ICompletionProposal,
if ((currentLeafNode.isHidden() && !"".equals(currentLeafNode.getText().trim()))
|| isCursorAtTheEndOfTheLastElement) {
- if (getDisplayString().startsWith(currentLeafNode.getText())) {
- setText(getText().substring(currentLeafNode.getText().length()));
+ if (getDisplayString().toUpperCase().startsWith(currentLeafNode.getText().toUpperCase())) {
+ offsetToApply-=currentLeafNode.getText().trim().length();
}
}
if (!currentLeafNode.isHidden() &&
isCursorAtTheEndOfTheLastElement &&
- getDisplayString().equalsIgnoreCase(getText())) {
+ offsetToApply==offset) {
if (currentLeafNode.getGrammarElement() instanceof CrossReference
&& abstractElement instanceof CrossReference) {
@@ -252,8 +256,8 @@ public class XtextCompletionProposal implements ICompletionProposal,
}
}
- document.replace(this.offset, offset != this.offset ? offset
- - this.offset : 0, getText());
+ document.replace(offsetToApply, offset != offsetToApply ? offset
+ - offsetToApply : 0, getText());
} catch (BadLocationException e) {
logger.error(e);
diff --git a/tests/org.eclipse.xtext.ui.common.tests/src/org/eclipse/xtext/ui/common/editor/codecompletion/ContentAssistProcessorTestBuilder.java b/tests/org.eclipse.xtext.ui.common.tests/src/org/eclipse/xtext/ui/common/editor/codecompletion/ContentAssistProcessorTestBuilder.java
new file mode 100644
index 0000000..b828992
--- /dev/null
+++ b/tests/org.eclipse.xtext.ui.common.tests/src/org/eclipse/xtext/ui/common/editor/codecompletion/ContentAssistProcessorTestBuilder.java
@@ -0,0 +1,225 @@
+/*******************************************************************************
+ * __ ___ _
+ * \ \/ / |_ _____ __ |_
+ * \ /| __/ _ \ \/ / __|
+ * / \| |_ __/> <| |_
+ * /_/\_\\__\___/_/\_\\__|
+ *
+ * Copyright (c) 2008 itemis AG (http://www.itemis.eu) 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
+ *******************************************************************************/
+package org.eclipse.xtext.ui.common.editor.codecompletion;
+
+import static junit.framework.Assert.assertEquals;
+import static junit.framework.Assert.assertTrue;
+import static org.easymock.EasyMock.anyObject;
+import static org.easymock.EasyMock.createMock;
+import static org.easymock.EasyMock.expect;
+import static org.easymock.EasyMock.replay;
+
+import java.io.InputStream;
+import java.util.Arrays;
+
+import org.eclipse.emf.common.util.URI;
+import org.eclipse.emf.ecore.resource.ResourceSet;
+import org.eclipse.jface.text.ITextViewer;
+import org.eclipse.jface.text.contentassist.ICompletionProposal;
+import org.eclipse.jface.text.contentassist.IContentAssistProcessor;
+import org.eclipse.swt.SWT;
+import org.eclipse.swt.custom.StyledText;
+import org.eclipse.swt.widgets.Shell;
+import org.eclipse.xtext.parsetree.CompositeNode;
+import org.eclipse.xtext.resource.IResourceFactory;
+import org.eclipse.xtext.resource.XtextResource;
+import org.eclipse.xtext.resource.XtextResourceSet;
+import org.eclipse.xtext.service.IServiceScope;
+import org.eclipse.xtext.service.ServiceRegistry;
+import org.eclipse.xtext.ui.core.editor.model.IXtextDocument;
+import org.eclipse.xtext.ui.core.editor.model.UnitOfWork;
+import org.eclipse.xtext.util.StringInputStream;
+
+/**
+ * Represents a builder for <code>IContentAssistProcessor</code> tests.
+ *
+ * @author Michael Clay - Initial contribution and API
+ */
+public class ContentAssistProcessorTestBuilder {
+
+ private IContentAssistProcessor contentAssistProcessor;
+ private ITextViewer textViewerMock;
+ private IXtextDocument xtextDocumentMock;
+ private IServiceScope serviceScope;
+ private StringBuilder modelBuilder = new StringBuilder("");
+ private int cursorPosition;
+
+ public ContentAssistProcessorTestBuilder(IServiceScope serviceScope, IContentAssistProcessor contentAssistProcessor) {
+ this.contentAssistProcessor = contentAssistProcessor;
+ this.textViewerMock = createMock(ITextViewer.class);
+ this.xtextDocumentMock = createMock(IXtextDocument.class);
+ this.serviceScope = serviceScope;
+ ServiceRegistry.injectServices(serviceScope, this.contentAssistProcessor);
+ }
+
+ public ContentAssistProcessorTestBuilder set(String model) {
+ this.modelBuilder = new StringBuilder(model);
+ this.cursorPosition = model.length();
+ return this;
+ }
+
+ public ContentAssistProcessorTestBuilder clear(String model) {
+ this.modelBuilder = new StringBuilder("");
+ this.cursorPosition = 0;
+ return this;
+ }
+
+ public ContentAssistProcessorTestBuilder append(String model) {
+ this.modelBuilder.append(model);
+ this.cursorPosition += model.length();
+ return this;
+ }
+
+ public ContentAssistProcessorTestBuilder insert(String model, int cursorPosition) {
+ this.modelBuilder.insert(cursorPosition, model);
+ this.cursorPosition = cursorPosition + model.length();
+ return this;
+ }
+
+ public ContentAssistProcessorTestBuilder delete(int times) {
+ this.modelBuilder.delete(this.cursorPosition - times, this.cursorPosition);
+ this.cursorPosition = this.modelBuilder.length();
+ return this;
+ }
+
+ public ContentAssistProcessorTestBuilder cursorBack(int times) {
+ this.cursorPosition -= times;
+ return this;
+ }
+
+ public ContentAssistProcessorTestBuilder applyText() throws Exception {
+ applyText(0, true);
+ return this;
+ }
+
+ public ContentAssistProcessorTestBuilder applyText(boolean appendSpace) throws Exception {
+ applyText(0, appendSpace);
+ return this;
+ }
+
+ public ContentAssistProcessorTestBuilder applyText(int index, boolean appendSpace) throws Exception {
+ append(computeCompletionProposals(this.modelBuilder.toString(), this.cursorPosition)[index].getDisplayString());
+ if (appendSpace) {
+ append(" ");
+ }
+ return this;
+ }
+
+ public ContentAssistProcessorTestBuilder assertCount(int completionProposalCount) throws Exception {
+ assertCountAtCursorPosition(completionProposalCount, this.cursorPosition);
+ return this;
+ }
+
+ public ContentAssistProcessorTestBuilder assertText(String... expectedText) throws Exception {
+ assertTextAtCursorPosition(this.cursorPosition, expectedText);
+ return this;
+ }
+
+ public ContentAssistProcessorTestBuilder assertTextAtCursorPosition(int cursorPosition, String... expectedText)
+ throws Exception {
+
+ String currentModelToParse = this.modelBuilder.toString();
+
+ ICompletionProposal[] computeCompletionProposals = computeCompletionProposals(currentModelToParse,
+ cursorPosition);
+
+ assertEquals("expect only " + expectedText.length + " CompletionProposal item for model '"
+ + currentModelToParse + "'", expectedText.length, computeCompletionProposals.length);
+
+ for (int i = 0; i < computeCompletionProposals.length; i++) {
+ ICompletionProposal completionProposal = computeCompletionProposals[i];
+ assertTrue("expect completionProposal text '" + completionProposal + "' ", Arrays.asList(expectedText)
+ .contains(completionProposal.getDisplayString()));
+ }
+
+ return this;
+ }
+
+ public ContentAssistProcessorTestBuilder assertCountAtCursorPosition(int completionProposalCount, int cursorPosition)
+ throws Exception {
+
+ String currentModelToParse = this.modelBuilder.toString();
+
+ ICompletionProposal[] computeCompletionProposals = computeCompletionProposals(currentModelToParse,
+ cursorPosition);
+
+ assertEquals("expect only " + completionProposalCount + " CompletionProposal item for model '"
+ + currentModelToParse + "'", completionProposalCount, computeCompletionProposals.length);
+
+ return this;
+ }
+
+ public ICompletionProposal[] computeCompletionProposals(String currentModelToParse, int cursorPosition)
+ throws Exception {
+ CompositeNode rootNode = getRootNode(currentModelToParse);
+
+ org.easymock.EasyMock.reset(textViewerMock, xtextDocumentMock, textViewerMock);
+
+ expect(textViewerMock.getDocument()).andReturn(xtextDocumentMock);
+ expect(xtextDocumentMock.readOnly((UnitOfWork<CompositeNode>) anyObject())).andReturn(rootNode);
+ expect(textViewerMock.getTextWidget()).andReturn(newStyledTextWidgetMock(currentModelToParse));
+
+ replay(textViewerMock, xtextDocumentMock);
+
+ ICompletionProposal[] computeCompletionProposals = this.contentAssistProcessor.computeCompletionProposals(
+ textViewerMock, cursorPosition);
+ return computeCompletionProposals;
+ }
+
+ @Override
+ public String toString() {
+ return this.modelBuilder.toString() + "\n length: " + this.modelBuilder.toString().length() + "\n cursor at: "
+ + this.cursorPosition;
+ }
+
+ private CompositeNode getRootNode(String model) throws Exception {
+ return getRootNode(new StringInputStream(model));
+ }
+
+ private CompositeNode getRootNode(InputStream model) throws Exception {
+ XtextResource resource = getResource(model);
+ return getRootNode(resource);
+ }
+
+ private XtextResource getResource(InputStream in) throws Exception {
+ ResourceSet rs = new XtextResourceSet();
+ XtextResource resource = (XtextResource) rs.createResource(URI.createURI("mytestmodel."
+ + getResourceFactory().getModelFileExtensions()[0]));
+ resource.load(in, null);
+ return resource;
+ }
+
+ private IResourceFactory getResourceFactory() {
+ return ServiceRegistry.getService(this.serviceScope, IResourceFactory.class);
+ }
+
+ private CompositeNode getRootNode(XtextResource resource) {
+ return resource.getParseResult().getRootNode();
+ }
+
+ private StyledText newStyledTextWidgetMock(final String testDslModel) {
+ return new StyledText(new Shell(), SWT.NONE) {
+ @Override
+ public int getCharCount() {
+ return testDslModel.length();
+ }
+
+ @Override
+ public String getText(int start, int end) {
+ return testDslModel.substring(start, end + 1);
+ }
+ };
+ }
+
+}
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 8141d2f..0578cb1 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
@@ -13,30 +13,9 @@
*******************************************************************************/
package org.eclipse.xtext.ui.common.editor.codecompletion;
-import static org.easymock.EasyMock.anyObject;
-import static org.easymock.EasyMock.createMock;
-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;
-import org.eclipse.jface.text.contentassist.ICompletionProposal;
-import org.eclipse.swt.SWT;
-import org.eclipse.swt.custom.StyledText;
-import org.eclipse.swt.widgets.Shell;
-import org.eclipse.xtext.parsetree.CompositeNode;
-import org.eclipse.xtext.service.ServiceRegistry;
import org.eclipse.xtext.testlanguages.ReferenceGrammarStandaloneSetup;
import org.eclipse.xtext.testlanguages.ReferenceGrammarUiConfig;
import org.eclipse.xtext.ui.common.AbstractUiTest;
-import org.eclipse.xtext.ui.core.editor.model.IXtextDocument;
-import org.eclipse.xtext.ui.core.editor.model.UnitOfWork;
/**
@@ -45,144 +24,72 @@ 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
{
- private DefaultContentAssistProcessor defaultContentAssistProcessor;
- private ITextViewer textViewerMock;
- private IXtextDocument xtextDocumentMock;
-
+ private ContentAssistProcessorTestBuilder contentAssistProcessorTestBuilder;
+
@Override
protected void setUp() throws Exception {
super.setUp();
withUi(ReferenceGrammarStandaloneSetup.class,ReferenceGrammarUiConfig.class);
- textViewerMock = createMock(ITextViewer.class);
- xtextDocumentMock = createMock(IXtextDocument.class);
- defaultContentAssistProcessor = new DefaultContentAssistProcessor();
- ServiceRegistry.injectServices(getCurrentServiceScope(), defaultContentAssistProcessor);
+ contentAssistProcessorTestBuilder = new ContentAssistProcessorTestBuilder(getCurrentServiceScope(),new DefaultContentAssistProcessor());
}
public void testComputeCompletionProposalsCount() throws Exception {
-
- Map<String, Integer> model2ExpectedProposalCountMap = new HashMap<String, Integer>();
- StringBuilder modelBuilder = new StringBuilder("");
- model2ExpectedProposalCountMap.put(modelBuilder.toString(), 1);
- model2ExpectedProposalCountMap.put(modelBuilder.append("spielplatz ").toString(), 2);
- model2ExpectedProposalCountMap.put(modelBuilder.append("1 ").toString(), 3);
- model2ExpectedProposalCountMap.put(modelBuilder.append("\"JUNIT\" ").toString(), 1);
- model2ExpectedProposalCountMap.put(modelBuilder.append("{ ").toString(), 5);
- model2ExpectedProposalCountMap.put(modelBuilder.append("kind ").toString(), 1);
- model2ExpectedProposalCountMap.put(modelBuilder.append("(k1 0) erwachsener(e1 0) erwachsener(e2 0) familie( f1 ").toString(),2);
- model2ExpectedProposalCountMap.put(modelBuilder.append("e1 ").toString(),2);
- model2ExpectedProposalCountMap.put(modelBuilder.append("e2 ").toString(),1);
-
- for (Iterator<String> iterator = model2ExpectedProposalCountMap.keySet()
- .iterator(); iterator.hasNext();) {
-
- String testDslModel = iterator.next();
-
- int expectedProposalCount = model2ExpectedProposalCountMap.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 " + expectedProposalCount+ " CompletionProposal item for model '" + testDslModel+ "'",
- expectedProposalCount,
- computeCompletionProposals.length);
- }
-
+ contentAssistProcessorTestBuilder.assertCount(1)
+ .append("spielplatz ").assertCount(2)
+ .append("1 ").assertCount(3)
+ .append("\"JUNIT\" ").assertCount(1)
+ .append("{ ").assertCount(5)
+ .append("kind ").assertCount(1)
+ .append("(k1 0) erwachsener(e1 0) erwachsener(e2 0) familie( f1 ").assertCount(2)
+ .append("e1 ").assertCount(2)
+ .append("e2").assertCount(1);
}
public void testComputeCompletionProposalsText() throws Exception {
+ contentAssistProcessorTestBuilder.assertText("spielplatz ")
+ .applyText().assertText("0","1")
+ .applyText().assertText("\"SpielplatzBeschreibungSTRING\"","\"SpielplatzBeschreibung\"","{")
+ .applyText().assertText("{")
+ .applyText().assertText("erwachsener ","familie ","spielzeug ","kind ","}")
+ .append("erwachsener ").assertText("(")
+ .applyText().assertText("ErwachsenerNameID","ErwachsenerName")
+ .append("e1 ").assertText("0","1")
+ .applyText().assertText(")")
+ .applyText().append("erwachsener (e2 0) kind ").assertText("(")
+ .applyText().assertText("KindNameID","KindName")
+ .append("k1 ").assertText("0","1")
+ .applyText().assertText(")")
+ .applyText().append("kind (k2 0) familie ").assertText("(")
+ .applyText().assertText("keyword ","\"FamilieNameSTRING\"","FamilieNameID")
+ .append("keyword ").assertText("e1","e2")
+ .applyText().assertText("e1","e2")
+ .append("e2 ").assertText("k1","k2")
+ .append("k").assertText("k1","k2",",",")")
+ .append("1 ").assertText(",",")")
+ .append("k2 ").assertText(",",")")
+ ;
- Map<String, List<String>> model2ExpectedProposalTextMap = new HashMap<String, List<String>>();
- StringBuilder modelBuilder = new StringBuilder("");
- model2ExpectedProposalTextMap.put(modelBuilder.toString(), Arrays.asList("spielplatz "));
- model2ExpectedProposalTextMap.put(modelBuilder.append("spielplatz ").toString(), Arrays.asList("0","1"));
- model2ExpectedProposalTextMap.put(modelBuilder.append("1 ").toString(), Arrays.asList("\"SpielplatzBeschreibungSTRING\"","\"SpielplatzBeschreibung\"","{"));
- model2ExpectedProposalTextMap.put(modelBuilder.append("\"SpielplatzBeschreibung\" ").toString(), Arrays.asList("{"));
- model2ExpectedProposalTextMap.put(modelBuilder.append("{ ").toString(), Arrays.asList("erwachsener ","familie ","spielzeug ","kind ","}"));
- model2ExpectedProposalTextMap.put(modelBuilder.append("erwachsener ").toString(), Arrays.asList("("));
- model2ExpectedProposalTextMap.put(modelBuilder.append("( ").toString(), Arrays.asList("ErwachsenerNameID","ErwachsenerName"));
- model2ExpectedProposalTextMap.put(modelBuilder.append("e1 ").toString(), Arrays.asList("0","1"));
- model2ExpectedProposalTextMap.put(modelBuilder.append("0 ").toString(), Arrays.asList(")"));
- modelBuilder.append(")").append("erwachsener (e2 0)");
- model2ExpectedProposalTextMap.put(modelBuilder.append("kind ").toString(), Arrays.asList("("));
- model2ExpectedProposalTextMap.put(modelBuilder.append("( ").toString(), Arrays.asList("KindNameID","KindName"));
- model2ExpectedProposalTextMap.put(modelBuilder.append("k1 ").toString(), Arrays.asList("0","1"));
- model2ExpectedProposalTextMap.put(modelBuilder.append("0 ").toString(), Arrays.asList(")"));
- modelBuilder.append(")").append("kind (k2 0)");
- model2ExpectedProposalTextMap.put(modelBuilder.append("familie ").toString(), Arrays.asList("("));
- model2ExpectedProposalTextMap.put(modelBuilder.append("( ").toString(), Arrays.asList("keyword ","\"FamilieNameSTRING\"","FamilieNameID"));
- model2ExpectedProposalTextMap.put(modelBuilder.append("keyword ").toString(), Arrays.asList("e1","e2"));
- model2ExpectedProposalTextMap.put(modelBuilder.append("e1 ").toString(), Arrays.asList("e1","e2"));
- model2ExpectedProposalTextMap.put(modelBuilder.append("").toString(), Arrays.asList("e1","e2"));
- model2ExpectedProposalTextMap.put(modelBuilder.append("e2 ").toString(), Arrays.asList("k1","k2"));
- model2ExpectedProposalTextMap.put(modelBuilder.append("k").toString(), Arrays.asList("k1","k2",",",")"));
- model2ExpectedProposalTextMap.put(modelBuilder.append("1 ").toString(), Arrays.asList(",",")"));
- model2ExpectedProposalTextMap.put(modelBuilder.append("k2 ").toString(), Arrays.asList(",",")"));
- 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) {
- @Override
- public int getCharCount() {
- return testDslModel.length();
- }
-
- @Override
- public String getText(int start, int end) {
- return testDslModel.substring(start, end);
- }
- };
+ public void testComputeCompletionProposalsIgnoreCase() throws Exception {
+ contentAssistProcessorTestBuilder.set("spielplatz 1 \"SpielplatzBeschreibung\" { kind(k1 0) kind(k2 0) erwachsener(e1 0) erwachsener(e2 0) ")
+ .append(" KI").assertText("kind ").delete(3)
+ .append(" ER").assertText("erwachsener ").delete(3)
+ .append(" SP").assertText("spielzeug ").delete(3)
+ .append(" FA").assertText("familie ").delete(3)
+ .append(" familie ( KEY").assertText("keyword ").delete(13)
+ .append(" familie ( \"").assertText("\"FamilieNameSTRING\"").delete(12)
+ .append(" familie ( K").assertText("keyword ").delete(11)
+ .append(" familie ( keyword E").assertText("e1","e2").delete(19)
+ .append(" familie ( keyword e1 E").assertText("e1","e2").delete(22)
+ .append(" familie ( keyword e1 e2 K").assertText("k1","k2",",",")").delete(25)
+ .append(" familie ( keyword e1 e2 k1,K").assertText("k1","k2",",",")").delete(28)
+ .append(" familie ( keyword e1 e2 k1,k2").assertText("k2",",",")")
+ ;
}
-
+
} \ No newline at end of file