diff --git a/java/java-tests/testSrc/com/intellij/codeInsight/daemon/lambda/TarjanTest.java b/java/java-tests/testSrc/com/intellij/codeInsight/daemon/lambda/TarjanTest.java index 6fef4a0a5482..18111d810df5 100644 --- a/java/java-tests/testSrc/com/intellij/codeInsight/daemon/lambda/TarjanTest.java +++ b/java/java-tests/testSrc/com/intellij/codeInsight/daemon/lambda/TarjanTest.java @@ -1,5 +1,5 @@ /* - * Copyright 2000-2013 JetBrains s.r.o. + * Copyright 2000-2015 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. @@ -17,80 +17,69 @@ package com.intellij.codeInsight.daemon.lambda; import com.intellij.openapi.util.text.StringUtil; import com.intellij.psi.impl.source.resolve.graphInference.InferenceVariablesOrder; -import com.intellij.util.Function; -import junit.framework.Assert; -import junit.framework.TestCase; +import org.junit.Test; import java.util.ArrayList; -import java.util.Arrays; import java.util.List; +import static org.junit.Assert.assertEquals; + /** - * User: anna - * Date: 7/4/13 + * Testdata from https://github.com/bwesterb/py-tarjan + * + * @author anna + * @since 4.07.2013 */ -public class TarjanTest extends TestCase { - - //testdata from https://github.com/bwesterb/py-tarjan/ +public class TarjanTest { + @Test public void testResultGraph() throws Exception { - + List>> tarjan = InferenceVariablesOrder.tarjan(getNodes()); + String messages = StringUtil.join(tarjan, nodes -> StringUtil.join(nodes, node -> String.valueOf(node.getValue()), ", "), "\n"); + assertEquals("[9]\n" + + "[8], [7], [6]\n" + + "[5]\n" + + "[2], [1]\n" + + "[4], [3]", messages); + } - final List>> tarjan = InferenceVariablesOrder.tarjan(Arrays.asList(initNodes())); - final String messages = StringUtil.join(tarjan, new Function>, String>() { - @Override - public String fun(List> nodes) { - return StringUtil.join(nodes, new Function, String>() { - @Override - public String fun(InferenceVariablesOrder.InferenceGraphNode node) { - return String.valueOf(node.getValue()); - } - }, ","); - } - }, "\n"); - - Assert.assertEquals("[9]\n" + - "[8],[7],[6]\n" + - "[5]\n" + - "[2],[1]\n" + - "[4],[3]", messages); - - final ArrayList> acyclicNodes = InferenceVariablesOrder.initNodes(Arrays.asList(initNodes())); - final String aMessages = StringUtil.join(acyclicNodes, new Function, String>() { - @Override - public String fun(InferenceVariablesOrder.InferenceGraphNode node) { - return String.valueOf(node.getValue()); - } - }, ","); - - - Assert.assertEquals("[9],[8, 7, 6],[5],[2, 1],[4, 3]", aMessages); + @Test + public void testAcyclic() throws Exception { + List> acyclicNodes = InferenceVariablesOrder.initNodes(getNodes()); + String messages = StringUtil.join(acyclicNodes, node -> String.valueOf(node.getValue()), "\n"); + assertEquals("[9]\n" + + "[8, 7, 6]\n" + + "[5]\n" + + "[2, 1]\n" + + "[4, 3]", messages); } //{1:[2],2:[1,5],3:[4],4:[3,5],5:[6],6:[7],7:[8],8:[6,9],9:[]} - private static InferenceVariablesOrder.InferenceGraphNode[] initNodes() { - InferenceVariablesOrder.InferenceGraphNode[] nodes = new InferenceVariablesOrder.InferenceGraphNode[9]; - for (int i = 0; i < nodes.length; i++) { - nodes[i] = new InferenceVariablesOrder.InferenceGraphNode(i + 1); + private static List> getNodes() { + List> nodes = new ArrayList<>(9); + + for (int i = 0; i < 9; i++) { + nodes.add(new InferenceVariablesOrder.InferenceGraphNode<>(i + 1)); } - nodes[0].getDependencies().add(nodes[1]); + nodes.get(0).getDependencies().add(nodes.get(1)); - nodes[1].getDependencies().add(nodes[0]); - nodes[1].getDependencies().add(nodes[4]); + nodes.get(1).getDependencies().add(nodes.get(0)); + nodes.get(1).getDependencies().add(nodes.get(4)); - nodes[2].getDependencies().add(nodes[3]); + nodes.get(2).getDependencies().add(nodes.get(3)); - nodes[3].getDependencies().add(nodes[2]); - nodes[3].getDependencies().add(nodes[4]); + nodes.get(3).getDependencies().add(nodes.get(2)); + nodes.get(3).getDependencies().add(nodes.get(4)); - nodes[4].getDependencies().add(nodes[5]); + nodes.get(4).getDependencies().add(nodes.get(5)); - nodes[5].getDependencies().add(nodes[6]); + nodes.get(5).getDependencies().add(nodes.get(6)); - nodes[6].getDependencies().add(nodes[7]); + nodes.get(6).getDependencies().add(nodes.get(7)); + + nodes.get(7).getDependencies().add(nodes.get(5)); + nodes.get(7).getDependencies().add(nodes.get(8)); - nodes[7].getDependencies().add(nodes[5]); - nodes[7].getDependencies().add(nodes[8]); return nodes; } } diff --git a/platform/util/testSrc/com/intellij/util/text/StringUtilTest.java b/platform/util/testSrc/com/intellij/util/text/StringUtilTest.java index 2d80c681bb87..6af19a615746 100644 --- a/platform/util/testSrc/com/intellij/util/text/StringUtilTest.java +++ b/platform/util/testSrc/com/intellij/util/text/StringUtilTest.java @@ -19,16 +19,19 @@ import com.intellij.openapi.util.Comparing; import com.intellij.openapi.util.text.StringUtil; import com.intellij.util.LineSeparator; import com.intellij.xml.util.XmlStringUtil; -import junit.framework.TestCase; +import org.junit.Test; import java.nio.CharBuffer; import java.util.*; +import static org.junit.Assert.*; + /** * @author Eugene Zhuravlev * @since Dec 22, 2006 */ -public class StringUtilTest extends TestCase { +public class StringUtilTest { + @Test public void testToUpperCase() { assertEquals('/', StringUtil.toUpperCase('/')); assertEquals(':', StringUtil.toUpperCase(':')); @@ -40,6 +43,7 @@ public class StringUtilTest extends TestCase { assertEquals('\u2567', StringUtil.toUpperCase(Character.toLowerCase('\u2567'))); } + @Test public void testToLowerCase() { assertEquals('/', StringUtil.toLowerCase('/')); assertEquals(':', StringUtil.toLowerCase(':')); @@ -51,6 +55,7 @@ public class StringUtilTest extends TestCase { assertEquals('\u2567', StringUtil.toUpperCase(Character.toLowerCase('\u2567'))); } + @Test public void testIsEmptyOrSpaces() throws Exception { assertTrue(StringUtil.isEmptyOrSpaces(null)); assertTrue(StringUtil.isEmptyOrSpaces("")); @@ -61,6 +66,7 @@ public class StringUtilTest extends TestCase { assertFalse(StringUtil.isEmptyOrSpaces("test")); } + @Test public void testSplitWithQuotes() { final List strings = StringUtil.splitHonorQuotes("aaa bbb ccc \"ddd\" \"e\\\"e\\\"e\" ", ' '); assertEquals(5, strings.size()); @@ -71,16 +77,19 @@ public class StringUtilTest extends TestCase { assertEquals("\"e\\\"e\\\"e\"", strings.get(4)); } - public void testUnpluralize() { + @Test + public void testUnPluralize() { assertEquals("s", StringUtil.unpluralize("s")); assertEquals("z", StringUtil.unpluralize("zs")); } + @Test public void testPluralize() { assertEquals("values", StringUtil.pluralize("value")); assertEquals("values", StringUtil.pluralize("values")); } + @Test public void testStartsWithConcatenation() { assertTrue(StringUtil.startsWithConcatenation("something.with.dot", "something", ".")); assertTrue(StringUtil.startsWithConcatenation("something.with.dot", "", "something.")); @@ -90,6 +99,7 @@ public class StringUtilTest extends TestCase { assertFalse(StringUtil.startsWithConcatenation("some", "something", "")); } + @Test public void testNaturalCompare() { assertEquals(1, StringUtil.naturalCompare("test011", "test10")); assertEquals(1, StringUtil.naturalCompare("test10a", "test010")); @@ -116,12 +126,14 @@ public class StringUtilTest extends TestCase { assertEquals(Arrays.asList("C148A_InsomniaCure", "C148B_Escape", "C148C_TersePrincess", "C148D_BagOfMice", "C148E_Porcelain"), strings3); } + @Test public void testFormatLinks() { assertEquals("http://a-b+c", StringUtil.formatLinks("http://a-b+c")); } + @Test public void testCopyHeapCharBuffer() { - String s = "abcde"; + String s = "abc.d"; CharBuffer buffer = CharBuffer.allocate(s.length()); buffer.append(s); buffer.rewind(); @@ -133,20 +145,24 @@ public class StringUtilTest extends TestCase { assertNull(CharArrayUtil.fromSequenceWithoutCopying(buffer.subSequence(1, 2))); } + @Test public void testTitleCase() { assertEquals("Couldn't Connect to Debugger", StringUtil.wordsToBeginFromUpperCase("Couldn't connect to debugger")); } + @Test public void testSentenceCapitalization() { assertEquals("couldn't connect to debugger", StringUtil.wordsToBeginFromLowerCase("Couldn't Connect to Debugger")); } + @Test public void testEscapeStringCharacters() { assertEquals("\\\"\\n", StringUtil.escapeStringCharacters(3, "\\\"\n", "\"", false, new StringBuilder()).toString()); assertEquals("\\\"\\n", StringUtil.escapeStringCharacters(2, "\"\n", "\"", false, new StringBuilder()).toString()); assertEquals("\\\\\\\"\\n", StringUtil.escapeStringCharacters(3, "\\\"\n", "\"", true, new StringBuilder()).toString()); } + @Test public void testEscapeSlashes() { assertEquals("\\/", StringUtil.escapeSlashes("/")); assertEquals("foo\\/bar\\foo\\/", StringUtil.escapeSlashes("foo/bar\\foo/")); @@ -154,12 +170,14 @@ public class StringUtilTest extends TestCase { assertEquals("\\\\\\\\server\\\\share\\\\extension.crx", StringUtil.escapeBackSlashes("\\\\server\\share\\extension.crx")); } + @Test public void testEscapeQuotes() { assertEquals("\\\"", StringUtil.escapeQuotes("\"")); assertEquals("foo\\\"bar'\\\"", StringUtil.escapeQuotes("foo\"bar'\"")); } - public void testUnqote() { + @Test + public void testUnquote() { assertEquals("", StringUtil.unquoteString("")); assertEquals("\"", StringUtil.unquoteString("\"")); assertEquals("", StringUtil.unquoteString("\"\"")); @@ -180,6 +198,8 @@ public class StringUtilTest extends TestCase { assertEquals("\"foo\'", StringUtil.unquoteString("\"foo\'")); } + @SuppressWarnings("SSBasedInspection") + @Test public void testStripQuotesAroundValue() { assertEquals("", StringUtil.stripQuotesAroundValue("")); assertEquals("", StringUtil.stripQuotesAroundValue("'")); @@ -198,7 +218,8 @@ public class StringUtilTest extends TestCase { assertEquals("foo' 'bar", StringUtil.stripQuotesAroundValue("foo' 'bar")); } - public void testUnqoteWithQuotationChar() { + @Test + public void testUnquoteWithQuotationChar() { assertEquals("", StringUtil.unquoteString("", '|')); assertEquals("|", StringUtil.unquoteString("|", '|')); assertEquals("", StringUtil.unquoteString("||", '|')); @@ -208,6 +229,7 @@ public class StringUtilTest extends TestCase { assertEquals("foo|", StringUtil.unquoteString("foo|", '|')); } + @Test public void testIsQuotedString() { assertFalse(StringUtil.isQuotedString("")); assertFalse(StringUtil.isQuotedString("'")); @@ -218,6 +240,7 @@ public class StringUtilTest extends TestCase { assertTrue(StringUtil.isQuotedString("\"foo\"")); } + @Test public void testJoin() { assertEquals("", StringUtil.join(Collections.emptyList(), ",")); assertEquals("qqq", StringUtil.join(Collections.singletonList("qqq"), ",")); @@ -227,9 +250,10 @@ public class StringUtilTest extends TestCase { assertEquals("foo,,bar", StringUtil.join(new String[]{"foo", "", "bar"}, ",")); } + @Test public void testSplitByLineKeepingSeparators() { - assertEquals(Arrays.asList(""), Arrays.asList(StringUtil.splitByLinesKeepSeparators(""))); - assertEquals(Arrays.asList("aa"), Arrays.asList(StringUtil.splitByLinesKeepSeparators("aa"))); + assertEquals(Collections.singletonList(""), Arrays.asList(StringUtil.splitByLinesKeepSeparators(""))); + assertEquals(Collections.singletonList("aa"), Arrays.asList(StringUtil.splitByLinesKeepSeparators("aa"))); assertEquals(Arrays.asList("\n", "\n", "aa\n", "\n", "bb\n", "cc\n", "\n"), Arrays.asList(StringUtil.splitByLinesKeepSeparators("\n\naa\n\nbb\ncc\n\n"))); @@ -240,8 +264,11 @@ public class StringUtilTest extends TestCase { Arrays.asList(StringUtil.splitByLinesKeepSeparators("\n\r\n\n\r\n\r\raa\rbb\r\ncc\n\rdd\n\n\r\n\r"))); } + @Test public void testShortened() { - String[] names = {"AVeryVeeryLongClassName.java", "com.test.SomeJAVAClassName.java", "strangelowercaseclassname.java", "PrefixPostfix.java", "SomeJAVAClassName.java", "qwertyuiopasdghjklzxcvbnm1234567890"}; + @SuppressWarnings("SpellCheckingInspection") String[] names = { + "AVeryVeeryLongClassName.java", "com.test.SomeJAVAClassName.java", "strangelowercaseclassname.java", "PrefixPostfix.java", + "SomeJAVAClassName.java", "qwertyuiopasdghjklzxcvbnm1234567890"}; for (String name : names) { for (int i = name.length() + 1; i > 15; i--) { String shortened = StringUtil.getShortened(name, i); @@ -259,15 +286,18 @@ public class StringUtilTest extends TestCase { } } + @Test public void testReplaceReturnReplacementIfTextEqualsToReplacedText() { String newS = "/tmp"; assertSame(StringUtil.replace("$PROJECT_FILE$", "$PROJECT_FILE$".toLowerCase().toUpperCase() /* ensure new String instance */, newS), newS); } + @Test public void testReplace() { assertEquals(StringUtil.replace("$PROJECT_FILE$/filename", "$PROJECT_FILE$", "/tmp"), "/tmp/filename"); } + @Test public void testEqualsIgnoreWhitespaces() { assertTrue(StringUtil.equalsIgnoreWhitespaces(null, null)); assertFalse(StringUtil.equalsIgnoreWhitespaces("", null)); @@ -281,7 +311,7 @@ public class StringUtilTest extends TestCase { assertTrue(StringUtil.equalsIgnoreWhitespaces("x", "x ")); assertTrue(StringUtil.equalsIgnoreWhitespaces("x\n", "x")); - assertTrue(StringUtil.equalsIgnoreWhitespaces("abcd", "a\nb\nc\nd\n")); + assertTrue(StringUtil.equalsIgnoreWhitespaces("abc", "a\nb\nc\n")); assertTrue(StringUtil.equalsIgnoreWhitespaces("x y x", "x y x")); assertTrue(StringUtil.equalsIgnoreWhitespaces("xyx", "x y x")); @@ -293,6 +323,7 @@ public class StringUtilTest extends TestCase { assertFalse(StringUtil.equalsIgnoreWhitespaces("xyx", "xYx")); } + @Test public void testStringHashCodeIgnoreWhitespaces() { assertTrue(Comparing.equal(StringUtil.stringHashCodeIgnoreWhitespaces(""), StringUtil.stringHashCodeIgnoreWhitespaces(""))); assertTrue(Comparing.equal(StringUtil.stringHashCodeIgnoreWhitespaces("\n\t "), StringUtil.stringHashCodeIgnoreWhitespaces(""))); @@ -303,7 +334,7 @@ public class StringUtilTest extends TestCase { 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("abc"), StringUtil.stringHashCodeIgnoreWhitespaces("a\nb\nc\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"))); @@ -315,6 +346,7 @@ public class StringUtilTest extends TestCase { assertFalse(Comparing.equal(StringUtil.stringHashCodeIgnoreWhitespaces("xyx"), StringUtil.stringHashCodeIgnoreWhitespaces("xYx"))); } + @Test public void testContains() { assertTrue(StringUtil.contains("1", "1")); assertFalse(StringUtil.contains("1", "12")); @@ -322,6 +354,7 @@ public class StringUtilTest extends TestCase { assertTrue(StringUtil.contains("12", "2")); } + @Test public void testDetectSeparators() { assertEquals(null, StringUtil.detectSeparators("")); assertEquals(null, StringUtil.detectSeparators("asd")); @@ -340,6 +373,7 @@ public class StringUtilTest extends TestCase { assertEquals(LineSeparator.CRLF, StringUtil.detectSeparators("asd\r\nads\n")); } + @Test public void testFormatFileSize() { assertEquals("0B", StringUtil.formatFileSize(0)); assertEquals("1B", StringUtil.formatFileSize(1)); @@ -357,6 +391,7 @@ public class StringUtilTest extends TestCase { assertEquals("1.23G", StringUtil.formatFileSize(1234567890)); } + @Test public void testFormatDuration() { assertEquals("0ms", StringUtil.formatDuration(0)); assertEquals("1ms", StringUtil.formatDuration(1)); @@ -374,13 +409,15 @@ public class StringUtilTest extends TestCase { assertEquals("2w 0d 6h 56m 7s 890ms", StringUtil.formatDuration(1234567890)); } + @Test public void testXmlWrapInCDATA() { - assertEquals("", XmlStringUtil.wrapInCDATA("abcd")); - assertEquals("]]>", XmlStringUtil.wrapInCDATA("abcd]]>")); - assertEquals("efgh]]>", XmlStringUtil.wrapInCDATA("abcd]]>efgh")); + assertEquals("", XmlStringUtil.wrapInCDATA("abc")); + assertEquals("]]>", XmlStringUtil.wrapInCDATA("abc]]>")); + assertEquals("def]]>", XmlStringUtil.wrapInCDATA("abc]]>def")); assertEquals("]]]>]]]>", XmlStringUtil.wrapInCDATA("123]]>]]>