summaryrefslogtreecommitdiff
path: root/unittests
diff options
context:
space:
mode:
Diffstat (limited to 'unittests')
-rw-r--r--unittests/Format/FormatTest.cpp14
-rw-r--r--unittests/Format/FormatTestComments.cpp109
-rw-r--r--unittests/Format/FormatTestJS.cpp10
-rw-r--r--unittests/Format/FormatTestSelective.cpp8
4 files changed, 136 insertions, 5 deletions
diff --git a/unittests/Format/FormatTest.cpp b/unittests/Format/FormatTest.cpp
index 076041406c87a..0935c1bed204c 100644
--- a/unittests/Format/FormatTest.cpp
+++ b/unittests/Format/FormatTest.cpp
@@ -3457,6 +3457,18 @@ TEST_F(FormatTest, BreaksAfterAssignments) {
" 1;");
}
+TEST_F(FormatTest, ConfigurableBreakAssignmentPenalty) {
+ FormatStyle Style = getLLVMStyle();
+ verifyFormat("int aaaaaaaaaaaaaaaaaaaaaaaaaa =\n"
+ " bbbbbbbbbbbbbbbbbbbbbbbbbb + cccccccccccccccccccccccccc;",
+ Style);
+
+ Style.PenaltyBreakAssignment = 20;
+ verifyFormat("int aaaaaaaaaaaaaaaaaaaaaaaaaa = bbbbbbbbbbbbbbbbbbbbbbbbbb +\n"
+ " cccccccccccccccccccccccccc;",
+ Style);
+}
+
TEST_F(FormatTest, AlignsAfterAssignments) {
verifyFormat(
"int Result = aaaaaaaaaaaaaaaaaaaaaaaaa + aaaaaaaaaaaaaaaaaaaaaaaaa +\n"
@@ -8802,6 +8814,8 @@ TEST_F(FormatTest, ParsesConfiguration) {
CHECK_PARSE("ObjCBlockIndentWidth: 1234", ObjCBlockIndentWidth, 1234u);
CHECK_PARSE("ColumnLimit: 1234", ColumnLimit, 1234u);
CHECK_PARSE("MaxEmptyLinesToKeep: 1234", MaxEmptyLinesToKeep, 1234u);
+ CHECK_PARSE("PenaltyBreakAssignment: 1234",
+ PenaltyBreakAssignment, 1234u);
CHECK_PARSE("PenaltyBreakBeforeFirstCallParameter: 1234",
PenaltyBreakBeforeFirstCallParameter, 1234u);
CHECK_PARSE("PenaltyExcessCharacter: 1234", PenaltyExcessCharacter, 1234u);
diff --git a/unittests/Format/FormatTestComments.cpp b/unittests/Format/FormatTestComments.cpp
index 4238efe54f064..a44a6845587da 100644
--- a/unittests/Format/FormatTestComments.cpp
+++ b/unittests/Format/FormatTestComments.cpp
@@ -1020,6 +1020,38 @@ TEST_F(FormatTestComments, SplitsLongLinesInCommentsInPreprocessor) {
getLLVMStyleWithColumns(20)));
}
+TEST_F(FormatTestComments, KeepsTrailingPPCommentsAndSectionCommentsSeparate) {
+ verifyFormat("#ifdef A // line about A\n"
+ "// section comment\n"
+ "#endif",
+ getLLVMStyleWithColumns(80));
+ verifyFormat("#ifdef A // line 1 about A\n"
+ " // line 2 about A\n"
+ "// section comment\n"
+ "#endif",
+ getLLVMStyleWithColumns(80));
+ EXPECT_EQ("#ifdef A // line 1 about A\n"
+ " // line 2 about A\n"
+ "// section comment\n"
+ "#endif",
+ format("#ifdef A // line 1 about A\n"
+ " // line 2 about A\n"
+ "// section comment\n"
+ "#endif",
+ getLLVMStyleWithColumns(80)));
+ verifyFormat("int f() {\n"
+ " int i;\n"
+ "#ifdef A // comment about A\n"
+ " // section comment 1\n"
+ " // section comment 2\n"
+ " i = 2;\n"
+ "#else // comment about #else\n"
+ " // section comment 3\n"
+ " i = 4;\n"
+ "#endif\n"
+ "}", getLLVMStyleWithColumns(80));
+}
+
TEST_F(FormatTestComments, CommentsInStaticInitializers) {
EXPECT_EQ(
"static SomeType type = {aaaaaaaaaaaaaaaaaaaa, /* comment */\n"
@@ -1198,6 +1230,16 @@ TEST_F(FormatTestComments, ReflowsComments) {
format("/* long long long long\n"
" * long */",
getLLVMStyleWithColumns(20)));
+ EXPECT_EQ("///< long long long\n"
+ "///< long long\n",
+ format("///< long long long long\n"
+ "///< long\n",
+ getLLVMStyleWithColumns(20)));
+ EXPECT_EQ("//!< long long long\n"
+ "//!< long long\n",
+ format("//!< long long long long\n"
+ "//!< long\n",
+ getLLVMStyleWithColumns(20)));
// Don't bring leading whitespace up while reflowing.
EXPECT_EQ("/* long long long\n"
@@ -1535,7 +1577,7 @@ TEST_F(FormatTestComments, ReflowsComments) {
" *\n"
" * long */",
getLLVMStyleWithColumns(20)));
-
+
// Don't reflow lines having content that is a single character.
EXPECT_EQ("// long long long\n"
"// long\n"
@@ -1560,7 +1602,7 @@ TEST_F(FormatTestComments, ReflowsComments) {
format("// long long long long\n"
"// @param arg",
getLLVMStyleWithColumns(20)));
-
+
// Don't reflow lines starting with 'TODO'.
EXPECT_EQ("// long long long\n"
"// long\n"
@@ -1629,6 +1671,69 @@ TEST_F(FormatTestComments, ReflowsComments) {
"// long",
getLLVMStyleWithColumns(20)));
+ // Don't reflow separate bullets in list
+ EXPECT_EQ("// - long long long\n"
+ "// long\n"
+ "// - long",
+ format("// - long long long long\n"
+ "// - long",
+ getLLVMStyleWithColumns(20)));
+ EXPECT_EQ("// * long long long\n"
+ "// long\n"
+ "// * long",
+ format("// * long long long long\n"
+ "// * long",
+ getLLVMStyleWithColumns(20)));
+ EXPECT_EQ("// + long long long\n"
+ "// long\n"
+ "// + long",
+ format("// + long long long long\n"
+ "// + long",
+ getLLVMStyleWithColumns(20)));
+ EXPECT_EQ("// 1. long long long\n"
+ "// long\n"
+ "// 2. long",
+ format("// 1. long long long long\n"
+ "// 2. long",
+ getLLVMStyleWithColumns(20)));
+ EXPECT_EQ("// -# long long long\n"
+ "// long\n"
+ "// -# long",
+ format("// -# long long long long\n"
+ "// -# long",
+ getLLVMStyleWithColumns(20)));
+
+ EXPECT_EQ("// - long long long\n"
+ "// long long long\n"
+ "// - long",
+ format("// - long long long long\n"
+ "// long long\n"
+ "// - long",
+ getLLVMStyleWithColumns(20)));
+ EXPECT_EQ("// - long long long\n"
+ "// long long long\n"
+ "// long\n"
+ "// - long",
+ format("// - long long long long\n"
+ "// long long long\n"
+ "// - long",
+ getLLVMStyleWithColumns(20)));
+
+ // Large number (>2 digits) are not list items
+ EXPECT_EQ("// long long long\n"
+ "// long 1024. long.",
+ format("// long long long long\n"
+ "// 1024. long.",
+ getLLVMStyleWithColumns(20)));
+
+ // Do not break before number, to avoid introducing a non-reflowable doxygen
+ // list item.
+ EXPECT_EQ("// long long\n"
+ "// long 10. long.",
+ format("// long long long 10.\n"
+ "// long.",
+ getLLVMStyleWithColumns(20)));
+
// Don't break or reflow after implicit string literals.
verifyFormat("#include <t> // l l l\n"
" // l",
diff --git a/unittests/Format/FormatTestJS.cpp b/unittests/Format/FormatTestJS.cpp
index ff28f304be994..ba6ff02360851 100644
--- a/unittests/Format/FormatTestJS.cpp
+++ b/unittests/Format/FormatTestJS.cpp
@@ -548,15 +548,14 @@ TEST_F(FormatTestJS, AsyncFunctions) {
" // Comment.\n"
" return async.then();\n"
"}\n");
- verifyFormat("for async (const x of y) {\n"
+ verifyFormat("for await (const x of y) {\n"
" console.log(x);\n"
"}\n");
verifyFormat("function asyncLoop() {\n"
- " for async (const x of y) {\n"
+ " for await (const x of y) {\n"
" console.log(x);\n"
" }\n"
"}\n");
-
}
TEST_F(FormatTestJS, FunctionParametersTrailingComma) {
@@ -1824,6 +1823,11 @@ TEST_F(FormatTestJS, NonNullAssertionOperator) {
verifyFormat("let x = !foo;\n");
verifyFormat("let x = foo[0]!;\n");
verifyFormat("let x = (foo)!;\n");
+ verifyFormat("let x = x(foo!);\n");
+ verifyFormat(
+ "a.aaaaaa(a.a!).then(\n"
+ " x => x(x));\n",
+ getGoogleJSStyleWithColumns(20));
verifyFormat("let x = foo! - 1;\n");
verifyFormat("let x = {foo: 1}!;\n");
verifyFormat(
diff --git a/unittests/Format/FormatTestSelective.cpp b/unittests/Format/FormatTestSelective.cpp
index 9ee87b34c2171..182218fe96dbe 100644
--- a/unittests/Format/FormatTestSelective.cpp
+++ b/unittests/Format/FormatTestSelective.cpp
@@ -530,6 +530,14 @@ TEST_F(FormatTestSelective, SelectivelyRequoteJavaScript) {
20, 0));
}
+TEST_F(FormatTestSelective, KeepsIndentAfterCommentSectionImport) {
+ std::string Code = "#include <a> // line 1\n" // 23 chars long
+ " // line 2\n" // 23 chars long
+ "\n" // this newline is char 47
+ "int i;"; // this line is not indented
+ EXPECT_EQ(Code, format(Code, 47, 1));
+}
+
} // end namespace
} // end namespace format
} // end namespace clang