From 358eaa3dcea1dee6350c2cbf80aab3c25db4d4d9 Mon Sep 17 00:00:00 2001 From: Cameron Desrochers Date: Fri, 15 Nov 2019 11:48:06 -0500 Subject: [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 --- clang/unittests/Format/FormatTest.cpp | 90 +++++++++++++++++++++++++++++++++++ 1 file changed, 90 insertions(+) (limited to 'clang/unittests/Format/FormatTest.cpp') 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) { -- cgit v1.2.1