mirror of
https://gitflic.ru/project/openide/openide.git
synced 2026-09-27 10:03:11 +07:00
refactored SplitterTest, got rid of CheckArea completely
This commit is contained in:
@@ -24,7 +24,6 @@ import org.jetbrains.annotations.Nullable;
|
||||
import java.text.CharacterIterator;
|
||||
import java.text.StringCharacterIterator;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collections;
|
||||
import java.util.List;
|
||||
import java.util.regex.Matcher;
|
||||
import java.util.regex.Pattern;
|
||||
@@ -84,20 +83,6 @@ public abstract class BaseSplitter implements Splitter {
|
||||
return TextRange.from(range.getStartOffset() + start, end - start);
|
||||
}
|
||||
|
||||
public List<CheckArea> split(@Nullable final String text) {
|
||||
if (text == null) {
|
||||
return Collections.emptyList();
|
||||
}
|
||||
final List<CheckArea> result = new ArrayList<CheckArea>();
|
||||
split(text, new TextRange(0, text.length()), new Consumer<TextRange>() {
|
||||
@Override
|
||||
public void consume(TextRange textRange) {
|
||||
result.add(new CheckArea(text, textRange));
|
||||
}
|
||||
});
|
||||
return result;
|
||||
}
|
||||
|
||||
protected static boolean tooSmall(int from, int till) {
|
||||
return till - from <= MIN_RANGE_LENGTH;
|
||||
}
|
||||
|
||||
@@ -1,45 +0,0 @@
|
||||
/*
|
||||
* Copyright 2000-2009 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.inspections;
|
||||
|
||||
import com.intellij.openapi.util.TextRange;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
|
||||
public class CheckArea {
|
||||
|
||||
private final String text;
|
||||
private final TextRange textRange;
|
||||
|
||||
public CheckArea(String text, TextRange range) {
|
||||
this.text = text;
|
||||
textRange = range;
|
||||
}
|
||||
|
||||
public TextRange getTextRange() {
|
||||
return textRange;
|
||||
}
|
||||
|
||||
@Nullable
|
||||
public String getWord() {
|
||||
if (text == null || textRange == null) return null;
|
||||
return textRange.substring(text);
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return "CheckArea{range = " + textRange + ", word=" + (getWord() != null ? getWord() : "") + '}';
|
||||
}
|
||||
}
|
||||
+74
-136
@@ -15,12 +15,13 @@
|
||||
*/
|
||||
package com.intellij.spellchecker.inspector;
|
||||
|
||||
import com.intellij.spellchecker.inspections.CheckArea;
|
||||
import com.intellij.openapi.util.TextRange;
|
||||
import com.intellij.spellchecker.inspections.Splitter;
|
||||
import com.intellij.spellchecker.inspections.SplitterFactory;
|
||||
import com.intellij.util.Consumer;
|
||||
import junit.framework.Assert;
|
||||
import junit.framework.TestCase;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
|
||||
import java.io.BufferedReader;
|
||||
import java.io.IOException;
|
||||
@@ -36,399 +37,336 @@ public class SplitterTest extends TestCase {
|
||||
|
||||
public void testSplitSimpleCamelCase() {
|
||||
String text = "simpleCamelCase";
|
||||
List<CheckArea> checkAreas = SplitterFactory.getInstance().getIdentifierSplitter().split(text);
|
||||
correctListToCheck(checkAreas, text, new String[]{"simple", "Camel", "Case"});
|
||||
correctListToCheck(SplitterFactory.getInstance().getIdentifierSplitter(), text, "simple", "Camel", "Case");
|
||||
}
|
||||
|
||||
public void testSplitCamelCaseWithUpperCasedWord() {
|
||||
String text = "camelCaseJSP";
|
||||
List<CheckArea> checkAreas = SplitterFactory.getInstance().getIdentifierSplitter().split(text);
|
||||
correctListToCheck(checkAreas, text, new String[]{"camel", "Case"});
|
||||
correctListToCheck(SplitterFactory.getInstance().getIdentifierSplitter(), text, "camel", "Case");
|
||||
}
|
||||
|
||||
public void testArrays() {
|
||||
String text = "Token[]";
|
||||
List<CheckArea> checkAreas = SplitterFactory.getInstance().getIdentifierSplitter().split(text);
|
||||
correctListToCheck(checkAreas, text, new String[]{"Token"});
|
||||
correctListToCheck(SplitterFactory.getInstance().getIdentifierSplitter(), text, "Token");
|
||||
}
|
||||
|
||||
public void testIdentifierInSingleQuotes() {
|
||||
String text = "'fill'";
|
||||
List<CheckArea> checkAreas = SplitterFactory.getInstance().getIdentifierSplitter().split(text);
|
||||
correctListToCheck(checkAreas, text, new String[]{"fill"});
|
||||
correctListToCheck(SplitterFactory.getInstance().getIdentifierSplitter(), text, "fill");
|
||||
}
|
||||
|
||||
|
||||
public void testWordsInSingleQuotesWithSep() {
|
||||
String text = "'test-something'";
|
||||
List<CheckArea> checkAreas = SplitterFactory.getInstance().getStringLiteralSplitter().split(text);
|
||||
correctListToCheck(checkAreas, text, new String[]{"test", "something"});
|
||||
correctListToCheck(SplitterFactory.getInstance().getStringLiteralSplitter(), text, "test", "something");
|
||||
}
|
||||
|
||||
public void testComplexWordsInQuotes() {
|
||||
String text = "\"test-customer's'\"";
|
||||
List<CheckArea> checkAreas = SplitterFactory.getInstance().getPlainTextSplitter().split(text);
|
||||
correctListToCheck(checkAreas, text, new String[]{"test", "customer's"});
|
||||
correctListToCheck(SplitterFactory.getInstance().getPlainTextSplitter(), text, "test", "customer's");
|
||||
}
|
||||
|
||||
public void testCapitalizedWithShortWords() {
|
||||
String text = "IntelliJ";
|
||||
List<CheckArea> checkAreas = SplitterFactory.getInstance().getIdentifierSplitter().split(text);
|
||||
correctListToCheck(checkAreas, text, new String[]{"Intelli"});
|
||||
correctListToCheck(SplitterFactory.getInstance().getIdentifierSplitter(), text, "Intelli");
|
||||
}
|
||||
|
||||
public void testWords() {
|
||||
String text = "first-last";
|
||||
List<CheckArea> checkAreas = SplitterFactory.getInstance().getIdentifierSplitter().split(text);
|
||||
correctListToCheck(checkAreas, text, new String[]{"first", "last"});
|
||||
correctListToCheck(SplitterFactory.getInstance().getIdentifierSplitter(), text, "first", "last");
|
||||
}
|
||||
|
||||
public void testCapitalizedWithShortAndLongWords() {
|
||||
String text = "IntelliJTestTest";
|
||||
List<CheckArea> checkAreas = SplitterFactory.getInstance().getIdentifierSplitter().split(text);
|
||||
correctListToCheck(checkAreas, text, new String[]{"Intelli", "Test", "Test"});
|
||||
correctListToCheck(SplitterFactory.getInstance().getIdentifierSplitter(), text, "Intelli", "Test", "Test");
|
||||
}
|
||||
|
||||
public void testWordWithApostrophe1() {
|
||||
String text = "don't check";
|
||||
List<CheckArea> checkAreas = SplitterFactory.getInstance().getStringLiteralSplitter().split(text);
|
||||
correctListToCheck(checkAreas, text, new String[]{"don't", "check"});
|
||||
correctListToCheck(SplitterFactory.getInstance().getStringLiteralSplitter(), text, "don't", "check");
|
||||
}
|
||||
|
||||
public void testHexInPlainText() {
|
||||
String text = "some text 0xacvfgt";
|
||||
List<CheckArea> checkAreas = SplitterFactory.getInstance().getPlainTextSplitter().split(text);
|
||||
correctListToCheck(checkAreas, text, new String[]{"some", "text"});
|
||||
correctListToCheck(SplitterFactory.getInstance().getPlainTextSplitter(), text, "some", "text");
|
||||
}
|
||||
|
||||
public void testHexInStringLiteral() {
|
||||
String text = "qwerty 0x12acfgt test";
|
||||
List<CheckArea> checkAreas = SplitterFactory.getInstance().getStringLiteralSplitter().split(text);
|
||||
correctListToCheck(checkAreas, text, new String[]{"qwerty", "test"});
|
||||
correctListToCheck(SplitterFactory.getInstance().getStringLiteralSplitter(), text, "qwerty", "test");
|
||||
}
|
||||
|
||||
|
||||
public void testHex() {
|
||||
String text = "0xacvfgt";
|
||||
List<CheckArea> checkAreas = SplitterFactory.getInstance().getWordSplitter().split(text);
|
||||
correctListToCheck(checkAreas, text, new String[]{});
|
||||
correctListToCheck(SplitterFactory.getInstance().getWordSplitter(), text);
|
||||
}
|
||||
|
||||
public void testCheckXmlIgnored() {
|
||||
String text = "abcdef" + new String(new char[]{0xDC00}) + "test";
|
||||
List<CheckArea> checkAreas = SplitterFactory.getInstance().getPlainTextSplitter().split(text);
|
||||
correctListToCheck(checkAreas, text, new String[]{});
|
||||
correctListToCheck(SplitterFactory.getInstance().getPlainTextSplitter(), text);
|
||||
}
|
||||
|
||||
public void testIdentifiersWithNumbers() {
|
||||
String text = "result1";
|
||||
List<CheckArea> checkAreas = SplitterFactory.getInstance().getIdentifierSplitter().split(text);
|
||||
correctListToCheck(checkAreas, text, new String[]{"result"});
|
||||
correctListToCheck(SplitterFactory.getInstance().getIdentifierSplitter(), text, "result");
|
||||
}
|
||||
|
||||
public void testIdentifiersWithNumbersInside() {
|
||||
public void testIdentifiersWithNumbersInside() {
|
||||
String text = "result1result";
|
||||
List<CheckArea> checkAreas = SplitterFactory.getInstance().getIdentifierSplitter().split(text);
|
||||
correctListToCheck(checkAreas, text, new String[]{"result","result"});
|
||||
correctListToCheck(SplitterFactory.getInstance().getIdentifierSplitter(), text, "result","result");
|
||||
}
|
||||
|
||||
public void testWordWithApostrophe2() {
|
||||
String text = "customers'";
|
||||
List<CheckArea> checkAreas = SplitterFactory.getInstance().getStringLiteralSplitter().split(text);
|
||||
correctListToCheck(checkAreas, text, new String[]{"customers"});
|
||||
correctListToCheck(SplitterFactory.getInstance().getStringLiteralSplitter(), text, "customers");
|
||||
}
|
||||
|
||||
public void testWordWithApostrophe3() {
|
||||
String text = "customer's";
|
||||
List<CheckArea> checkAreas = SplitterFactory.getInstance().getStringLiteralSplitter().split(text);
|
||||
correctListToCheck(checkAreas, text, new String[]{"customer's"});
|
||||
correctListToCheck(SplitterFactory.getInstance().getStringLiteralSplitter(), text, "customer's");
|
||||
}
|
||||
|
||||
|
||||
public void testWordWithApostrophe4() {
|
||||
String text = "we'll";
|
||||
List<CheckArea> checkAreas = SplitterFactory.getInstance().getStringLiteralSplitter().split(text);
|
||||
correctListToCheck(checkAreas, text, new String[]{"we'll"});
|
||||
correctListToCheck(SplitterFactory.getInstance().getStringLiteralSplitter(), text, "we'll");
|
||||
}
|
||||
|
||||
public void testWordWithApostrophe5() {
|
||||
String text = "I'm you're we'll";
|
||||
List<CheckArea> checkAreas = SplitterFactory.getInstance().getStringLiteralSplitter().split(text);
|
||||
correctListToCheck(checkAreas, text, new String[]{"you're", "we'll"});
|
||||
correctListToCheck(SplitterFactory.getInstance().getStringLiteralSplitter(), text, "you're", "we'll");
|
||||
}
|
||||
|
||||
public void testConstantName() {
|
||||
String text = "TEST_CONSTANT";
|
||||
List<CheckArea> checkAreas = SplitterFactory.getInstance().getIdentifierSplitter().split(text);
|
||||
correctListToCheck(checkAreas, text, new String[]{"TEST", "CONSTANT"});
|
||||
correctListToCheck(SplitterFactory.getInstance().getIdentifierSplitter(), text, "TEST", "CONSTANT");
|
||||
|
||||
}
|
||||
|
||||
public void testLongConstantName() {
|
||||
String text = "TEST_VERY_VERY_LONG_AND_COMPLEX_CONSTANT";
|
||||
List<CheckArea> checkAreas = SplitterFactory.getInstance().getIdentifierSplitter().split(text);
|
||||
correctListToCheck(checkAreas, text, new String[]{"TEST", "VERY", "VERY", "LONG", "COMPLEX", "CONSTANT"});
|
||||
correctListToCheck(SplitterFactory.getInstance().getIdentifierSplitter(), text, "TEST", "VERY", "VERY", "LONG", "COMPLEX", "CONSTANT");
|
||||
|
||||
}
|
||||
|
||||
public void testJavaComments() {
|
||||
String text = "/*special symbols*/";
|
||||
List<CheckArea> checkAreas = SplitterFactory.getInstance().getCommentSplitter().split(text);
|
||||
correctListToCheck(checkAreas, text, new String[]{"special", "symbols"});
|
||||
correctListToCheck(SplitterFactory.getInstance().getCommentSplitter(), text, "special", "symbols");
|
||||
|
||||
}
|
||||
|
||||
|
||||
public void testXmlComments() {
|
||||
String text = "<!--special symbols-->";
|
||||
List<CheckArea> checkAreas = SplitterFactory.getInstance().getCommentSplitter().split(text);
|
||||
correctListToCheck(checkAreas, text, new String[]{"special", "symbols"});
|
||||
correctListToCheck(SplitterFactory.getInstance().getCommentSplitter(), text, "special", "symbols");
|
||||
|
||||
}
|
||||
|
||||
public void testCamelCaseInXmlComments() {
|
||||
String text = "<!--specialCase symbols-->";
|
||||
List<CheckArea> checkAreas = SplitterFactory.getInstance().getCommentSplitter().split(text);
|
||||
correctListToCheck(checkAreas, text, new String[]{"special", "Case", "symbols"});
|
||||
correctListToCheck(SplitterFactory.getInstance().getCommentSplitter(), text, "special", "Case", "symbols");
|
||||
|
||||
}
|
||||
|
||||
public void testWordsWithNumbers() {
|
||||
String text = "testCamelCase123";
|
||||
List<CheckArea> checkAreas = SplitterFactory.getInstance().getIdentifierSplitter().split(text);
|
||||
correctListToCheck(checkAreas, text, new String[]{"test", "Camel", "Case"});
|
||||
correctListToCheck(SplitterFactory.getInstance().getIdentifierSplitter(), text, "test", "Camel", "Case");
|
||||
|
||||
}
|
||||
|
||||
public void testCommentsWithWordsWithNumbers() {
|
||||
String text = "<!--specialCase456 symbols-->";
|
||||
List<CheckArea> checkAreas = SplitterFactory.getInstance().getCommentSplitter().split(text);
|
||||
correctListToCheck(checkAreas, text, new String[]{"special", "Case", "symbols"});
|
||||
correctListToCheck(SplitterFactory.getInstance().getCommentSplitter(), text, "special", "Case", "symbols");
|
||||
|
||||
}
|
||||
|
||||
public void testCommentsWithAbr() {
|
||||
String text = "<!--JSPTestClass-->";
|
||||
List<CheckArea> checkAreas = SplitterFactory.getInstance().getCommentSplitter().split(text);
|
||||
correctListToCheck(checkAreas, text, new String[]{"Test", "Class"});
|
||||
correctListToCheck(SplitterFactory.getInstance().getCommentSplitter(), text, "Test", "Class");
|
||||
|
||||
}
|
||||
|
||||
public void testStringLiterals() {
|
||||
String text = "test\ntest\n";
|
||||
List<CheckArea> checkAreas = SplitterFactory.getInstance().getStringLiteralSplitter().split(text);
|
||||
correctListToCheck(checkAreas, text, new String[]{"test", "test"});
|
||||
correctListToCheck(SplitterFactory.getInstance().getStringLiteralSplitter(), text, "test", "test");
|
||||
|
||||
}
|
||||
|
||||
|
||||
public void testCommentWithHtml() {
|
||||
String text = "<!--<li>something go here</li> <li>next content</li> foooo barrrr <p> text -->";
|
||||
List<CheckArea> checkAreas = SplitterFactory.getInstance().getCommentSplitter().split(text);
|
||||
correctListToCheck(checkAreas, text, new String[]{"something", "here", "next", "content", "foooo", "barrrr", "text"});
|
||||
correctListToCheck(SplitterFactory.getInstance().getCommentSplitter(), text, "something", "here", "next", "content", "foooo", "barrrr",
|
||||
"text");
|
||||
|
||||
}
|
||||
|
||||
public void testCommentWithHtmlTagsAndAtr() {
|
||||
String text = "<!-- <li style='color:red;'>something go here</li> foooo <li style='color:red;'>barrrr</li> <p> text text -->";
|
||||
List<CheckArea> checkAreas = SplitterFactory.getInstance().getCommentSplitter().split(text);
|
||||
correctListToCheck(checkAreas, text, new String[]{"something", "here", "foooo", "barrrr", "text", "text"});
|
||||
correctListToCheck(SplitterFactory.getInstance().getCommentSplitter(), text, "something", "here", "foooo", "barrrr", "text", "text");
|
||||
|
||||
}
|
||||
|
||||
public void testSpecial() {
|
||||
String text = "test test";
|
||||
List<CheckArea> checkAreas = SplitterFactory.getInstance().getPlainTextSplitter().split(text);
|
||||
correctListToCheck(checkAreas, text, new String[]{"test", "test"});
|
||||
correctListToCheck(SplitterFactory.getInstance().getPlainTextSplitter(), text, "test", "test");
|
||||
|
||||
}
|
||||
|
||||
public void testColorUC() {
|
||||
String text = "#AABBFF";
|
||||
List<CheckArea> checkAreas = SplitterFactory.getInstance().getWordSplitter().split(text);
|
||||
correctListToCheck(checkAreas, text, new String[]{});
|
||||
correctListToCheck(SplitterFactory.getInstance().getWordSplitter(), text);
|
||||
|
||||
}
|
||||
|
||||
public void testColorUCSC() {
|
||||
String text = "#AABBFF;";
|
||||
List<CheckArea> checkAreas = SplitterFactory.getInstance().getWordSplitter().split(text);
|
||||
correctListToCheck(checkAreas, text, new String[]{});
|
||||
correctListToCheck(SplitterFactory.getInstance().getWordSplitter(), text);
|
||||
|
||||
}
|
||||
|
||||
public void testColorUCSurrounded() {
|
||||
String text = "\"#AABBFF\"";
|
||||
List<CheckArea> checkAreas = SplitterFactory.getInstance().getWordSplitter().split(text);
|
||||
correctListToCheck(checkAreas, text, new String[]{});
|
||||
correctListToCheck(SplitterFactory.getInstance().getWordSplitter(), text);
|
||||
|
||||
}
|
||||
|
||||
public void testColorLC() {
|
||||
String text = "#fff";
|
||||
List<CheckArea> checkAreas = SplitterFactory.getInstance().getAttributeValueSplitter().split(text);
|
||||
correctListToCheck(checkAreas, text, new String[]{});
|
||||
correctListToCheck(SplitterFactory.getInstance().getAttributeValueSplitter(), text);
|
||||
|
||||
}
|
||||
|
||||
public void testTooShort() {
|
||||
String text = "bgColor carLight";
|
||||
List<CheckArea> checkAreas = SplitterFactory.getInstance().getStringLiteralSplitter().split(text);
|
||||
correctListToCheck(checkAreas, text, new String[]{"Color", "Light"});
|
||||
correctListToCheck(SplitterFactory.getInstance().getStringLiteralSplitter(), text, "Color", "Light");
|
||||
|
||||
}
|
||||
|
||||
public void testPhpVariableCorrectSimple() {
|
||||
String text = "$this";
|
||||
List<CheckArea> checkAreas = SplitterFactory.getInstance().getIdentifierSplitter().split(text);
|
||||
correctListToCheck(checkAreas, text, new String[]{"this"});
|
||||
correctListToCheck(SplitterFactory.getInstance().getIdentifierSplitter(), text, "this");
|
||||
|
||||
}
|
||||
|
||||
public void testPhpVariableCorrect() {
|
||||
String text = "$this_this$this";
|
||||
List<CheckArea> checkAreas = SplitterFactory.getInstance().getIdentifierSplitter().split(text);
|
||||
correctListToCheck(checkAreas, text, new String[]{"this", "this", "this"});
|
||||
correctListToCheck(SplitterFactory.getInstance().getIdentifierSplitter(), text, "this", "this", "this");
|
||||
|
||||
}
|
||||
|
||||
public void testEmail() {
|
||||
String text = "some text with email (shkate.test@gmail.com) inside";
|
||||
List<CheckArea> checkAreas = SplitterFactory.getInstance().getStringLiteralSplitter().split(text);
|
||||
correctListToCheck(checkAreas, text, new String[]{"some", "text", "with", "email", "inside"});
|
||||
correctListToCheck(SplitterFactory.getInstance().getStringLiteralSplitter(), text, "some", "text", "with", "email", "inside");
|
||||
|
||||
}
|
||||
|
||||
public void testEmailOnly() {
|
||||
String text = "shkate123-\u00DC.test@gmail.com";
|
||||
List<CheckArea> checkAreas = SplitterFactory.getInstance().getPlainTextSplitter().split(text);
|
||||
correctListToCheck(checkAreas, text, new String[]{});
|
||||
correctListToCheck(SplitterFactory.getInstance().getPlainTextSplitter(), text);
|
||||
|
||||
}
|
||||
|
||||
public void testUrl() {
|
||||
String text = "http://www.jetbrains.com/idea";
|
||||
List<CheckArea> checkAreas = SplitterFactory.getInstance().getPlainTextSplitter().split(text);
|
||||
correctListToCheck(checkAreas, text, new String[]{});
|
||||
|
||||
correctListToCheck(SplitterFactory.getInstance().getPlainTextSplitter(), text);
|
||||
}
|
||||
|
||||
public void testWordBeforeDelimiter() {
|
||||
String text = "badd,";
|
||||
List<CheckArea> checkAreas = SplitterFactory.getInstance().getPlainTextSplitter().split(text);
|
||||
correctListToCheck(checkAreas, text, new String[]{"badd"});
|
||||
|
||||
correctListToCheck(SplitterFactory.getInstance().getPlainTextSplitter(), text, "badd");
|
||||
}
|
||||
|
||||
public void testWordAfterDelimiter() {
|
||||
String text = ",badd";
|
||||
List<CheckArea> checkAreas = SplitterFactory.getInstance().getPlainTextSplitter().split(text);
|
||||
correctListToCheck(checkAreas, text, new String[]{"badd"});
|
||||
|
||||
correctListToCheck(SplitterFactory.getInstance().getPlainTextSplitter(), text, "badd");
|
||||
}
|
||||
|
||||
public void testWordInCapsBeforeDelimiter() {
|
||||
String text = "BADD,";
|
||||
List<CheckArea> checkAreas = SplitterFactory.getInstance().getPlainTextSplitter().split(text);
|
||||
correctListToCheck(checkAreas, text, new String[]{"BADD"});
|
||||
correctListToCheck(SplitterFactory.getInstance().getPlainTextSplitter(), text, "BADD");
|
||||
|
||||
}
|
||||
|
||||
public void testWordInCapsAfterDelimiter() {
|
||||
String text = ",BADD";
|
||||
List<CheckArea> checkAreas = SplitterFactory.getInstance().getPlainTextSplitter().split(text);
|
||||
correctListToCheck(checkAreas, text, new String[]{"BADD"});
|
||||
correctListToCheck(SplitterFactory.getInstance().getPlainTextSplitter(), text, "BADD");
|
||||
|
||||
}
|
||||
|
||||
public void testWordInCapsAfterDelimiter2() {
|
||||
String text = "BADD;";
|
||||
List<CheckArea> checkAreas = SplitterFactory.getInstance().getPlainTextSplitter().split(text);
|
||||
correctListToCheck(checkAreas, text, new String[]{"BADD"});
|
||||
correctListToCheck(SplitterFactory.getInstance().getPlainTextSplitter(), text, "BADD");
|
||||
|
||||
}
|
||||
|
||||
public void testWordInCapsAfterDelimiter3() {
|
||||
String text = ";BADD;";
|
||||
List<CheckArea> checkAreas = SplitterFactory.getInstance().getPlainTextSplitter().split(text);
|
||||
correctListToCheck(checkAreas, text, new String[]{"BADD"});
|
||||
|
||||
correctListToCheck(SplitterFactory.getInstance().getPlainTextSplitter(), text, "BADD");
|
||||
}
|
||||
|
||||
public void testWordWithUmlauts() {
|
||||
String text = "rechtsb\u00FCndig";
|
||||
List<CheckArea> checkAreas = SplitterFactory.getInstance().getPlainTextSplitter().split(text);
|
||||
correctListToCheck(checkAreas, text, new String[]{text});
|
||||
|
||||
correctListToCheck(SplitterFactory.getInstance().getPlainTextSplitter(), text, text);
|
||||
}
|
||||
|
||||
|
||||
public void testWordUpperCasedWithUmlauts() {
|
||||
String text = "RECHTSB\u00DCNDIG";
|
||||
List<CheckArea> checkAreas = SplitterFactory.getInstance().getPlainTextSplitter().split(text);
|
||||
correctListToCheck(checkAreas, text, new String[]{text});
|
||||
|
||||
correctListToCheck(SplitterFactory.getInstance().getPlainTextSplitter(), text, text);
|
||||
}
|
||||
|
||||
public void testCommaSeparatedList() {
|
||||
String text = "properties,test,properties";
|
||||
List<CheckArea> checkAreas = SplitterFactory.getInstance().getPlainTextSplitter().split(text);
|
||||
correctListToCheck(checkAreas, text, new String[]{"properties", "test", "properties"});
|
||||
correctListToCheck(SplitterFactory.getInstance().getPlainTextSplitter(), text, "properties", "test", "properties");
|
||||
|
||||
}
|
||||
|
||||
public void testSemicolonSeparatedList() {
|
||||
String text = "properties;test;properties";
|
||||
List<CheckArea> checkAreas = SplitterFactory.getInstance().getPlainTextSplitter().split(text);
|
||||
correctListToCheck(checkAreas, text, new String[]{"properties", "test", "properties"});
|
||||
correctListToCheck(SplitterFactory.getInstance().getPlainTextSplitter(), text, "properties", "test", "properties");
|
||||
|
||||
}
|
||||
|
||||
public void testProperties1() {
|
||||
String text = "properties.test.properties";
|
||||
List<CheckArea> checkAreas = SplitterFactory.getInstance().getPropertiesSplitter().split(text);
|
||||
correctListToCheck(checkAreas, text, new String[]{"properties", "test", "properties"});
|
||||
|
||||
correctListToCheck(SplitterFactory.getInstance().getPropertiesSplitter(), text, "properties", "test", "properties");
|
||||
}
|
||||
|
||||
|
||||
public void testPropertiesWithCamelCase() {
|
||||
String text = "upgrade.testCommit.propertiesSomeNews";
|
||||
List<CheckArea> checkAreas = SplitterFactory.getInstance().getPropertiesSplitter().split(text);
|
||||
correctListToCheck(checkAreas, text, new String[]{"upgrade", "test", "Commit", "properties", "Some", "News"});
|
||||
|
||||
correctListToCheck(SplitterFactory.getInstance().getPropertiesSplitter(), text, "upgrade", "test", "Commit", "properties", "Some",
|
||||
"News");
|
||||
}
|
||||
|
||||
public void testWordUpperCasedWithUmlautsInTheBeginning() {
|
||||
String text = "\u00DCNDIG";
|
||||
List<CheckArea> checkAreas = SplitterFactory.getInstance().getPlainTextSplitter().split(text);
|
||||
correctListToCheck(checkAreas, text, new String[]{text});
|
||||
|
||||
correctListToCheck(SplitterFactory.getInstance().getPlainTextSplitter(), text, text);
|
||||
}
|
||||
|
||||
|
||||
public void testTCData() {
|
||||
final InputStream stream = SplitterTest.class.getResourceAsStream("contents.txt");
|
||||
String text = convertStreamToString(stream);
|
||||
List<CheckArea> checkAreas = SplitterFactory.getInstance().getPlainTextSplitter().split(text);
|
||||
List<String> words = wordsToCheck(checkAreas, text);
|
||||
assertNull(words);
|
||||
List<String> words = wordsToCheck(SplitterFactory.getInstance().getPlainTextSplitter(), text);
|
||||
assertEquals(0, words.size());
|
||||
}
|
||||
|
||||
|
||||
@Nullable
|
||||
private static List<String> wordsToCheck(List<CheckArea> toCheck, String text) {
|
||||
if (text == null || toCheck == null) return null;
|
||||
List<String> words = new ArrayList<String>();
|
||||
for (CheckArea area : toCheck) {
|
||||
words.add(area.getWord());
|
||||
}
|
||||
return (words.size() != 0) ? words : null;
|
||||
private static List<String> wordsToCheck(Splitter splitter, final String text) {
|
||||
final List<String> words = new ArrayList<String>();
|
||||
splitter.split(text, TextRange.allOf(text), new Consumer<TextRange>() {
|
||||
@Override
|
||||
public void consume(TextRange textRange) {
|
||||
words.add(textRange.substring(text));
|
||||
}
|
||||
});
|
||||
return words;
|
||||
}
|
||||
|
||||
|
||||
private static void correctListToCheck(List<CheckArea> toCheck, String text, @NotNull String[] expected) {
|
||||
List<String> words = wordsToCheck(toCheck, text);
|
||||
private static void correctListToCheck(Splitter splitter, String text, @NotNull String... expected) {
|
||||
List<String> words = wordsToCheck(splitter, text);
|
||||
List<String> expectedWords = Arrays.asList(expected);
|
||||
Assert.assertEquals("Splitting:'" + text + "'", expectedWords.toString(), words!=null ? words.toString() : "[]");
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user