Added tests for existing inspections

GitOrigin-RevId: a296390121a24397e7568709f2bdd8aa47bcc716
This commit is contained in:
marcelhillesheim
2021-10-15 17:46:30 +02:00
committed by intellij-monorepo-bot
parent 6b390f21ea
commit 90369b34dc
5 changed files with 65 additions and 0 deletions
@@ -15,6 +15,14 @@ import ru.adelf.idea.dotenv.psi.DotEnvFile;
import java.util.*;
public class DuplicateKeyInspection extends LocalInspectionTool {
// Change the display name within the plugin.xml
// This needs to be here as otherwise the tests will throw errors.
@NotNull
@Override
public String getDisplayName() {
return "Duplicate Key";
}
@Override
public boolean runForWholeFile() {
return true;
@@ -16,6 +16,13 @@ import ru.adelf.idea.dotenv.psi.DotEnvTypes;
import ru.adelf.idea.dotenv.psi.DotEnvValue;
public class SpaceInsideNonQuotedInspection extends LocalInspectionTool {
// Change the display name within the plugin.xml
// This needs to be here as otherwise the tests will throw errors.
@NotNull
@Override
public String getDisplayName() {
return "Space inside non-quoted value";
}
private AddQuotesQuickFix addQuotesQuickFix = new AddQuotesQuickFix();
@@ -86,6 +86,7 @@
<lang.parserDefinition language="DotEnv" implementationClass="ru.adelf.idea.dotenv.DotEnvParserDefinition"/>
<lang.commenter language="DotEnv" implementationClass="ru.adelf.idea.dotenv.extension.DotEnvCommenter"/>
<!-- displayName defined within class otherwise test will throw errors -->
<localInspection language="DotEnv"
groupName="DotEnv"
shortName="DotEnvDuplicateKeyInspection"
@@ -94,6 +95,7 @@
level="WARNING"
implementationClass="ru.adelf.idea.dotenv.inspections.DuplicateKeyInspection"/>
<!-- displayName defined within class otherwise test will throw errors -->
<localInspection language="DotEnv"
groupName="DotEnv"
shortName="DotEnvSpaceInsideNonQuotedInspection"
@@ -0,0 +1,44 @@
package ru.adelf.idea.dotenv.tests.dotenv;
import com.intellij.codeInsight.daemon.impl.HighlightInfo;
import com.intellij.codeInspection.InspectionProfileEntry;
import ru.adelf.idea.dotenv.inspections.DuplicateKeyInspection;
import ru.adelf.idea.dotenv.inspections.SpaceInsideNonQuotedInspection;
import ru.adelf.idea.dotenv.tests.DotEnvLightCodeInsightFixtureTestCase;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collections;
import java.util.List;
public class InspectionsTest extends DotEnvLightCodeInsightFixtureTestCase {
@Override
public void setUp() throws Exception {
super.setUp();
myFixture.configureFromExistingVirtualFile(myFixture.copyFileToProject("inspections.env"));
}
protected String getTestDataPath() {
return basePath + "dotenv/fixtures";
}
public void testDuplicateKey() {
doInspectionTest(new DuplicateKeyInspection(), Arrays.asList("DUPLICATE_KEY=test", "DUPLICATE_KEY=test2"));
}
public void testSpaceInsideNonQuoted() {
doInspectionTest(new SpaceInsideNonQuotedInspection(), Collections.singletonList("spaces without quotes"));
}
private void doInspectionTest(InspectionProfileEntry entry, List<String> expectedHighlightedText) {
myFixture.enableInspections(entry);
List<HighlightInfo> highlightInfoList = myFixture.doHighlighting();
List<String> actualHighlightedText = new ArrayList<>();
highlightInfoList.forEach( highlightInfo -> actualHighlightedText.add(highlightInfo.getText()));
assertEquals(actualHighlightedText, expectedHighlightedText);
}
}
@@ -0,0 +1,4 @@
DUPLICATE_KEY=test
DUPLICATE_KEY=test2
SPACE_INSIDE_NON_QUOTED=spaces without quotes