1 package com
.intellij
.codeInsight
.completion
;
3 import com
.intellij
.codeInsight
.lookup
.LookupElement
;
4 import com
.intellij
.codeInsight
.lookup
.LookupManager
;
5 import com
.intellij
.codeInsight
.lookup
.impl
.LookupImpl
;
6 import com
.intellij
.testFramework
.LightCodeInsightTestCase
;
7 import com
.intellij
.psi
.statistics
.impl
.StatisticsManagerImpl
;
8 import com
.intellij
.psi
.statistics
.StatisticsManager
;
9 import org
.jetbrains
.annotations
.NonNls
;
11 import java
.util
.Arrays
;
16 public abstract class LightCompletionTestCase
extends LightCodeInsightTestCase
{
17 protected String myPrefix
;
18 protected LookupElement
[] myItems
;
19 private CompletionType myType
= CompletionType
.BASIC
;
22 protected void setUp() throws Exception
{
24 ((StatisticsManagerImpl
)StatisticsManager
.getInstance()).clearStatistics();
27 protected void tearDown() throws Exception
{
28 LookupManager
.getInstance(getProject()).hideActiveLookup();
32 protected void configureByFile(String filePath
) throws Exception
{
33 super.configureByFile(filePath
);
38 protected void configureByFileNoComplete(String filePath
) throws Exception
{
39 super.configureByFile(filePath
);
42 protected void complete() {
46 protected void complete(final int time
) {
47 new CodeCompletionHandlerBase(myType
).invokeCompletion(getProject(), getEditor(), getFile(), time
);
49 LookupImpl lookup
= (LookupImpl
)LookupManager
.getActiveLookup(myEditor
);
50 myItems
= lookup
== null ?
null : lookup
.getItems().toArray(LookupElement
.EMPTY_ARRAY
);
51 myPrefix
= lookup
== null ?
null : lookup
.getItems().get(0).getPrefixMatcher().getPrefix();
54 public void setType(CompletionType type
) {
58 protected void selectItem(LookupElement item
) {
59 selectItem(item
, (char)0);
62 protected void selectItem(LookupElement item
, char completionChar
) {
63 final LookupImpl lookup
= (LookupImpl
)LookupManager
.getInstance(getProject()).getActiveLookup();
64 lookup
.setCurrentItem(item
);
65 if (completionChar
== 0 || completionChar
== '\n' || completionChar
== '\t') {
66 lookup
.finishLookup(completionChar
);
72 protected void testByCount(int finalCount
, @NonNls String
... values
) {
73 if (myItems
== null) {
74 assertEquals(0, finalCount
);
78 for (final LookupElement myItem
: myItems
) {
79 for (String value
: values
) {
81 assertFalse("Unacceptable value reached: " + myItem
.getLookupString(), true);
83 if (value
.equals(myItem
.getLookupString())) {
89 assertEquals(finalCount
, index
);
92 protected void assertStringItems(@NonNls String
... items
) {
93 assertEquals(Arrays
.asList(myItems
).toString(), items
.length
, myItems
.length
);
94 for (int i
= 0; i
< myItems
.length
; i
++) {
95 LookupElement item
= myItems
[i
];
96 assertEquals(items
[i
], item
.getLookupString());
100 protected static LookupImpl
getLookup() {
101 return (LookupImpl
)LookupManager
.getActiveLookup(myEditor
);