mirror of
https://gitflic.ru/project/openide/openide.git
synced 2026-09-27 10:03:11 +07:00
Spellchecker plugin: fix tests, add TextSplitter improvement - avoid to collect for checking the words with unprintable symbols
This commit is contained in:
@@ -48,7 +48,7 @@ public class TextSplitter {
|
||||
@NonNls
|
||||
private static final Pattern SPECIAL = Pattern.compile("^&\\p{Alnum}{4};");
|
||||
|
||||
private static final String delimiters = ".,;:!?*/&";
|
||||
private static final String delimiters = ".,;:!?*/&\"";
|
||||
|
||||
|
||||
private TextSplitter() {
|
||||
@@ -172,7 +172,13 @@ public class TextSplitter {
|
||||
|
||||
private static void addWord(String text, List<CheckArea> results, boolean flag, TextRange found) {
|
||||
boolean tooShort = (found.getEndOffset() - found.getStartOffset()) <= 3;
|
||||
results.add(new CheckArea(text, found, flag || tooShort));
|
||||
for (int i = found.getStartOffset(); i<found.getEndOffset();i++){
|
||||
if (!Character.isLetter(text.charAt(i)) && text.charAt(i)!='\''){
|
||||
return;
|
||||
}
|
||||
}
|
||||
final CheckArea area = new CheckArea(text, found, flag || tooShort);
|
||||
results.add(area);
|
||||
}
|
||||
|
||||
|
||||
|
||||
@@ -1,2 +1,2 @@
|
||||
def abc(String <TYPO descr="Typo: In word 'dddd'">dddd</TYPO>) {
|
||||
def test(int <TYPO descr="Typo: In word 'dddd'">dddd</TYPO>) {
|
||||
}
|
||||
|
||||
+17
-27
@@ -38,36 +38,30 @@ public class DictionaryTest extends TestCase {
|
||||
private Dictionary dictionary;
|
||||
|
||||
private Map<String, Integer> sizes = new HashMap<String, Integer>();
|
||||
private Map<String, Integer> times = new HashMap<String, Integer>();
|
||||
private Map<String, Integer> times = new HashMap<String, Integer>();
|
||||
private static final String JETBRAINS_DIC = "jetbrains.dic";
|
||||
private static final String ENGLISH_DIC = "english.dic";
|
||||
|
||||
{
|
||||
sizes.put("jetbrains.dic", 1000);
|
||||
sizes.put("english.dic", 140000);
|
||||
sizes.put("russian-utf8.dic", 1200000);
|
||||
sizes.put(JETBRAINS_DIC, 1000);
|
||||
sizes.put(ENGLISH_DIC, 140000);
|
||||
}
|
||||
|
||||
{
|
||||
times.put("jetbrains.dic", 100);
|
||||
times.put("english.dic", 2700);
|
||||
times.put("russian-utf8.dic", 32000);
|
||||
times.put(JETBRAINS_DIC, 100);
|
||||
times.put(ENGLISH_DIC, 3500);
|
||||
}
|
||||
|
||||
public void testDictionary() throws IOException {
|
||||
|
||||
DefaultBundledDictionariesProvider dp = new DefaultBundledDictionariesProvider();
|
||||
final String[] names = dp.getBundledDictionaries();
|
||||
final String[] names = new String[]{JETBRAINS_DIC,ENGLISH_DIC};
|
||||
for (String name : names) {
|
||||
StreamLoader loader = createLoader(name);
|
||||
loadDictionaryTest(loader, sizes.get(name), name);
|
||||
loadHalfDictionaryTest(50000, name);
|
||||
loadDictionaryTest(name, sizes.get(name));
|
||||
loadHalfDictionaryTest(name, 50000);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
public void loadDictionaryTest(final Loader loader, int wordCount, final String name) throws IOException {
|
||||
public void loadDictionaryTest(@NotNull final String name, int wordCount) throws IOException {
|
||||
final Transformation transform = new Transformation();
|
||||
|
||||
final Loader loader = new StreamLoader(DefaultBundledDictionariesProvider.class.getResourceAsStream(name), name);
|
||||
IdeaTestUtil
|
||||
.assertTiming("Dictionary load depends on words count. Approximate word count: " + wordCount + ".", times.get(name), new Runnable() {
|
||||
public void run() {
|
||||
@@ -76,7 +70,7 @@ public class DictionaryTest extends TestCase {
|
||||
});
|
||||
|
||||
final Set<String> wordsToStoreAndCheck = createWordSets(name, 50000, 1).getFirst();
|
||||
IdeaTestUtil.assertTiming("Invoke 'contains' " + wordsToStoreAndCheck.size() + " times", 1000, new Runnable() {
|
||||
IdeaTestUtil.assertTiming("Invoke 'contains' " + wordsToStoreAndCheck.size() + " times", 2000, new Runnable() {
|
||||
public void run() {
|
||||
for (String s : wordsToStoreAndCheck) {
|
||||
assertTrue(dictionary.contains(s));
|
||||
@@ -86,10 +80,6 @@ public class DictionaryTest extends TestCase {
|
||||
|
||||
}
|
||||
|
||||
private static StreamLoader createLoader(String name) {
|
||||
return new StreamLoader(DefaultBundledDictionariesProvider.class.getResourceAsStream(name), name);
|
||||
}
|
||||
|
||||
private static Loader createLoader(final Set<String> words) {
|
||||
return new Loader() {
|
||||
public void load(@NotNull Consumer<String> consumer) {
|
||||
@@ -106,7 +96,7 @@ public class DictionaryTest extends TestCase {
|
||||
|
||||
@SuppressWarnings({"unchecked"})
|
||||
private static Pair<Set<String>, Set<String>> createWordSets(String name, final int maxCount, final int mod) {
|
||||
Loader loader = createLoader(name);
|
||||
Loader loader = new StreamLoader(DefaultBundledDictionariesProvider.class.getResourceAsStream(name), name);
|
||||
final Set<String> wordsToStore = new THashSet<String>();
|
||||
final Set<String> wordsToCheck = new THashSet<String>();
|
||||
final Transformation transform = new Transformation();
|
||||
@@ -135,10 +125,10 @@ public class DictionaryTest extends TestCase {
|
||||
}
|
||||
|
||||
|
||||
public void loadHalfDictionaryTest(final int maxCount, final String name) throws IOException {
|
||||
|
||||
public static void loadHalfDictionaryTest(final String name, final int maxCount) throws IOException {
|
||||
final Pair<Set<String>, Set<String>> sets = createWordSets(name, maxCount, 2);
|
||||
CompressedDictionary dictionary = CompressedDictionary.create(createLoader(sets.getFirst()), new Transformation());
|
||||
final Loader loader = createLoader(sets.getFirst());
|
||||
CompressedDictionary dictionary = CompressedDictionary.create(loader, new Transformation());
|
||||
for (String s : sets.getSecond()) {
|
||||
if (!sets.getFirst().contains(s)) {
|
||||
assertFalse(dictionary.contains(s));
|
||||
|
||||
@@ -174,7 +174,21 @@ public class SplitterTest extends TestCase {
|
||||
String text = "test test";
|
||||
List<CheckArea> checkAreas = TextSplitter.splitText(text);
|
||||
correctListToCheck(checkAreas, text, new String[]{"test", "test"});
|
||||
correctIgnored(checkAreas, text, new String[]{" "});
|
||||
correctIgnored(checkAreas, text, new String[]{});
|
||||
}
|
||||
|
||||
public void testColorUC() {
|
||||
String text = "#AABBFF";
|
||||
List<CheckArea> checkAreas = TextSplitter.splitText(text);
|
||||
correctListToCheck(checkAreas, text, new String[]{});
|
||||
correctIgnored(checkAreas, text, new String[]{});
|
||||
}
|
||||
|
||||
public void testColorLC() {
|
||||
String text = "#fff";
|
||||
List<CheckArea> checkAreas = TextSplitter.splitText(text);
|
||||
correctListToCheck(checkAreas, text, new String[]{});
|
||||
correctIgnored(checkAreas, text, new String[]{});
|
||||
}
|
||||
|
||||
public void testTooShort() {
|
||||
@@ -270,13 +284,12 @@ public class SplitterTest extends TestCase {
|
||||
correctListToCheck(checkAreas, text, new String[]{});
|
||||
}
|
||||
|
||||
public void testNoWordsInHugeBinaryWithXmlFile() {
|
||||
public void testTCData() {
|
||||
final InputStream stream = SplitterTest.class.getResourceAsStream("contents.txt");
|
||||
String text = convertStreamToString(stream);
|
||||
List<CheckArea> checkAreas = TextSplitter.splitText(text);
|
||||
List<String> words = wordsToCheck(checkAreas, text);
|
||||
assertNotNull(words);
|
||||
assertEquals(45284, words.size());
|
||||
assertNull(words);
|
||||
}
|
||||
|
||||
|
||||
|
||||
Binary file not shown.
Reference in New Issue
Block a user