Extract Java and XML specific parts out of CommentByBlockTest

GitOrigin-RevId: 500c2c8ea836e4ec4131f626310f00f9b0737f2e
This commit is contained in:
Dmitry Jemerov
2022-04-28 17:30:30 +02:00
committed by intellij-monorepo-bot
parent 0b16d0a9dd
commit cbd42f55d8
44 changed files with 506 additions and 0 deletions

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

@@ -0,0 +1,14 @@
package temp;
public class Test {
public String method(
String string1,
String string2) {
<selection> /*
if ("something".equals(string1)) {
return string2;
}
*/
</selection> return null;
}
}

View File

@@ -0,0 +1,12 @@
package temp;
public class Test {
public String method(
String string1,
String string2) {
<selection> if ("something".equals(string1)) {
return string2;
}
</selection> return null;
}
}

View File

@@ -0,0 +1,10 @@
class A {
void foo() {
<selection>/*
nameWidth += tree.getFontMetrics(tree.getFont()*/
/*.deriveFont(Font.ITALIC)*//*
).stringWidth(text);
*/
</selection>
}
}

View File

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

View File

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

View File

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

View File

@@ -0,0 +1,12 @@
package temp;
public class Test {
public String method(
String string1,
String string2) {
<selection> if ("something".equals(string1)) {
return string2;
}
</selection> return null;
}
}

View File

@@ -0,0 +1,14 @@
package temp;
public class Test {
public String method(
String string1,
String string2) {
<selection> /*
if ("something".equals(string1)) {
return string2;
}
*/
</selection> return null;
}
}

View File

@@ -0,0 +1,6 @@
class A {
void foo() {
<caret><selection> nameWidth += tree.getFontMetrics(tree.getFont()/*.deriveFont(Font.ITALIC)*/).stringWidth(text);
</selection>
}
}

View File

@@ -0,0 +1,120 @@
// 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.application.options.CodeStyle;
import com.intellij.lang.java.JavaLanguage;
import com.intellij.openapi.actionSystem.IdeActions;
import com.intellij.psi.codeStyle.CommonCodeStyleSettings;
import com.intellij.testFramework.EditorTestUtil;
import com.intellij.testFramework.LightPlatformCodeInsightTestCase;
import org.jetbrains.annotations.NotNull;
public class JavaCommentByBlockTest extends LightPlatformCodeInsightTestCase {
@Override
protected @NotNull String getTestDataPath() {
return JavaTestUtil.getJavaTestDataPath();
}
public void testIDEADEV27995() {
configureByFile("/codeInsight/commentByBlock/java/beforeIdeadev27995.java");
performAction();
checkResultByFile("/codeInsight/commentByBlock/java/afterIdeadev27995.java");
}
public void testJava1() {
configureByFile("/codeInsight/commentByBlock/java/before1.java");
performAction();
checkResultByFile("/codeInsight/commentByBlock/java/after1.java");
}
public void testJava2() {
configureByFile("/codeInsight/commentByBlock/java/before2.java");
performAction();
checkResultByFile("/codeInsight/commentByBlock/java/after2.java");
}
public void testJava3() {
configureByFile("/codeInsight/commentByBlock/java/before3.java");
performAction();
checkResultByFile("/codeInsight/commentByBlock/java/after3.java");
}
public void testJava4() {
CommonCodeStyleSettings javaSettings = CodeStyle.getSettings(getProject()).getCommonSettings(JavaLanguage.INSTANCE);
boolean blockCommentAtFirstCol = javaSettings.BLOCK_COMMENT_AT_FIRST_COLUMN;
try {
javaSettings.BLOCK_COMMENT_AT_FIRST_COLUMN = false;
configureByFile("/codeInsight/commentByBlock/java/before4.java");
performAction();
checkResultByFile("/codeInsight/commentByBlock/java/after4.java");
}
finally {
javaSettings.BLOCK_COMMENT_AT_FIRST_COLUMN = blockCommentAtFirstCol;
}
}
public void testJava5() {
CommonCodeStyleSettings javaSettings = CodeStyle.getSettings(getProject()).getCommonSettings(JavaLanguage.INSTANCE);
boolean blockCommentAtFirstCol = javaSettings.BLOCK_COMMENT_AT_FIRST_COLUMN;
try {
javaSettings.BLOCK_COMMENT_AT_FIRST_COLUMN = false;
configureByFile("/codeInsight/commentByBlock/java/before5.java");
performAction();
checkResultByFile("/codeInsight/commentByBlock/java/after5.java");
}
finally {
javaSettings.BLOCK_COMMENT_AT_FIRST_COLUMN = blockCommentAtFirstCol;
}
}
public void testMulticaret() {
configureByFile("/codeInsight/commentByBlock/java/MulticaretBefore.java");
performAction();
checkResultByFile("/codeInsight/commentByBlock/java/MulticaretAfter.java");
}
public void testMulticaretUncomment() {
configureByFile("/codeInsight/commentByBlock/java/MulticaretUncommentBefore.java");
performAction();
checkResultByFile("/codeInsight/commentByBlock/java/MulticaretUncommentAfter.java");
}
public void testCommentStringWithBlockPrefix() {
doTestForText("class C { <selection>String s = \"/*\";<caret></selection> }",
"class C { <selection>/*String s = \"/*\";<caret>*/</selection> }");
}
public void testCommentStringWithBlockSuffix() {
doTestForText("class C { <selection>String s = \"*/\";<caret></selection> }",
"class C { <selection>String s = \"*/\";<caret></selection> }");
}
public void testCommentRangeIntersectingWithExistingComment() {
doTestForText("class C { /* some <selection>comment */ int i = 3;<caret></selection> }",
"class C { /* some <selection>comment */ int i = 3;<caret></selection> }");
}
public void testSelectionContainsJavadoc() {
doTestForText("class C {\n" +
" <selection>int a;\n" +
" /** doc */\n" +
" int b;<caret></selection>\n" +
"}",
"class C {\n" +
" <selection>/*int a;\n" +
" *//** doc *//*\n" +
" int b;*/<caret></selection>\n" +
"}");
}
private void doTestForText(String before, String after) {
configureFromFileText(getTestName(true) + ".java", before);
performAction();
checkResultByText(after);
}
private void performAction() {
EditorTestUtil.executeAction(getEditor(), IdeActions.ACTION_COMMENT_BLOCK);
}
}

