Search in sources :

Example 1 with CompletionType

use of com.intellij.codeInsight.completion.CompletionType in project intellij-community by JetBrains.

the class CompletionTester method doTestVariantsInner.

public void doTestVariantsInner(String fileName, FileType fileType) throws Throwable {
    String fullFileName = myFixture.getTestDataPath() + File.separator + fileName;
    String content = FileUtil.loadFile(new File(fullFileName));
    int index = content.indexOf(getDelimiter());
    assert index > 0;
    String testFileContent = content.substring(0, index);
    String expectedDataContent = content.substring(index + getDelimiter().length());
    myFixture.configureByText(fileType, testFileContent);
    final Scanner in = new Scanner(expectedDataContent);
    final CompletionType type = CompletionType.valueOf(in.next());
    final int count = in.nextInt();
    final CheckType checkType = CheckType.valueOf(in.next());
    in.useDelimiter("\n");
    final List<String> variants = new ArrayList<>();
    while (in.hasNext()) {
        final String variant = in.next().trim();
        if (variant.length() > 0) {
            variants.add(variant);
        }
    }
    myFixture.complete(type, count);
    List<String> stringList = myFixture.getLookupElementStrings();
    if (stringList == null) {
        stringList = Collections.emptyList();
    }
    if (checkType == CheckType.EQUALS) {
        UsefulTestCase.assertOrderedEquals(stringList, variants);
    } else if (checkType == CheckType.INCLUDES) {
        variants.removeAll(stringList);
        assertTrue("Missing variants: " + variants, variants.isEmpty());
    } else if (checkType == CheckType.EXCLUDES) {
        variants.retainAll(stringList);
        assertTrue("Unexpected variants: " + variants, variants.isEmpty());
    }
}
Also used : Scanner(java.util.Scanner) ArrayList(java.util.ArrayList) CompletionType(com.intellij.codeInsight.completion.CompletionType) File(java.io.File)

Aggregations

CompletionType (com.intellij.codeInsight.completion.CompletionType)1 File (java.io.File)1 ArrayList (java.util.ArrayList)1 Scanner (java.util.Scanner)1