IDEA-52127 A formatter option to force spaces after unary operators like "!"

Corresponding test is added
This commit is contained in:
Denis Zhdanov
2010-05-18 10:38:56 +04:00
parent 931b44a0c3
commit 519d20d519

View File

@@ -78,4 +78,43 @@ public class JavaFormatterSpaceTest extends AbstractJavaFormatterTest {
"}";
doTextTest(initial, formatted); // Expect the comma to be inserted between type arguments
}
public void testUnaryOperators() {
// Inspired by IDEA-52127
getSettings().SPACE_AFTER_UNARY_OPERATOR = false;
String initial =
"public class FormattingTest {\n" +
" public void foo() {\n" +
" int i = 1;\n" +
" System.out.println(-i);\n" +
" System.out.println(+i);\n" +
" System.out.println(++i);\n" +
" System.out.println(i++);\n" +
" System.out.println(--i);\n" +
" System.out.println(i--);\n" +
" boolean b = true;\n" +
" System.out.println(!b);\n" +
" }\n" +
"}";
doTextTest(initial, initial); // Don't expect spaces to be inserted after unary operators
getSettings().SPACE_AFTER_UNARY_OPERATOR = true;
String formatted =
"public class FormattingTest {\n" +
" public void foo() {\n" +
" int i = 1;\n" +
" System.out.println(- i);\n" +
" System.out.println(+ i);\n" +
" System.out.println(++ i);\n" +
" System.out.println(i++);\n" +
" System.out.println(-- i);\n" +
" System.out.println(i--);\n" +
" boolean b = true;\n" +
" System.out.println(! b);\n" +
" }\n" +
"}";
doTextTest(initial, formatted); // Expect spaces to be inserted after unary operators
}
}