Merge remote-tracking branch 'origin/master'

This commit is contained in:
Anna Kozlova
2014-10-06 18:18:40 +02:00
2 changed files with 57 additions and 1 deletions
@@ -2683,7 +2683,15 @@ public class StringUtil extends StringUtilRt {
}
@Contract(pure = true)
public static boolean equalsIgnoreWhitespaces(@NotNull CharSequence s1, @NotNull CharSequence s2) {
public static boolean equalsIgnoreWhitespaces(@Nullable CharSequence s1, @Nullable CharSequence s2) {
if (s1 == null ^ s2 == null) {
return false;
}
if (s1 == null) {
return true;
}
int len1 = s1.length();
int len2 = s2.length();
@@ -15,6 +15,7 @@
*/
package com.intellij.util.text;
import com.intellij.openapi.util.Comparing;
import com.intellij.openapi.util.text.StringUtil;
import junit.framework.TestCase;
@@ -233,4 +234,51 @@ public class StringUtilTest extends TestCase {
public void testReplace() {
assertEquals(StringUtil.replace("$PROJECT_FILE$/filename", "$PROJECT_FILE$", "/tmp"), "/tmp/filename");
}
public void testEqualsIgnoreWhitespaces() {
assertTrue(StringUtil.equalsIgnoreWhitespaces(null, null));
assertFalse(StringUtil.equalsIgnoreWhitespaces("", null));
assertTrue(StringUtil.equalsIgnoreWhitespaces("", ""));
assertTrue(StringUtil.equalsIgnoreWhitespaces("\n\t ", ""));
assertTrue(StringUtil.equalsIgnoreWhitespaces("", "\t\n \n\t"));
assertTrue(StringUtil.equalsIgnoreWhitespaces("\t", "\n"));
assertTrue(StringUtil.equalsIgnoreWhitespaces("x", " x"));
assertTrue(StringUtil.equalsIgnoreWhitespaces("x", "x "));
assertTrue(StringUtil.equalsIgnoreWhitespaces("x\n", "x"));
assertTrue(StringUtil.equalsIgnoreWhitespaces("abcd", "a\nb\nc\nd\n"));
assertTrue(StringUtil.equalsIgnoreWhitespaces("x y x", "x y x"));
assertTrue(StringUtil.equalsIgnoreWhitespaces("xyx", "x y x"));
assertFalse(StringUtil.equalsIgnoreWhitespaces("x", "\t\n "));
assertFalse(StringUtil.equalsIgnoreWhitespaces("", " x "));
assertFalse(StringUtil.equalsIgnoreWhitespaces("", "x "));
assertFalse(StringUtil.equalsIgnoreWhitespaces("", " x"));
assertFalse(StringUtil.equalsIgnoreWhitespaces("xyx", "xxx"));
assertFalse(StringUtil.equalsIgnoreWhitespaces("xyx", "xYx"));
}
public void testStringHashCodeIgnoreWhitespaces() {
assertTrue(Comparing.equal(StringUtil.stringHashCodeIgnoreWhitespaces(""), StringUtil.stringHashCodeIgnoreWhitespaces("")));
assertTrue(Comparing.equal(StringUtil.stringHashCodeIgnoreWhitespaces("\n\t "), StringUtil.stringHashCodeIgnoreWhitespaces("")));
assertTrue(Comparing.equal(StringUtil.stringHashCodeIgnoreWhitespaces(""), StringUtil.stringHashCodeIgnoreWhitespaces("\t\n \n\t")));
assertTrue(Comparing.equal(StringUtil.stringHashCodeIgnoreWhitespaces("\t"), StringUtil.stringHashCodeIgnoreWhitespaces("\n")));
assertTrue(Comparing.equal(StringUtil.stringHashCodeIgnoreWhitespaces("x"), StringUtil.stringHashCodeIgnoreWhitespaces(" x")));
assertTrue(Comparing.equal(StringUtil.stringHashCodeIgnoreWhitespaces("x"), StringUtil.stringHashCodeIgnoreWhitespaces("x ")));
assertTrue(Comparing.equal(StringUtil.stringHashCodeIgnoreWhitespaces("x\n"), StringUtil.stringHashCodeIgnoreWhitespaces("x")));
assertTrue(Comparing.equal(StringUtil.stringHashCodeIgnoreWhitespaces("abcd"), StringUtil.stringHashCodeIgnoreWhitespaces("a\nb\nc\nd\n")));
assertTrue(Comparing.equal(StringUtil.stringHashCodeIgnoreWhitespaces("x y x"), StringUtil.stringHashCodeIgnoreWhitespaces("x y x")));
assertTrue(Comparing.equal(StringUtil.stringHashCodeIgnoreWhitespaces("xyx"), StringUtil.stringHashCodeIgnoreWhitespaces("x y x")));
assertFalse(Comparing.equal(StringUtil.stringHashCodeIgnoreWhitespaces("x"), StringUtil.stringHashCodeIgnoreWhitespaces("\t\n ")));
assertFalse(Comparing.equal(StringUtil.stringHashCodeIgnoreWhitespaces(""), StringUtil.stringHashCodeIgnoreWhitespaces(" x ")));
assertFalse(Comparing.equal(StringUtil.stringHashCodeIgnoreWhitespaces(""), StringUtil.stringHashCodeIgnoreWhitespaces("x ")));
assertFalse(Comparing.equal(StringUtil.stringHashCodeIgnoreWhitespaces(""), StringUtil.stringHashCodeIgnoreWhitespaces(" x")));
assertFalse(Comparing.equal(StringUtil.stringHashCodeIgnoreWhitespaces("xyx"), StringUtil.stringHashCodeIgnoreWhitespaces("xxx")));
assertFalse(Comparing.equal(StringUtil.stringHashCodeIgnoreWhitespaces("xyx"), StringUtil.stringHashCodeIgnoreWhitespaces("xYx")));
}
}