summaryrefslogtreecommitdiffstats
path: root/clang/unittests/Format/FormatTest.cpp
diff options
context:
space:
mode:
authorCameron Desrochers <Cameron.Desrochers@octasic.com>2019-11-15 11:48:06 -0500
committerCameron Desrochers <Cameron.Desrochers@octasic.com>2019-11-15 11:50:22 -0500
commit358eaa3dcea1dee6350c2cbf80aab3c25db4d4d9 (patch)
treef5ad11b9c447f3b23a89f8bd5b0cf3997b49080e /clang/unittests/Format/FormatTest.cpp
parent72768685567b5e2ef9820b80997c5aed615e9f57 (diff)
downloadbcm5719-llvm-358eaa3dcea1dee6350c2cbf80aab3c25db4d4d9.tar.gz
bcm5719-llvm-358eaa3dcea1dee6350c2cbf80aab3c25db4d4d9.zip
[clang-format] Flexible line endings
Line ending detection is now set with the `DeriveLineEnding` option. CRLF can now be used as the default line ending by setting `UseCRLF`. When line ending detection is disabled, all line endings are converted according to the `UseCRLF` option. Differential Revision: https://reviews.llvm.org/D19031
Diffstat (limited to 'clang/unittests/Format/FormatTest.cpp')
-rw-r--r--clang/unittests/Format/FormatTest.cpp90
1 files changed, 90 insertions, 0 deletions
diff --git a/clang/unittests/Format/FormatTest.cpp b/clang/unittests/Format/FormatTest.cpp
index b8a73621c77..122c59782b6 100644
--- a/clang/unittests/Format/FormatTest.cpp
+++ b/clang/unittests/Format/FormatTest.cpp
@@ -12500,6 +12500,7 @@ TEST_F(FormatTest, ParsesConfigurationBools) {
CHECK_PARSE_BOOL(BreakStringLiterals);
CHECK_PARSE_BOOL(CompactNamespaces);
CHECK_PARSE_BOOL(ConstructorInitializerAllOnOneLineOrOnePerLine);
+ CHECK_PARSE_BOOL(DeriveLineEnding);
CHECK_PARSE_BOOL(DerivePointerAlignment);
CHECK_PARSE_BOOL_FIELD(DerivePointerAlignment, "DerivePointerBinding");
CHECK_PARSE_BOOL(DisableFormat);
@@ -12528,6 +12529,7 @@ TEST_F(FormatTest, ParsesConfigurationBools) {
CHECK_PARSE_BOOL(SpaceBeforeCtorInitializerColon);
CHECK_PARSE_BOOL(SpaceBeforeInheritanceColon);
CHECK_PARSE_BOOL(SpaceBeforeRangeBasedForLoopColon);
+ CHECK_PARSE_BOOL(UseCRLF);
CHECK_PARSE_NESTED_BOOL(BraceWrapping, AfterCaseLabel);
CHECK_PARSE_NESTED_BOOL(BraceWrapping, AfterClass);
@@ -14056,6 +14058,94 @@ TEST_F(FormatTest, SupportsCRLF) {
format("/*\r\n"
" \r\r\r\n"
"*/"));
+
+ FormatStyle style = getLLVMStyle();
+
+ style.DeriveLineEnding = true;
+ style.UseCRLF = false;
+ EXPECT_EQ("union FooBarBazQux {\n"
+ " int foo;\n"
+ " int bar;\n"
+ " int baz;\n"
+ "};",
+ format("union FooBarBazQux {\r\n"
+ " int foo;\n"
+ " int bar;\r\n"
+ " int baz;\n"
+ "};",
+ style));
+ style.UseCRLF = true;
+ EXPECT_EQ("union FooBarBazQux {\r\n"
+ " int foo;\r\n"
+ " int bar;\r\n"
+ " int baz;\r\n"
+ "};",
+ format("union FooBarBazQux {\r\n"
+ " int foo;\n"
+ " int bar;\r\n"
+ " int baz;\n"
+ "};",
+ style));
+
+ style.DeriveLineEnding = false;
+ style.UseCRLF = false;
+ EXPECT_EQ("union FooBarBazQux {\n"
+ " int foo;\n"
+ " int bar;\n"
+ " int baz;\n"
+ " int qux;\n"
+ "};",
+ format("union FooBarBazQux {\r\n"
+ " int foo;\n"
+ " int bar;\r\n"
+ " int baz;\n"
+ " int qux;\r\n"
+ "};",
+ style));
+ style.UseCRLF = true;
+ EXPECT_EQ("union FooBarBazQux {\r\n"
+ " int foo;\r\n"
+ " int bar;\r\n"
+ " int baz;\r\n"
+ " int qux;\r\n"
+ "};",
+ format("union FooBarBazQux {\r\n"
+ " int foo;\n"
+ " int bar;\r\n"
+ " int baz;\n"
+ " int qux;\n"
+ "};",
+ style));
+
+ style.DeriveLineEnding = true;
+ style.UseCRLF = false;
+ EXPECT_EQ("union FooBarBazQux {\r\n"
+ " int foo;\r\n"
+ " int bar;\r\n"
+ " int baz;\r\n"
+ " int qux;\r\n"
+ "};",
+ format("union FooBarBazQux {\r\n"
+ " int foo;\n"
+ " int bar;\r\n"
+ " int baz;\n"
+ " int qux;\r\n"
+ "};",
+ style));
+ style.UseCRLF = true;
+ EXPECT_EQ("union FooBarBazQux {\n"
+ " int foo;\n"
+ " int bar;\n"
+ " int baz;\n"
+ " int qux;\n"
+ "};",
+ format("union FooBarBazQux {\r\n"
+ " int foo;\n"
+ " int bar;\r\n"
+ " int baz;\n"
+ " int qux;\n"
+ "};",
+ style));
}
TEST_F(FormatTest, MunchSemicolonAfterBlocks) {
OpenPOWER on IntegriCloud