View File

@@ -0,0 +1,106 @@
// 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.testFramework.EditorTestUtil;
import com.intellij.testFramework.LightPlatformCodeInsightTestCase;
import com.intellij.testFramework.PlatformTestUtil;
import org.jetbrains.annotations.NotNull;
import java.io.File;
public class XmlCommentByBlockTest extends LightPlatformCodeInsightTestCase {
@Override
protected @NotNull String getTestDataPath() {
return PlatformTestUtil.getCommunityPath().replace(File.separatorChar, '/') + "/xml/tests/testData";
}
public void testXml1() {
configureByFile("/codeInsight/commentByBlock/xml/before1.xml");
performAction();
checkResultByFile("/codeInsight/commentByBlock/xml/after1.xml");
}
public void testXml2() {
configureByFile("/codeInsight/commentByBlock/xml/before2.xml");
performAction();
checkResultByFile("/codeInsight/commentByBlock/xml/after2.xml");
}
public void test3() {
doTest();
}
public void testDoubleDash() {
doTest();
}
public void testSingleDash() {
doTest(false);
}
public void testSelfClosing() {
doTest();
}
private void doTest() {
doTest(false);
doTest(true);
}
private void doTest(boolean invert) {
String test = getTestName(false);
String before = invert ? "after" : "before";
configureByFile("/codeInsight/commentByBlock/xml/" + before + test + ".xml");
performAction();
String after = invert ? "before" : "after";
checkResultByFile("/codeInsight/commentByBlock/xml/" + after + test + ".xml");
}
public void testHtml1() {
configureByFile("/codeInsight/commentByBlock/html/before1.html");
performAction();
checkResultByFile("/codeInsight/commentByBlock/html/after1.html");
}
public void testHtml2() {
configureByFile("/codeInsight/commentByBlock/html/before2.html");
performAction();
checkResultByFile("/codeInsight/commentByBlock/html/after2.html");
}
public void testNestedXml() {
configureByFile("/codeInsight/commentByBlock/xml/before4.xml");
performAction();
checkResultByFile("/codeInsight/commentByBlock/xml/after4.xml");
}
public void testNestedHtml() {
configureByFile("/codeInsight/commentByBlock/html/before3.html");
performAction();
checkResultByFile("/codeInsight/commentByBlock/html/after3.html");
}
public void testRightUncommentBoundsXml() {
configureByFile("/codeInsight/commentByBlock/xml/before5.xml");
performAction();
checkResultByFile("/codeInsight/commentByBlock/xml/after5.xml");
}
public void testIdeaDev25498_1() {
configureByFile("/codeInsight/commentByBlock/xml/beforeIdeaDev25498_1.xml");
performAction();
checkResultByFile("/codeInsight/commentByBlock/xml/afterIdeaDev25498_1.xml");
}
public void testIdeaDev25498_2() {
configureByFile("/codeInsight/commentByBlock/xml/beforeIdeaDev25498_2.xml");
performAction();
checkResultByFile("/codeInsight/commentByBlock/xml/afterIdeaDev25498_2.xml");
}
private void performAction() {
EditorTestUtil.executeAction(getEditor(), IdeActions.ACTION_COMMENT_BLOCK);
}
}

