Extract Java and XML specific parts out of CommentByLineTest

GitOrigin-RevId: 37045b21bd20c877ec76670b1ca0097354d1cb94
This commit is contained in:
Dmitry Jemerov
2022-04-28 17:12:40 +02:00
committed by intellij-monorepo-bot
parent 299c50d248
commit 65270d424e
79 changed files with 759 additions and 0 deletions

View File

@@ -0,0 +1,6 @@
public class Test {
public void foo() {
// System.out.println();
}
}

View File

@@ -0,0 +1,6 @@
public class Test {
<selection>//public void foo() {
// System.out.println();
// }
</selection><caret>}

View File

@@ -0,0 +1,6 @@
public class Test {
<selection>public void foo() {
System.out.println();
}
</selection><caret>}

View File

@@ -0,0 +1,6 @@
public class Test {
<selection>//public void foo() {
// System.out.println();
// }
</selection><caret>}

View File

@@ -0,0 +1,7 @@
public class Test {
public void foo() {
//System.out.println();
<selection> // System.out.println();
//}
</selection><caret>}

View File

@@ -0,0 +1,11 @@
public class Test {
public void foo() {
<selection><caret> int x = 1;
int x = 1;
int x = 1;
int x = 1;
int x = 1;
</selection>
}

View File

@@ -0,0 +1,12 @@
class A {
// <selection>public void test1() {
// }
//
// public void test3() {
// someFunc3();
// }
//
// public void test4() {
// someFunc4();
// }</selection><caret>
}

View File

@@ -0,0 +1,8 @@
public class Test {
public void foooo(int a,
<selection> //int b,
//
//int c</selection><caret>,
int d) {
}
}

View File

@@ -0,0 +1,5 @@
class A {
<selection> //int a;
//
//int b;</selection>
}

View File

@@ -0,0 +1,6 @@
class A {
public static void main(String[] args) {
// int <caret>i = 10;
// int <caret>j = 20;
}
}

View File

@@ -0,0 +1,6 @@
class A {
public static void main(String[] args) {
// int i = 10;
int j <caret>= 20<caret>;
}
}

View File

@@ -0,0 +1,8 @@
class A {
public static void main(String[] args) {
System.out.println();
<caret>System.out.println();
System.out.println();
<caret>System.out.println();
}
}

View File

@@ -0,0 +1,12 @@
class A {
<selection>public void test1() {
}
public void test3() {
someFunc3();
}
public void test4() {
someFunc4();
}</selection><caret>
}

View File

@@ -0,0 +1,6 @@
public class Test {
public void foo() {
<caret>System.out.println();
}
}

View File

@@ -0,0 +1,6 @@
public class Test {
<selection>public void foo() {
System.out.println();
}
</selection><caret>}

View File

@@ -0,0 +1,6 @@
public class Test {
<selection>//public void foo() {
// System.out.println();
// }
</selection><caret>}

View File

@@ -0,0 +1,6 @@
public class Test {
<selection>public void foo() {
System.out.println();
}
</selection><caret>}

View File

@@ -0,0 +1,7 @@
public class Test {
public void foo() {
//System.out.println();
<selection> System.out.println();
}
</selection><caret>}

View File

@@ -0,0 +1,11 @@
public class Test {
public void foo() {
<selection><caret> // int x = 1;
// int x = 1;
// int x = 1;
// int x = 1;
// int x = 1;
</selection>
}

View File

@@ -0,0 +1,12 @@
class A {
<selection>public void test1() {
}
public void test3() {
someFunc3();
}
public void test4() {
someFunc4();
}</selection><caret>
}

View File

@@ -0,0 +1,8 @@
public class Test {
public void foooo(int a,
<selection> int b,
int c</selection><caret>,
int d) {
}
}

View File

@@ -0,0 +1,5 @@
class A {
<selection> int a;
int b;</selection>
}

View File

@@ -0,0 +1,6 @@
class A {
public static void main(String[] args) {
int <caret>i = 10;
int <caret>j = 20;
}
}

View File

@@ -0,0 +1,6 @@
class A {
public static void main(String[] args) {
int <caret>i = <caret>10;
int j = 20;
}
}

View File

@@ -0,0 +1,8 @@
class A {
public static void main(String[] args) {
// <caret>System.out.println();
System.out.println();
// <caret>System.out.println();
System.out.println();
}
}

View File

@@ -0,0 +1,12 @@
class A {
// <selection>public void test1() {
// }
//
// public void test3() {
// someFunc3();
// }
//
//public void test4() {
// someFunc4();
//}</selection><caret>
}

View File

@@ -0,0 +1,134 @@
// Copyright 2000-2022 JetBrains s.r.o. and contributors. Use of this source code is governed by the Apache 2.0 license.
package com.intellij.codeInsight;
import com.intellij.JavaTestUtil;
import com.intellij.codeInsight.folding.CodeFoldingManager;
import com.intellij.lang.java.JavaLanguage;
import com.intellij.openapi.actionSystem.IdeActions;
import com.intellij.psi.codeStyle.CommonCodeStyleSettings;
import com.intellij.testFramework.PlatformTestUtil;
import org.jetbrains.annotations.NotNull;
public class JavaCommentByLineTest extends CommentByLineTestBase {
@Override
protected @NotNull String getTestDataPath() {
return JavaTestUtil.getJavaTestDataPath();
}
public void testJava1() {
doTest();
}
public void testJava2() {
doTest();
}
public void testJava3() {
doTest();
}
public void testJava4() {
getLanguageSettings(JavaLanguage.INSTANCE).LINE_COMMENT_AT_FIRST_COLUMN = false;
doTest();
}
public void testJava5() {
getLanguageSettings(JavaLanguage.INSTANCE).LINE_COMMENT_AT_FIRST_COLUMN = false;
doTest();
}
public void testJava6() {
getLanguageSettings(JavaLanguage.INSTANCE).LINE_COMMENT_AT_FIRST_COLUMN = false;
doTest();
}
public void testJava_MulticaretSingleLine() {
doTest();
}
public void testJava_MulticaretBlock() {
doTest();
}
public void testJava_MulticaretUncommentSeveralBlocks() {
doTest();
}
public void testJava_AddSpace() {
CommonCodeStyleSettings settings = getLanguageSettings(JavaLanguage.INSTANCE);
settings.LINE_COMMENT_AT_FIRST_COLUMN = false;
settings.LINE_COMMENT_ADD_SPACE = true;
doTest();
}
public void testJava_UncommentRemovingSpace() {
getLanguageSettings(JavaLanguage.INSTANCE).LINE_COMMENT_ADD_SPACE = true;
doTest();
}
public void testJava_CommentUncommentDoesNotAddSpacesOnEmptyLine() {
getLanguageSettings(JavaLanguage.INSTANCE).LINE_COMMENT_AT_FIRST_COLUMN = false;
doInvertedTest(1);
}
public void testFoldedOneLineMethod() {
configureFromFileText(getTestName(false) + ".java",
"class C {\n" +
" void m() {\n" +
" <caret>System.out.println();\n" +
" }\n" +
"}");
CodeFoldingManager.getInstance(getProject()).buildInitialFoldings(getEditor());
executeAction(IdeActions.ACTION_COLLAPSE_ALL_REGIONS);
performAction();
checkResultByText("class C {\n" +
"// void m() {\n" +
"// System.out.println();\n" +
"// }\n" +
"}");
}
public void testFoldingAtSelectionEnd() {
configureFromFileText(getTestName(false) + ".java",
"class C {\n" +
"<caret> void m1() {\n" +
" System.out.println();\n" +
" }\n" +
" void m2() {\n" +
" System.out.println();\n" +
" }\n" +
"}");
CodeFoldingManager.getInstance(getProject()).buildInitialFoldings(getEditor());
executeAction(IdeActions.ACTION_COLLAPSE_ALL_REGIONS);
executeAction(IdeActions.ACTION_EDITOR_MOVE_CARET_DOWN_WITH_SELECTION);
performAction();
checkResultByText("class C {\n" +
"// void m1() {\n" +
"// System.out.println();\n" +
"// }\n" +
" void m2() {\n" +
" System.out.println();\n" +
" }\n" +
"}");
}
public void testJava_AlignedWithSmartTabs() {
CommonCodeStyleSettings settings = getLanguageSettings(JavaLanguage.INSTANCE);
settings.LINE_COMMENT_AT_FIRST_COLUMN = false;
settings.getIndentOptions().USE_TAB_CHARACTER = true;
settings.getIndentOptions().SMART_TABS = true;
doTest();
}
public void testUncommentLargeFilePerformance() {
StringBuilder source = new StringBuilder("class C {\n");
for (int i = 0; i < 5000; i++) {
source.append(" int value").append(i).append(";\n");
}
source.append("}");
configureFromFileText(getTestName(false) + ".java", source.toString());
executeAction(IdeActions.ACTION_SELECT_ALL);
PlatformTestUtil.startPerformanceTest("Uncommenting large file", 2000, CommentByLineTestBase::performAction)
.setup(CommentByLineTestBase::performAction)
.assertTiming();
}
}

View File

@@ -0,0 +1,34 @@
// Copyright 2000-2022 JetBrains s.r.o. and contributors. Use of this source code is governed by the Apache 2.0 license.
package com.intellij.codeInsight;
import com.intellij.openapi.actionSystem.IdeActions;
import com.intellij.openapi.util.text.StringUtil;
import com.intellij.testFramework.LightPlatformCodeInsightTestCase;
import com.intellij.testFramework.PlatformTestUtil;
public abstract class CommentByLineTestBase extends LightPlatformCodeInsightTestCase {
protected void doTest() {
doTest(1, false);
}
public void doInvertedTest(int count) {
doTest(count, false);
doTest(count, true);
}
protected void doTest(int count, boolean invert) {
String name = getTestName(true);
String lang = name.split("[0-9_]+")[0];
String suffix = name.substring(lang.length());
suffix = StringUtil.trimStart(suffix, "_");
configureByFile("/codeInsight/commentByLine/" + lang + (invert ? "/after" : "/before") + suffix + "." + lang);
for (int i = 0; i < count; i++) {
performAction();
}
checkResultByFile("/codeInsight/commentByLine/" + lang + (invert ? "/before" : "/after") + suffix + "." + lang);
}
protected static void performAction() {
PlatformTestUtil.invokeNamedAction(IdeActions.ACTION_COMMENT_LINE);
}
}

View File

@@ -0,0 +1,119 @@
// Copyright 2000-2022 JetBrains s.r.o. and contributors. Use of this source code is governed by the Apache 2.0 license.
package com.intellij.codeInsight;
import com.intellij.lang.html.HTMLLanguage;
import com.intellij.lang.xml.XMLLanguage;
import com.intellij.testFramework.PlatformTestUtil;
import org.jetbrains.annotations.NotNull;
import java.io.File;
public class XmlCommentByLineTest extends CommentByLineTestBase {
@Override
protected @NotNull String getTestDataPath() {
return PlatformTestUtil.getCommunityPath().replace(File.separatorChar, '/') + "/xml/tests/testData";
}
public void testXml1() {
doTest();
}
public void testXml2() {
doTest();
}
public void testXml3() {
doTest();
}
public void testXml4() {
getLanguageSettings(XMLLanguage.INSTANCE).LINE_COMMENT_AT_FIRST_COLUMN = false;
doTest();
}
public void testXml5() {
getLanguageSettings(XMLLanguage.INSTANCE).LINE_COMMENT_AT_FIRST_COLUMN = false;
doTest();
}
public void testXml6() {
doTest();
}
public void testXml7() {
doTest();
}
public void testXml8() {
doTest();
}
public void testXml9() {
doTest();
}
public void testXml10() { // this is a feature
doTest();
}
public void testXml11() {
doTest();
}
public void testXml_DoubleDash() {
doInvertedTest(1);
}
public void testXml_SingleDash() {
doTest();
}
public void testXml_SingleDashWithSpace() {
doTest();
}
public void testXml_OtherLine() {
doTest();
}
public void testHtml1() {
doTest();
}
public void testHtml2() {
doTest();
}
public void testHtml3() {
doTest();
}
public void testHtml4() {
getLanguageSettings(HTMLLanguage.INSTANCE).LINE_COMMENT_AT_FIRST_COLUMN = false;
doTest();
}
public void testHtml5() {
getLanguageSettings(HTMLLanguage.INSTANCE).LINE_COMMENT_AT_FIRST_COLUMN = false;
doTest();
}
public void testHtml6() {
doTest();
}
public void testHtml7() {
doTest();
}
public void testHtml8() {
doTest();
}
public void testHtml9() {
doTest();
}
public void testHtml10() {
doTest();
}
}

View File

@@ -0,0 +1,6 @@
<tag>
<!-- <subtag>-->
Value
</subtag>
<emptyTag attr=""/>
</tag>

View File

@@ -0,0 +1,3 @@
<!--<selection><script type="text/javascript">-->
<!--alert("a");-->
<!--</script></selection>-->

View File

@@ -0,0 +1,6 @@
<tag>
<subtag>
<caret> Value
</subtag>
<emptyTag attr=""/>
</tag>

View File

@@ -0,0 +1,6 @@
<tag>
<!--&lt;!&ndash; <subtag>-->
<caret> Value
</subtag>
<emptyTag attr=""/>
</tag>

View File

@@ -0,0 +1,6 @@
<tag>
<!--<subtag>-->
<caret> Value
</subtag>
<emptyTag attr=""/>
</tag>

View File

@@ -0,0 +1,6 @@
<tag>
<!--<subtag>-->
<!-- Value-->
</subtag>
<emptyTag attr=""/>
</tag>

View File

@@ -0,0 +1,12 @@
<selection><!--<div>-->
<!--<p>paragraph</p>&lt;!&ndash; comment &ndash;&gt;<br>-->
<!--&lt;!&ndash; some existing comment &ndash;&gt;-->
<!--<h1>header</h1>-->
<!--&lt;!&ndash; some existing comment &ndash;&gt;-->
<!--</div>-->
</selection>

View File

@@ -0,0 +1,12 @@
<selection><div>
<p>paragraph</p> comment <br>
<!-- some existing comment
<h1>header</h1>
<!-- some existing comment
</div>
</selection>

View File

@@ -0,0 +1,6 @@
<html>
<a>
<!-- <selection><br/>-->
<!-- &lt;!&ndash;<br/>&ndash;&gt;<caret></selection>-->
</a>
</html>

View File

@@ -0,0 +1,6 @@
<html>
<a>
<selection><br/>
<!--<br/>--><caret></selection>
</a>
</html>

View File

@@ -0,0 +1,6 @@
<tag>
<caret> <subtag>
Value
</subtag>
<emptyTag attr=""/>
</tag>

View File

@@ -0,0 +1,3 @@
<selection><script type="text/javascript">
alert("a");
</script></selection>

View File

@@ -0,0 +1,6 @@
<tag>
<caret><!-- <subtag>-->
Value
</subtag>
<emptyTag attr=""/>
</tag>

View File

@@ -0,0 +1,6 @@
<tag>
<caret><!-- <subtag>
Value
</subtag>
<emptyTag attr=""/>
</tag>

View File

@@ -0,0 +1,6 @@
<tag>
<caret> <subtag>
Value
</subtag>
<emptyTag attr=""/>
</tag>

View File

@@ -0,0 +1,6 @@
<tag>
<!--<subtag>-->
<caret> Value
</subtag>
<emptyTag attr=""/>
</tag>

View File

@@ -0,0 +1,12 @@
<selection><caret><div>
<p>paragraph</p><!-- comment --><br>
<!-- some existing comment -->
<h1>header</h1>
<!-- some existing comment -->
</div>
</selection>

View File

@@ -0,0 +1,12 @@
<selection><!--<div>-->
<!--<p>paragraph</p>--><!-- comment --><!--<br>-->
<!--<!-- some existing comment -->
<!--<h1>header</h1>-->
<!--<!-- some existing comment -->
<!--</div>-->
</selection>

View File

@@ -0,0 +1,6 @@
<html>
<a>
<selection><br/>
<!--<br/>--><caret></selection>
</a>
</html>

View File

@@ -0,0 +1,6 @@
<html>
<a>
<!--<selection><br/>-->
<!--&lt;!&ndash;<br/>&ndash;&gt;<caret></selection>-->
</a>
</html>

View File

@@ -0,0 +1,6 @@
<tag>
<!-- <subtag>-->
Value
</subtag>
<emptyTag attr=""/>
</tag>

View File

@@ -0,0 +1,2 @@
<!--<caret>-->
<div></div>

View File

@@ -0,0 +1 @@
<!--<div/>--> <caret>

View File

@@ -0,0 +1,6 @@
<tag>
<subtag>
<caret> Value
</subtag>
<emptyTag attr=""/>
</tag>

View File

@@ -0,0 +1,6 @@
<tag>
<!--&lt;!&ndash; <subtag>-->
<caret> Value
</subtag>
<emptyTag attr=""/>
</tag>

View File

@@ -0,0 +1,6 @@
<tag>
<!--<subtag>-->
<caret> Value
</subtag>
<emptyTag attr=""/>
</tag>

View File

@@ -0,0 +1,6 @@
<tag>
<!--<subtag>-->
<!-- Value-->
</subtag>
<emptyTag attr=""/>
</tag>

View File

@@ -0,0 +1,4 @@
<!--<selection><layout class="org.apache.log4j.PatternLayout">-->
<!-- &lt;!&ndash; conversion pattern with 4 parts separated by #-#, second part is empty &ndash;&gt;-->
<!-- <param name="ConversionPattern" value="[%t] %m#-##-#%d{dd.MM.yyyy}#-#%d{HH:mm:ss}" />-->
<!--</layout></selection>-->

View File

@@ -0,0 +1,6 @@
<!--<selection><tag>-->
<!-- &lt;!&ndash;<subtag>&ndash;&gt;-->
<!-- Value-->
<!-- </subtag><caret></selection>-->
<emptyTag attr=""/>
</tag>

View File

@@ -0,0 +1,6 @@
<selection><tag>
<!--<subtag>-->
Value
</subtag><caret></selection>
<emptyTag attr=""/>
</tag>

View File

@@ -0,0 +1,4 @@
<!--<xxx f="value">-->
<!--</xxx>-->
<!-- -->

View File

@@ -0,0 +1 @@
<!--<a>&#45;&#45;</a>-->

View File

@@ -0,0 +1,8 @@
<root>
<tag/>
<!--
&lt;!&ndash; Some comment &ndash;&gt;
-->
</root>

View File

@@ -0,0 +1,3 @@
<a>
<!-- - -->
</a>

View File

@@ -0,0 +1,3 @@
<a>
<!-- - -->
</a>

View File

@@ -0,0 +1,6 @@
<tag>
<caret> <subtag>
Value
</subtag>
<emptyTag attr=""/>
</tag>

View File

@@ -0,0 +1,2 @@
<caret>
<div></div>

View File

@@ -0,0 +1 @@
<div/> <caret>

View File

@@ -0,0 +1,6 @@
<tag>
<caret><!-- <subtag>-->
Value
</subtag>
<emptyTag attr=""/>
</tag>

View File

@@ -0,0 +1,6 @@
<tag>
<caret><!-- <subtag>
Value
</subtag>
<emptyTag attr=""/>
</tag>

View File

@@ -0,0 +1,6 @@
<tag>
<caret> <subtag>
Value
</subtag>
<emptyTag attr=""/>
</tag>

View File

@@ -0,0 +1,6 @@
<tag>
<!--<subtag>-->
<caret> Value
</subtag>
<emptyTag attr=""/>
</tag>

View File

@@ -0,0 +1,4 @@
<selection><layout class="org.apache.log4j.PatternLayout">
<!-- conversion pattern with 4 parts separated by #-#, second part is empty -->
<param name="ConversionPattern" value="[%t] %m#-##-#%d{dd.MM.yyyy}#-#%d{HH:mm:ss}" />
</layout></selection>

View File

@@ -0,0 +1,6 @@
<selection><tag>
<!--<subtag>-->
Value
</subtag><caret></selection>
<emptyTag attr=""/>
</tag>

View File

@@ -0,0 +1,6 @@
<!--<selection><tag>-->
<!--&lt;!&ndash;<subtag>&ndash;&gt;-->
<!--Value-->
<!--</subtag><caret></selection>-->
<emptyTag attr=""/>
</tag>

View File

@@ -0,0 +1,4 @@
<selection><xxx f="value">
</xxx>
<caret></selection>

View File

@@ -0,0 +1 @@
<a>--</a>

View File

@@ -0,0 +1,8 @@
<root>
<caret> <!--<tag/>-->
<!--
&lt;!&ndash; Some comment &ndash;&gt;
-->
</root>

View File

@@ -0,0 +1,3 @@
<a>
<caret>-
</a>

View File

@@ -0,0 +1,3 @@
<a>
<caret> -
</a>