mirror of
https://gitflic.ru/project/openide/openide.git
synced 2026-02-04 23:39:07 +07:00
Spellchecker: initial spellchecker quickfix tests (ChangeTo)
This commit is contained in:
@@ -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() {
|
||||
|
||||
@@ -0,0 +1 @@
|
||||
<caret>
|
||||
@@ -0,0 +1 @@
|
||||
someСorrectWordsAndTypo
|
||||
@@ -0,0 +1 @@
|
||||
someСorrectWordsAndTyyypo<caret>
|
||||
@@ -0,0 +1 @@
|
||||
typo<caret>
|
||||
@@ -0,0 +1 @@
|
||||
SoomeTypoJooinedTogeether
|
||||
@@ -0,0 +1 @@
|
||||
SoomeTyyypo<caret>JooinedTogeether
|
||||
@@ -0,0 +1 @@
|
||||
some correct words and typo
|
||||
@@ -0,0 +1 @@
|
||||
some correct words and tyyypo<caret>
|
||||
@@ -0,0 +1 @@
|
||||
typo
|
||||
@@ -0,0 +1 @@
|
||||
tyyypo<caret>
|
||||
@@ -0,0 +1 @@
|
||||
someTypoAndСorrectWords
|
||||
@@ -0,0 +1 @@
|
||||
someTyyypo<caret>AndСorrectWords
|
||||
@@ -25,7 +25,7 @@ public abstract class SpellcheckerInspectionTestCase extends LightPlatformCodeIn
|
||||
return true;
|
||||
}
|
||||
|
||||
static String getSpellcheckerTestDataPath() {
|
||||
public static String getSpellcheckerTestDataPath() {
|
||||
return "/spellchecker/testData/";
|
||||
}
|
||||
|
||||
|
||||
@@ -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();
|
||||
}
|
||||
}
|
||||
@@ -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);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user