Files
openide/python/testSrc/com/jetbrains/commandInterface/commandLine/CommandLineSuggestionTest.java
Alexey Kudravtsev b71ddb3a75 restore file type associations after the test completed to avoid surprising test failures
GitOrigin-RevId: 9fbe29140e3dee42a46ea1a79a9caf3282624cae
2021-04-08 14:55:21 +00:00

67 lines
2.2 KiB
Java

/*
* Copyright 2000-2015 JetBrains s.r.o.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package com.jetbrains.commandInterface.commandLine;
import com.intellij.codeInsight.lookup.LookupElement;
import com.jetbrains.python.fixtures.PyTestCase;
import org.hamcrest.Matchers;
import org.jetbrains.annotations.NotNull;
import org.junit.Assert;
import java.util.HashSet;
import java.util.Set;
/**
* Tests references provide correct suggestions for commands, options and argument in command line
*
* @author Ilya.Kazakevich
*/
public final class CommandLineSuggestionTest extends PyTestCase {
/**
* Ensures suggestions are correct
*/
public void testSuggestions() {
CommandTestTools.initFileType(getTestRootDisposable());
CommandTestTools.createFileByText(myFixture, "command positional_ar --a");
ensureSuggestions("command", "command");
ensureSuggestions("positional_ar", "positional_argument", "--option-no-argument", "--available-option");
ensureSuggestions("--a", "--option-no-argument", "--available-option");
}
/**
* @param initialPositionText place to move cusor to
* @param expectedSuggestions expected suggestions
*/
private void ensureSuggestions(@NotNull final String initialPositionText, final String @NotNull ... expectedSuggestions) {
moveByText(initialPositionText);
final Set<String> completions = new HashSet<>();
for (final LookupElement element : myFixture.completeBasic()) {
completions.add(element.getLookupString());
}
Assert.assertThat("Bad suggestions", completions,
Matchers.containsInAnyOrder(expectedSuggestions));
}
@Override
protected String getTestDataPath() {
return CommandTestTools.TEST_PATH;
}
}