View File

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

View File

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

View File

@@ -0,0 +1,11 @@
<html>
<!-- comment 1 -->
<br>sometext
<selection><!--
<p align="right">paragraph</p>
<p>sometext &lt;!&ndash; comment 2 &ndash;&gt;</p>
&lt;!&ndash; comment 3
&ndash;&gt;
-->
</selection>
</html>

View File

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

View File

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

View File

@@ -0,0 +1,9 @@
<html>
<!-- comment 1 -->
<br>sometext
<selection><p align="right"><caret>paragraph</p>
<p>sometext <!-- comment 2 --></p>
<!-- comment 3
-->
</selection>
</html>

View File

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

View File

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

View File

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

View File

@@ -0,0 +1,8 @@
<selection><!--
<caret><tag>
&lt;!&ndash;
<subtag></subtag>
&ndash;&gt;
</tag>
-->
</selection>

View File

@@ -0,0 +1,8 @@
<a>
<selection><b>
t
</b>
<c>
b<caret>
</c></selection>
</a>

View File

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

View File

@@ -0,0 +1,10 @@
<selection><!--
<distributionManagement>
&lt;!&ndash; Climbing Vine Repository Distribution &ndash;&gt;
<repository>
<id>cv</id>
<name>CV Repository</name>
<url>scp://maven.climbingvine.ca/var/www/maven.climbingvine.ca/htdocs/</url>
</repository>
</distributionManagement>-->
</selection>

View File

@@ -0,0 +1,8 @@
<selection><distributionManagement>
<!-- Climbing Vine Repository Distribution -->
<repository>
<id>cv</id>
<name>CV Repository</name>
<url>scp://maven.climbingvine.ca/var/www/maven.climbingvine.ca/htdocs/</url>
</repository>
</distributionManagement></selection>

View File

@@ -0,0 +1 @@
<a><selection><!--&gt;--></selection></a>

View File

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

View File

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

View File

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

View File

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

View File

@@ -0,0 +1,6 @@
<selection><caret><tag>
<!--
<subtag></subtag>
-->
</tag>
</selection>

View File

@@ -0,0 +1,8 @@
<a>
<selection><!--<b>
t
</b>-->
<!--<c>
b<caret>
</c>--></selection>
</a>

View File

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

View File

@@ -0,0 +1,8 @@
<selection><distributionManagement>
<!-- Climbing Vine Repository Distribution -->
<repository>
<id>cv</id>
<name>CV Repository</name>
<url>scp://maven.climbingvine.ca/var/www/maven.climbingvine.ca/htdocs/</url>
</repository>
</distributionManagement></selection>

View File

@@ -0,0 +1,8 @@
<selection><!--<distributionManagement>
&lt;!&ndash; Climbing Vine Repository Distribution &ndash;&gt;
<repository>
<id>cv</id>
<name>CV Repository</name>
<url>scp://maven.climbingvine.ca/var/www/maven.climbingvine.ca/htdocs/</url>
</repository>
</distributionManagement>--></selection>

View File

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

View File

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