mirror of
https://gitflic.ru/project/openide/openide.git
synced 2026-04-21 05:51:25 +07:00
move JoinLinesTest to java-tests
This commit is contained in:
@@ -0,0 +1,6 @@
|
||||
class Foo {
|
||||
{
|
||||
int <caret>x = 0;
|
||||
x += 2;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,5 @@
|
||||
class Foo {
|
||||
{
|
||||
int x = 0 + 2;<caret>
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,3 @@
|
||||
class Foo {<caret>
|
||||
int k;
|
||||
}
|
||||
@@ -0,0 +1,2 @@
|
||||
class Foo {<caret> int k;
|
||||
}
|
||||
@@ -0,0 +1,6 @@
|
||||
class Foo {
|
||||
{
|
||||
int x <caret>= 0;
|
||||
x = 3;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,5 @@
|
||||
class Foo {
|
||||
{
|
||||
int x = 3;<caret>
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,6 @@
|
||||
/**
|
||||
* line 1<caret>
|
||||
* line 2
|
||||
*/
|
||||
class A{
|
||||
}
|
||||
@@ -0,0 +1,5 @@
|
||||
/**
|
||||
* line 1<caret> line 2
|
||||
*/
|
||||
class A{
|
||||
}
|
||||
@@ -0,0 +1,6 @@
|
||||
public class Test {
|
||||
public static void main(String[] args) {
|
||||
<caret>if (abc)
|
||||
foo();
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,5 @@
|
||||
public class Test {
|
||||
public static void main(String[] args) {
|
||||
if (abc)<caret> foo();
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,6 @@
|
||||
public class Foo {
|
||||
{
|
||||
String a = null;<caret>
|
||||
a = "sss"; //stupid test
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,5 @@
|
||||
public class Foo {
|
||||
{
|
||||
String a = "sss"; //stupid test
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,6 @@
|
||||
class a {
|
||||
void foo() {
|
||||
String s = "abc\"" <caret>+
|
||||
"def";
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,5 @@
|
||||
class a {
|
||||
void foo() {
|
||||
String s = "abc\"<caret>def";
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,6 @@
|
||||
class A{
|
||||
{
|
||||
int <caret>i;
|
||||
i = 0;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,5 @@
|
||||
class A{
|
||||
{
|
||||
int i = 0;<caret>
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,4 @@
|
||||
class A{
|
||||
int <caret>a
|
||||
= 0;
|
||||
}
|
||||
@@ -0,0 +1,3 @@
|
||||
class A{
|
||||
int a<caret> = 0;
|
||||
}
|
||||
@@ -0,0 +1,7 @@
|
||||
class A{
|
||||
{
|
||||
foo();
|
||||
<caret>
|
||||
bar();
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,6 @@
|
||||
class A{
|
||||
{
|
||||
foo();
|
||||
<caret>bar();
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,5 @@
|
||||
class C {
|
||||
private void f() {<caret>
|
||||
int i = 0;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,4 @@
|
||||
class C {
|
||||
private void f() {<caret> int i = 0;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,7 @@
|
||||
|
||||
class foo {
|
||||
{
|
||||
String s = "abc" <caret> +
|
||||
"def";
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,6 @@
|
||||
|
||||
class foo {
|
||||
{
|
||||
String s = "abc<caret>def";
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,5 @@
|
||||
class Foo {
|
||||
{
|
||||
}
|
||||
<caret>
|
||||
}
|
||||
@@ -0,0 +1,4 @@
|
||||
class Foo {
|
||||
{
|
||||
}
|
||||
<caret>}
|
||||
@@ -0,0 +1,5 @@
|
||||
class Foo {
|
||||
{
|
||||
}
|
||||
<caret>
|
||||
}
|
||||
@@ -0,0 +1,4 @@
|
||||
class Foo {
|
||||
{
|
||||
}
|
||||
<caret>}
|
||||
@@ -0,0 +1,5 @@
|
||||
class Foo {
|
||||
{
|
||||
}
|
||||
<caret>
|
||||
}
|
||||
@@ -0,0 +1,4 @@
|
||||
class Foo {
|
||||
{
|
||||
}
|
||||
<caret>}
|
||||
@@ -0,0 +1,5 @@
|
||||
class Foo {
|
||||
{
|
||||
}
|
||||
<caret>
|
||||
}
|
||||
@@ -0,0 +1,4 @@
|
||||
class Foo {
|
||||
{
|
||||
}
|
||||
<caret>}
|
||||
@@ -0,0 +1,5 @@
|
||||
class Foo {
|
||||
{
|
||||
}
|
||||
<caret>
|
||||
}
|
||||
@@ -0,0 +1,4 @@
|
||||
class Foo {
|
||||
{
|
||||
}
|
||||
<caret>}
|
||||
@@ -0,0 +1,5 @@
|
||||
class Foo {
|
||||
{
|
||||
}
|
||||
<caret>
|
||||
}
|
||||
@@ -0,0 +1,4 @@
|
||||
class Foo {
|
||||
{
|
||||
}
|
||||
<caret>}
|
||||
@@ -0,0 +1,4 @@
|
||||
class Test {
|
||||
}<caret>
|
||||
// this line is mandatory
|
||||
|
||||
@@ -0,0 +1,3 @@
|
||||
class Test {
|
||||
}<caret> // this line is mandatory
|
||||
|
||||
@@ -0,0 +1,3 @@
|
||||
<caret>
|
||||
class Test {
|
||||
}
|
||||
@@ -0,0 +1,2 @@
|
||||
<caret>class Test {
|
||||
}
|
||||
@@ -0,0 +1,4 @@
|
||||
class A{
|
||||
// comment <caret>1
|
||||
// comment 2
|
||||
}
|
||||
@@ -0,0 +1,3 @@
|
||||
class A{
|
||||
// comment 1<caret> comment 2
|
||||
}
|
||||
@@ -0,0 +1,4 @@
|
||||
class A{
|
||||
String s <caret>= "hfjsdakhfjksda" +
|
||||
"djfkasdjkfjs";
|
||||
}
|
||||
@@ -0,0 +1,3 @@
|
||||
class A{
|
||||
String s = "hfjsdakhfjksda<caret>djfkasdjkfjs";
|
||||
}
|
||||
@@ -0,0 +1,7 @@
|
||||
public class BrokenAlignment {
|
||||
|
||||
public BrokenAlignment(String errorMessage) {
|
||||
<caret>if (StringUtils
|
||||
.contains(errorMessage, "'UK_ACCOUNT_USERNAME'")
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,7 @@
|
||||
public class BrokenAlignment {
|
||||
|
||||
public BrokenAlignment(String errorMessage) {
|
||||
if (StringUtils.contains(<caret>errorMessage,
|
||||
"'UK_ACCOUNT_USERNAME'")
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,9 @@
|
||||
class C {
|
||||
private void f(int p) {
|
||||
int i;
|
||||
if (p==0) {<caret>
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,7 @@
|
||||
class C {
|
||||
private void f(int p) {
|
||||
int i;
|
||||
if (p==0) <caret>return;
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,9 @@
|
||||
class C {
|
||||
private void f(int p) {
|
||||
int i;
|
||||
if (p==0) {<caret>
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,8 @@
|
||||
class C {
|
||||
private void f(int p) {
|
||||
int i;
|
||||
if (p==0) {<caret> return;
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,21 @@
|
||||
import javax.swing.*;
|
||||
import java.awt.*;
|
||||
|
||||
class Foo {
|
||||
void foo (){
|
||||
ButtonWithExtension button;<caret>
|
||||
button = new Foo.ButtonWithExtension("", "", "", "");
|
||||
}
|
||||
|
||||
private abstract class MyActionButton extends JComponent{
|
||||
protected MyActionButton(String s1, String s2, String s3, String s4) {
|
||||
}
|
||||
}
|
||||
|
||||
private class ButtonWithExtension extends MyActionButton {
|
||||
protected ButtonWithExtension(String s1, String s2, String s3, String s4) {
|
||||
super(s1, s2, s3, s4);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,20 @@
|
||||
import javax.swing.*;
|
||||
import java.awt.*;
|
||||
|
||||
class Foo {
|
||||
void foo (){
|
||||
ButtonWithExtension button = new ButtonWithExtension("", "", "", "");
|
||||
}
|
||||
|
||||
private abstract class MyActionButton extends JComponent{
|
||||
protected MyActionButton(String s1, String s2, String s3, String s4) {
|
||||
}
|
||||
}
|
||||
|
||||
private class ButtonWithExtension extends MyActionButton {
|
||||
protected ButtonWithExtension(String s1, String s2, String s3, String s4) {
|
||||
super(s1, s2, s3, s4);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,229 @@
|
||||
package com.intellij.codeInsight;
|
||||
|
||||
import com.intellij.JavaTestUtil;
|
||||
import com.intellij.ide.DataManager;
|
||||
import com.intellij.openapi.actionSystem.IdeActions;
|
||||
import com.intellij.openapi.editor.actionSystem.EditorActionHandler;
|
||||
import com.intellij.openapi.editor.actionSystem.EditorActionManager;
|
||||
import com.intellij.openapi.fileTypes.StdFileTypes;
|
||||
import com.intellij.psi.codeStyle.CodeStyleSettings;
|
||||
import com.intellij.psi.codeStyle.CodeStyleSettingsManager;
|
||||
import com.intellij.psi.codeStyle.CommonCodeStyleSettings;
|
||||
import com.intellij.testFramework.LightCodeInsightTestCase;
|
||||
import org.jdom.Element;
|
||||
import org.jetbrains.annotations.NonNls;
|
||||
|
||||
public class JoinLinesTest extends LightCodeInsightTestCase {
|
||||
@Override
|
||||
protected String getTestDataPath() {
|
||||
return JavaTestUtil.getJavaTestDataPath();
|
||||
}
|
||||
|
||||
public void testNormal() throws Exception { doTest(); }
|
||||
|
||||
public void testStringLiteral() throws Exception { doTest(); }
|
||||
public void testLiteralSCR4989() throws Exception { doTest(); }
|
||||
|
||||
public void testSCR3493() throws Exception {
|
||||
CodeStyleSettings settings = CodeStyleSettingsManager.getSettings(getProject());
|
||||
boolean use_tab_character = settings.useTabCharacter(null);
|
||||
boolean smart_tabs = settings.isSmartTabs(null);
|
||||
try {
|
||||
settings.getIndentOptions(StdFileTypes.JAVA).USE_TAB_CHARACTER = true;
|
||||
settings.getIndentOptions(StdFileTypes.JAVA).SMART_TABS = true;
|
||||
doTest();
|
||||
} finally {
|
||||
settings.getIndentOptions(StdFileTypes.JAVA).USE_TAB_CHARACTER = use_tab_character;
|
||||
settings.getIndentOptions(StdFileTypes.JAVA).SMART_TABS = smart_tabs;
|
||||
}
|
||||
}
|
||||
public void testSCR3493a() throws Exception {
|
||||
CodeStyleSettings settings = CodeStyleSettingsManager.getSettings(getProject());
|
||||
boolean use_tab_character = settings.useTabCharacter(null);
|
||||
boolean smart_tabs = settings.isSmartTabs(null);
|
||||
try {
|
||||
settings.getIndentOptions(StdFileTypes.JAVA).USE_TAB_CHARACTER = true;
|
||||
settings.getIndentOptions(StdFileTypes.JAVA).SMART_TABS = true;
|
||||
doTest();
|
||||
} finally {
|
||||
settings.getIndentOptions(StdFileTypes.JAVA).USE_TAB_CHARACTER = use_tab_character;
|
||||
settings.getIndentOptions(StdFileTypes.JAVA).SMART_TABS = smart_tabs;
|
||||
}
|
||||
}
|
||||
public void testSCR3493b() throws Exception {
|
||||
CodeStyleSettings settings = CodeStyleSettingsManager.getSettings(getProject());
|
||||
boolean use_tab_character = settings.useTabCharacter(null);
|
||||
boolean smart_tabs = settings.isSmartTabs(null);
|
||||
try {
|
||||
settings.getIndentOptions(StdFileTypes.JAVA).USE_TAB_CHARACTER = true;
|
||||
settings.getIndentOptions(StdFileTypes.JAVA).SMART_TABS = true;
|
||||
doTest();
|
||||
} finally {
|
||||
settings.getIndentOptions(StdFileTypes.JAVA).USE_TAB_CHARACTER = use_tab_character;
|
||||
settings.getIndentOptions(StdFileTypes.JAVA).SMART_TABS = smart_tabs;
|
||||
}
|
||||
}
|
||||
public void testSCR3493c() throws Exception {
|
||||
CodeStyleSettings settings = CodeStyleSettingsManager.getSettings(getProject());
|
||||
boolean use_tab_character = settings.useTabCharacter(null);
|
||||
boolean smart_tabs = settings.isSmartTabs(null);
|
||||
try {
|
||||
settings.getIndentOptions(StdFileTypes.JAVA).USE_TAB_CHARACTER = true;
|
||||
settings.getIndentOptions(StdFileTypes.JAVA).SMART_TABS = true;
|
||||
doTest();
|
||||
} finally {
|
||||
settings.getIndentOptions(StdFileTypes.JAVA).USE_TAB_CHARACTER = use_tab_character;
|
||||
settings.getIndentOptions(StdFileTypes.JAVA).SMART_TABS = smart_tabs;
|
||||
}
|
||||
}
|
||||
public void testSCR3493d() throws Exception {
|
||||
CodeStyleSettings settings = CodeStyleSettingsManager.getSettings(getProject());
|
||||
boolean use_tab_character = settings.useTabCharacter(null);
|
||||
boolean smart_tabs = settings.isSmartTabs(null);
|
||||
try {
|
||||
settings.getIndentOptions(StdFileTypes.JAVA).USE_TAB_CHARACTER = true;
|
||||
settings.getIndentOptions(StdFileTypes.JAVA).SMART_TABS = true;
|
||||
doTest();
|
||||
} finally {
|
||||
settings.getIndentOptions(StdFileTypes.JAVA).USE_TAB_CHARACTER = use_tab_character;
|
||||
settings.getIndentOptions(StdFileTypes.JAVA).SMART_TABS = smart_tabs;
|
||||
}
|
||||
}
|
||||
public void testSCR3493e() throws Exception {
|
||||
CodeStyleSettings settings = CodeStyleSettingsManager.getSettings(getProject());
|
||||
boolean use_tab_character = settings.useTabCharacter(null);
|
||||
boolean smart_tabs = settings.isSmartTabs(null);
|
||||
try {
|
||||
settings.getIndentOptions(StdFileTypes.JAVA).USE_TAB_CHARACTER = true;
|
||||
settings.getIndentOptions(StdFileTypes.JAVA).SMART_TABS = true;
|
||||
doTest();
|
||||
} finally {
|
||||
settings.getIndentOptions(StdFileTypes.JAVA).USE_TAB_CHARACTER = use_tab_character;
|
||||
settings.getIndentOptions(StdFileTypes.JAVA).SMART_TABS = smart_tabs;
|
||||
}
|
||||
}
|
||||
public void testSCR5959() throws Exception {
|
||||
doTest();
|
||||
}
|
||||
public void testSCR6299() throws Exception {
|
||||
doTest();
|
||||
}
|
||||
|
||||
public void testLocalVar() throws Exception { doTest(); }
|
||||
|
||||
public void testSlashComment() throws Exception { doTest(); }
|
||||
public void testDocComment() throws Exception { doTest(); }
|
||||
|
||||
public void testOnEmptyLine() throws Exception { doTest(); }
|
||||
public void testCollapseClass() throws Exception { doTest(); }
|
||||
public void testSCR10386() throws Exception { doTest(); }
|
||||
public void testDeclarationWithInitializer() throws Exception {doTest(); }
|
||||
public void testUnwrapCodeBlock1() throws Exception {
|
||||
CodeStyleSettings settings = CodeStyleSettingsManager.getSettings(getProject());
|
||||
boolean use_tab_character = settings.useTabCharacter(null);
|
||||
boolean smart_tabs = settings.isSmartTabs(null);
|
||||
int old = settings.IF_BRACE_FORCE;
|
||||
try {
|
||||
settings.getIndentOptions(StdFileTypes.JAVA).USE_TAB_CHARACTER = true;
|
||||
settings.getIndentOptions(StdFileTypes.JAVA).SMART_TABS = true;
|
||||
settings.IF_BRACE_FORCE = CommonCodeStyleSettings.FORCE_BRACES_IF_MULTILINE;
|
||||
doTest();
|
||||
} finally {
|
||||
settings.getIndentOptions(StdFileTypes.JAVA).USE_TAB_CHARACTER = use_tab_character;
|
||||
settings.getIndentOptions(StdFileTypes.JAVA).SMART_TABS = smart_tabs;
|
||||
settings.IF_BRACE_FORCE = old;
|
||||
}
|
||||
}
|
||||
public void testUnwrapCodeBlock2() throws Exception {
|
||||
CodeStyleSettings settings = CodeStyleSettingsManager.getSettings(getProject());
|
||||
boolean use_tab_character = settings.useTabCharacter(null);
|
||||
boolean smart_tabs = settings.isSmartTabs(null);
|
||||
int old = settings.IF_BRACE_FORCE;
|
||||
try {
|
||||
settings.getIndentOptions(StdFileTypes.JAVA).USE_TAB_CHARACTER = true;
|
||||
settings.getIndentOptions(StdFileTypes.JAVA).SMART_TABS = true;
|
||||
settings.IF_BRACE_FORCE = CommonCodeStyleSettings.FORCE_BRACES_ALWAYS;
|
||||
doTest();
|
||||
} finally {
|
||||
settings.getIndentOptions(StdFileTypes.JAVA).USE_TAB_CHARACTER = use_tab_character;
|
||||
settings.getIndentOptions(StdFileTypes.JAVA).SMART_TABS = smart_tabs;
|
||||
settings.IF_BRACE_FORCE = old;
|
||||
}
|
||||
}
|
||||
|
||||
public void testAssignmentExpression() throws Exception {
|
||||
doTest();
|
||||
}
|
||||
public void testReformatInsertsNewlines() throws Exception {
|
||||
CodeStyleSettings settings = CodeStyleSettingsManager.getSettings(getProject());
|
||||
final Element root = new Element("fake");
|
||||
settings.writeExternal(root);
|
||||
try {
|
||||
settings.getIndentOptions(StdFileTypes.JAVA).USE_TAB_CHARACTER = true;
|
||||
settings.getIndentOptions(StdFileTypes.JAVA).SMART_TABS = true;
|
||||
settings.IF_BRACE_FORCE = CommonCodeStyleSettings.FORCE_BRACES_ALWAYS;
|
||||
settings.METHOD_BRACE_STYLE = CommonCodeStyleSettings.NEXT_LINE;
|
||||
doTest();
|
||||
} finally {
|
||||
settings.readExternal(root);
|
||||
}
|
||||
}
|
||||
|
||||
public void testForceBrace() throws Exception {
|
||||
CodeStyleSettings settings = CodeStyleSettingsManager.getSettings(getProject());
|
||||
int old = settings.IF_BRACE_FORCE;
|
||||
try {
|
||||
settings.IF_BRACE_FORCE = CommonCodeStyleSettings.FORCE_BRACES_ALWAYS;
|
||||
doTest();
|
||||
} finally {
|
||||
settings.IF_BRACE_FORCE = old;
|
||||
}
|
||||
}
|
||||
|
||||
public void testWrongWrapping() throws Exception{
|
||||
CodeStyleSettings settings = CodeStyleSettingsManager.getSettings(getProject());
|
||||
settings.setDefaultRightMargin(80);
|
||||
settings.CALL_PARAMETERS_WRAP = CommonCodeStyleSettings.WRAP_AS_NEEDED;
|
||||
settings.ALIGN_MULTILINE_PARAMETERS_IN_CALLS = true;
|
||||
doTest();
|
||||
}
|
||||
|
||||
public void testSubsequentJoiningAndUnexpectedTextRemoval() throws Exception {
|
||||
// Inspired by IDEA-65342
|
||||
CodeStyleSettings settings = CodeStyleSettingsManager.getSettings(getProject());
|
||||
settings.setDefaultRightMargin(50);
|
||||
settings.CALL_PARAMETERS_WRAP = CommonCodeStyleSettings.WRAP_AS_NEEDED;
|
||||
doTest(2);
|
||||
}
|
||||
|
||||
public void testLeaveTrailingComment() throws Exception { doTest(); }
|
||||
|
||||
private void doTest() throws Exception {
|
||||
doTest(".java");
|
||||
}
|
||||
|
||||
private void doTest(int times) throws Exception {
|
||||
doTest(".java", times);
|
||||
}
|
||||
|
||||
private void doTest(@NonNls final String ext) throws Exception {
|
||||
doTest(ext, 1);
|
||||
}
|
||||
|
||||
private void doTest(@NonNls final String ext, int times) throws Exception {
|
||||
@NonNls String path = "/codeInsight/joinLines/";
|
||||
|
||||
configureByFile(path + getTestName(false) + ext);
|
||||
while (times-- > 0) {
|
||||
performAction();
|
||||
}
|
||||
checkResultByFile(path + getTestName(false) + "_after" + ext);
|
||||
}
|
||||
|
||||
private void performAction() {
|
||||
EditorActionManager actionManager = EditorActionManager.getInstance();
|
||||
EditorActionHandler actionHandler = actionManager.getActionHandler(IdeActions.ACTION_EDITOR_JOIN_LINES);
|
||||
|
||||
actionHandler.execute(getEditor(), DataManager.getInstance().getDataContext());
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user