Spellchecker: initial spellchecker quickfix tests (ChangeTo)

This commit is contained in:
Olga Strizhenko
2017-08-17 18:23:20 +03:00
parent 68113568bd
commit 0a0c3c93a4
16 changed files with 143 additions and 1 deletions

View File

@@ -35,10 +35,16 @@ import java.util.List;
public class ChangeTo extends ShowSuggestions implements SpellCheckerQuickFix {
public static final String FIX_NAME = "ChangeTo";
public ChangeTo(String wordWithTypo) {
super(wordWithTypo);
}
@NotNull
public String getName() {
return FIX_NAME;
}
@NotNull
public String getFamilyName() {

View File

@@ -0,0 +1 @@
<caret>

View File

@@ -0,0 +1 @@
someСorrectWordsAndTypo

View File

@@ -0,0 +1 @@
someСorrectWordsAndTyyypo<caret>

View File

@@ -0,0 +1 @@
typo<caret>

View File

@@ -0,0 +1 @@
SoomeTypoJooinedTogeether

View File

@@ -0,0 +1 @@
SoomeTyyypo<caret>JooinedTogeether

View File

@@ -0,0 +1 @@
some correct words and typo

View File

@@ -0,0 +1 @@
some correct words and tyyypo<caret>

View File

@@ -0,0 +1 @@
tyyypo<caret>

View File

@@ -0,0 +1 @@
someTypoAndСorrectWords

View File

@@ -0,0 +1 @@
someTyyypo<caret>AndСorrectWords

View File

@@ -25,7 +25,7 @@ public abstract class SpellcheckerInspectionTestCase extends LightPlatformCodeIn
return true;
}
static String getSpellcheckerTestDataPath() {
public static String getSpellcheckerTestDataPath() {
return "/spellchecker/testData/";
}

View File

@@ -0,0 +1,72 @@
/*
* Copyright 2000-2017 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.intellij.spellchecker.inspection.quickfixes;
import com.intellij.codeInsight.intention.IntentionAction;
import com.intellij.codeInsight.lookup.Lookup;
import com.intellij.codeInsight.lookup.LookupElement;
import com.intellij.codeInsight.lookup.LookupManager;
import com.intellij.codeInsight.lookup.impl.LookupImpl;
import com.intellij.spellchecker.inspection.SpellcheckerInspectionTestCase;
import com.intellij.spellchecker.inspections.SpellCheckingInspection;
import com.intellij.spellchecker.quickfixes.ChangeTo;
import java.io.File;
public abstract class AbstractSpellCheckerFixesTest extends SpellcheckerInspectionTestCase {
protected abstract String getExtension();
@Override
protected String getBasePath() {
return getSpellcheckerTestDataPath() + "inspection" + File.separator + "quickfixes";
}
private void doChangeToTest(int toSelect) {
myFixture.configureByFile(getBeforeFile());
myFixture.enableInspections(SpellCheckingInspection.class);
final IntentionAction intention = myFixture.findSingleIntention(ChangeTo.FIX_NAME);
assertNotNull("cannot find quick fix", intention);
myFixture.launchAction(intention);
selectLookupElement(toSelect);
myFixture.checkResultByFile(getResultFile());
}
private void selectLookupElement(int i) {
final LookupElement[] elements = myFixture.getLookupElements();
final LookupImpl lookup = (LookupImpl)LookupManager.getInstance(getProject()).getActiveLookup();
lookup.setCurrentItem(elements[i]);
lookup.finishLookup(Lookup.NORMAL_SELECT_CHAR);
}
protected void doNoQuickFixTest(String quickfix) {
myFixture.configureByFile(getBeforeFile());
myFixture.enableInspections(SpellCheckingInspection.class);
assertNull(myFixture.getAvailableIntention(quickfix));
}
protected void doChangeToTest() {
doChangeToTest(0);
}
private String getResultFile() {
return getTestName(true) + ".after" + getExtension();
}
private String getBeforeFile() {
return getTestDataPath() + File.separator + getTestName(true) + getExtension();
}
}

View File

@@ -0,0 +1,52 @@
/*
* Copyright 2000-2017 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.intellij.spellchecker.inspection.quickfixes;
import com.intellij.spellchecker.quickfixes.ChangeTo;
public class PlainTextSpellCheckerFixesTest extends AbstractSpellCheckerFixesTest {
protected String getExtension() {
return ".txt";
}
public void testSimpleWordChangeTo() {
doChangeToTest();
}
public void testSeveralWordsChangeTo() {
doChangeToTest();
}
public void testJoinedWordsChangeTo() {
doChangeToTest();
}
public void testTypoInsideJoinedWordsChangeTo() {
doChangeToTest();
}
public void testSeveralJoinedTyposChangeTo() {
doChangeToTest();
}
public void testNoTypoChangeTo() {
doNoQuickFixTest(ChangeTo.FIX_NAME);
}
public void testEmptyChangeTo() {
doNoQuickFixTest(ChangeTo.FIX_NAME);
}
}