mirror of
https://gitflic.ru/project/openide/openide.git
synced 2026-01-04 08:51:02 +07:00
Couple of tests moved from old JavaFormatterTest class to fine-grained test classes
This commit is contained in:
@@ -17,6 +17,7 @@ package com.intellij.psi.formatter.java;
|
||||
|
||||
import com.intellij.openapi.fileTypes.StdFileTypes;
|
||||
import com.intellij.psi.codeStyle.CodeStyleSettings;
|
||||
import com.intellij.util.IncorrectOperationException;
|
||||
|
||||
/**
|
||||
* Is intended to hold specific java formatting tests for alignment settings (
|
||||
@@ -59,4 +60,49 @@ public class JavaFormatterAlignmentTest extends AbstractJavaFormatterTest {
|
||||
"}"
|
||||
);
|
||||
}
|
||||
|
||||
public void testTernaryOperator() throws Exception {
|
||||
// Inspired by IDEADEV-13018
|
||||
getSettings().ALIGN_MULTILINE_TERNARY_OPERATION = true;
|
||||
|
||||
doMethodTest("int i = a ? x\n" + ": y;", "int i = a ? x\n" + " : y;");
|
||||
}
|
||||
|
||||
public void testMethodCallArgumentsAndSmartTabs() throws IncorrectOperationException {
|
||||
// Inspired by IDEADEV-20144.
|
||||
getSettings().ALIGN_MULTILINE_PARAMETERS_IN_CALLS = true;
|
||||
getSettings().getIndentOptions(StdFileTypes.JAVA).SMART_TABS = true;
|
||||
getSettings().getIndentOptions(StdFileTypes.JAVA).USE_TAB_CHARACTER = true;
|
||||
doTextTest("class Foo {\n" +
|
||||
" void foo() {\n" +
|
||||
" bar(new Object[] {\n" +
|
||||
" \"hello1\",\n" +
|
||||
" \"hello2\", add(\"hello3\",\n" +
|
||||
" \"world\")\n" +
|
||||
"});" +
|
||||
" }}", "class Foo {\n" +
|
||||
"\tvoid foo() {\n" +
|
||||
"\t\tbar(new Object[]{\n" +
|
||||
"\t\t\t\t\"hello1\",\n" +
|
||||
"\t\t\t\t\"hello2\", add(\"hello3\",\n" +
|
||||
"\t\t\t\t \"world\")\n" +
|
||||
"\t\t});\n" +
|
||||
"\t}\n" +
|
||||
"}");
|
||||
}
|
||||
|
||||
public void testArrayInitializer() throws IncorrectOperationException {
|
||||
// Inspired by IDEADEV-16136
|
||||
getSettings().ARRAY_INITIALIZER_WRAP = CodeStyleSettings.WRAP_ALWAYS;
|
||||
getSettings().ALIGN_MULTILINE_ARRAY_INITIALIZER_EXPRESSION = true;
|
||||
|
||||
doTextTest(
|
||||
"@SuppressWarnings({\"UseOfSystemOutOrSystemErr\", \"AssignmentToCollectionOrArrayFieldFromParameter\", \"ReturnOfCollectionOrArrayField\"})\n" +
|
||||
"public class Some {\n" +
|
||||
"}", "@SuppressWarnings({\"UseOfSystemOutOrSystemErr\",\n" +
|
||||
" \"AssignmentToCollectionOrArrayFieldFromParameter\",\n" +
|
||||
" \"ReturnOfCollectionOrArrayField\"})\n" +
|
||||
"public class Some {\n" +
|
||||
"}");
|
||||
}
|
||||
}
|
||||
|
||||
@@ -17,6 +17,7 @@ package com.intellij.psi.formatter.java;
|
||||
|
||||
import com.intellij.openapi.fileTypes.StdFileTypes;
|
||||
import com.intellij.psi.codeStyle.CodeStyleSettings;
|
||||
import com.intellij.util.IncorrectOperationException;
|
||||
|
||||
/**
|
||||
* Is intended to hold java formatting indentation-specific tests.
|
||||
@@ -155,4 +156,51 @@ public class JavaFormatterIndentationTest extends AbstractJavaFormatterTest {
|
||||
"}"
|
||||
);
|
||||
}
|
||||
|
||||
public void testEnumIndentation() throws IncorrectOperationException {
|
||||
// Inspired by IDEADEV-2840
|
||||
doTextTest("enum Xyz {\n" + "FOO,\n" + "BAR,\n" + "}", "enum Xyz {\n" + " FOO,\n" + " BAR,\n" + "}");
|
||||
}
|
||||
|
||||
public void testFirstColumnComment() throws IncorrectOperationException {
|
||||
// Inspired by IDEADEV-14116
|
||||
getSettings().KEEP_FIRST_COLUMN_COMMENT = false;
|
||||
|
||||
doTextTest("class Foo{\n" + "private int foo; // this is a foo\n" + "}",
|
||||
"class Foo {\n" + " private int foo; // this is a foo\n" + "}");
|
||||
}
|
||||
|
||||
public void testCaseFromSwitch() throws IncorrectOperationException {
|
||||
// Inspired by IDEADEV-22920
|
||||
getSettings().INDENT_CASE_FROM_SWITCH = false;
|
||||
doTextTest("class Foo{\n" +
|
||||
"void foo () {\n" +
|
||||
"switch(someValue) {\n" +
|
||||
" // This comment is correctly not-indented\n" +
|
||||
" case 1:\n" +
|
||||
" doSomething();\n" +
|
||||
" break;\n" +
|
||||
"\n" +
|
||||
" // This comment should not be indented, but it is\n" +
|
||||
" case 2:\n" +
|
||||
" doSomethingElse();\n" +
|
||||
" break;\n" +
|
||||
"}\n" +
|
||||
"}\n" +
|
||||
"}", "class Foo {\n" +
|
||||
" void foo() {\n" +
|
||||
" switch (someValue) {\n" +
|
||||
" // This comment is correctly not-indented\n" +
|
||||
" case 1:\n" +
|
||||
" doSomething();\n" +
|
||||
" break;\n" +
|
||||
"\n" +
|
||||
" // This comment should not be indented, but it is\n" +
|
||||
" case 2:\n" +
|
||||
" doSomethingElse();\n" +
|
||||
" break;\n" +
|
||||
" }\n" +
|
||||
" }\n" +
|
||||
"}");
|
||||
}
|
||||
}
|
||||
|
||||
@@ -16,6 +16,8 @@
|
||||
package com.intellij.psi.formatter.java;
|
||||
|
||||
import com.intellij.openapi.fileTypes.StdFileTypes;
|
||||
import com.intellij.psi.codeStyle.CodeStyleSettings;
|
||||
import com.intellij.util.IncorrectOperationException;
|
||||
|
||||
/**
|
||||
* Is intended to hold specific java formatting tests for <code>'Place on New Line'</code> settings (
|
||||
@@ -163,4 +165,31 @@ public class JavaFormatterNewLineTest extends AbstractJavaFormatterTest {
|
||||
// Inspired by IDEA-17870
|
||||
doClassTest("public Test(@Qualifier(\"blah\") AType blah){}", "public Test(@Qualifier(\"blah\") AType blah) {\n" + "}");
|
||||
}
|
||||
|
||||
public void testArrayInitializer() throws IncorrectOperationException {
|
||||
// Inspired by IDEADEV-6787
|
||||
getSettings().ARRAY_INITIALIZER_WRAP = CodeStyleSettings.WRAP_ALWAYS;
|
||||
getSettings().ARRAY_INITIALIZER_LBRACE_ON_NEXT_LINE = true;
|
||||
getSettings().ARRAY_INITIALIZER_RBRACE_ON_NEXT_LINE = true;
|
||||
doTextTest(
|
||||
"public @interface Ann\n" +
|
||||
"{\n" +
|
||||
"int[] x = { 1, 2 };\n" +
|
||||
"\n" +
|
||||
"Mode[] modes () default { @Mode(value = 1), @Mode(value = 2) };\n" +
|
||||
"}",
|
||||
|
||||
"public @interface Ann {\n" +
|
||||
" int[] x = {\n" +
|
||||
" 1,\n" +
|
||||
" 2\n" +
|
||||
" };\n" +
|
||||
"\n" +
|
||||
" Mode[] modes() default {\n" +
|
||||
" @Mode(value = 1),\n" +
|
||||
" @Mode(value = 2)\n" +
|
||||
" };\n" +
|
||||
"}"
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -2957,132 +2957,4 @@ public void testSCR260() throws Exception {
|
||||
doTextTest("public interface TestInterface {\n" + " @Deprecated\n" + " <T> void parametrizedAnnotated(T data);\n" + "}",
|
||||
"public interface TestInterface {\n" + " @Deprecated\n" + " <T> void parametrizedAnnotated(T data);\n" + "}");
|
||||
}
|
||||
|
||||
public void testIDEADEV_22920() throws IncorrectOperationException {
|
||||
getSettings().INDENT_CASE_FROM_SWITCH = false;
|
||||
doTextTest("class Foo{\n" +
|
||||
"void foo () {\n" +
|
||||
"switch(someValue) {\n" +
|
||||
" // This comment is correctly not-indented\n" +
|
||||
" case 1:\n" +
|
||||
" doSomething();\n" +
|
||||
" break;\n" +
|
||||
"\n" +
|
||||
" // This comment should not be indented, but it is\n" +
|
||||
" case 2:\n" +
|
||||
" doSomethingElse();\n" +
|
||||
" break;\n" +
|
||||
"}\n" +
|
||||
"}\n" +
|
||||
"}", "class Foo {\n" +
|
||||
" void foo() {\n" +
|
||||
" switch (someValue) {\n" +
|
||||
" // This comment is correctly not-indented\n" +
|
||||
" case 1:\n" +
|
||||
" doSomething();\n" +
|
||||
" break;\n" +
|
||||
"\n" +
|
||||
" // This comment should not be indented, but it is\n" +
|
||||
" case 2:\n" +
|
||||
" doSomethingElse();\n" +
|
||||
" break;\n" +
|
||||
" }\n" +
|
||||
" }\n" +
|
||||
"}");
|
||||
}
|
||||
|
||||
public void testIDEADEV_16136() throws IncorrectOperationException {
|
||||
getSettings().ARRAY_INITIALIZER_WRAP = CodeStyleSettings.WRAP_ALWAYS;
|
||||
getSettings().ALIGN_MULTILINE_ARRAY_INITIALIZER_EXPRESSION = true;
|
||||
|
||||
doTextTest(
|
||||
"@SuppressWarnings({\"UseOfSystemOutOrSystemErr\", \"AssignmentToCollectionOrArrayFieldFromParameter\", \"ReturnOfCollectionOrArrayField\"})\n" +
|
||||
"public class Some {\n" +
|
||||
"}", "@SuppressWarnings({\"UseOfSystemOutOrSystemErr\",\n" +
|
||||
" \"AssignmentToCollectionOrArrayFieldFromParameter\",\n" +
|
||||
" \"ReturnOfCollectionOrArrayField\"})\n" +
|
||||
"public class Some {\n" +
|
||||
"}");
|
||||
}
|
||||
|
||||
public void testIDEADEV_20144() throws IncorrectOperationException {
|
||||
getSettings().ALIGN_MULTILINE_PARAMETERS_IN_CALLS = true;
|
||||
getSettings().getIndentOptions(StdFileTypes.JAVA).SMART_TABS = true;
|
||||
getSettings().getIndentOptions(StdFileTypes.JAVA).USE_TAB_CHARACTER = true;
|
||||
doTextTest("class Foo {\n" +
|
||||
" void foo() {\n" +
|
||||
" bar(new Object[] {\n" +
|
||||
" \"hello1\",\n" +
|
||||
" \"hello2\", add(\"hello3\",\n" +
|
||||
" \"world\")\n" +
|
||||
"});" +
|
||||
" }}", "class Foo {\n" +
|
||||
"\tvoid foo() {\n" +
|
||||
"\t\tbar(new Object[]{\n" +
|
||||
"\t\t\t\t\"hello1\",\n" +
|
||||
"\t\t\t\t\"hello2\", add(\"hello3\",\n" +
|
||||
"\t\t\t\t \"world\")\n" +
|
||||
"\t\t});\n" +
|
||||
"\t}\n" +
|
||||
"}");
|
||||
}
|
||||
|
||||
|
||||
public void testIDEADEV_14116() throws IncorrectOperationException {
|
||||
getSettings().KEEP_FIRST_COLUMN_COMMENT = false;
|
||||
|
||||
doTextTest("class Foo{\n" + "private int foo; // this is a foo\n" + "}",
|
||||
"class Foo {\n" + " private int foo; // this is a foo\n" + "}");
|
||||
}
|
||||
|
||||
public void testIDEADEV_13018() throws Exception {
|
||||
getSettings().ALIGN_MULTILINE_TERNARY_OPERATION = true;
|
||||
|
||||
doMethodTest("int i = a ? x\n" + ": y;", "int i = a ? x\n" + " : y;");
|
||||
}
|
||||
|
||||
public void testIDEADEV_2840() throws IncorrectOperationException {
|
||||
doTextTest("enum Xyz {\n" + "FOO,\n" + "BAR,\n" + "}", "enum Xyz {\n" + " FOO,\n" + " BAR,\n" + "}");
|
||||
}
|
||||
|
||||
public void testIDEADEV_6787() throws IncorrectOperationException {
|
||||
getSettings().ARRAY_INITIALIZER_WRAP = CodeStyleSettings.WRAP_ALWAYS;
|
||||
getSettings().ARRAY_INITIALIZER_LBRACE_ON_NEXT_LINE = true;
|
||||
getSettings().ARRAY_INITIALIZER_RBRACE_ON_NEXT_LINE = true;
|
||||
doTextTest(
|
||||
"public @interface Ann\n" +
|
||||
"{\n" +
|
||||
"int[] x = { 1, 2 };\n" +
|
||||
"\n" +
|
||||
"Mode[] modes () default { @Mode(value = 1), @Mode(value = 2) };\n" +
|
||||
"}",
|
||||
|
||||
"public @interface Ann {\n" +
|
||||
" int[] x = {\n" +
|
||||
" 1,\n" +
|
||||
" 2\n" +
|
||||
" };\n" +
|
||||
"\n" +
|
||||
" Mode[] modes() default {\n" +
|
||||
" @Mode(value = 1),\n" +
|
||||
" @Mode(value = 2)\n" +
|
||||
" };\n" +
|
||||
"}"
|
||||
);
|
||||
}
|
||||
|
||||
/*
|
||||
public void testIDEADEV_14192() throws IncorrectOperationException {
|
||||
getSettings().KEEP_SIMPLE_METHODS_IN_ONE_LINE = true;
|
||||
getSettings().METHOD_BRACE_STYLE = CodeStyleSettings.NEXT_LINE_SHIFTED;
|
||||
getSettings().METHOD_PARAMETERS_WRAP = CodeStyleSettings.WRAP_ALWAYS;
|
||||
doTextTest(
|
||||
"class Foo {\n" +
|
||||
"String foo(int i, boolean j){return something;}\n" +
|
||||
"}",
|
||||
"class Foo {\n" +
|
||||
" String foo(int i, boolean j) {return something;}\n" +
|
||||
"}");
|
||||
}
|
||||
*/
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user