[clang] 9299ace - [clang-format][NFC] Remove extraneous newlines in remaining unit tests
Owen Pan via cfe-commits
cfe-commits at lists.llvm.org
Fri Oct 27 03:42:31 PDT 2023
Author: Owen Pan
Date: 2023-10-27T03:42:16-07:00
New Revision: 9299ace0a20d3ea4d921c033a49364ea6f24263e
URL: https://github.com/llvm/llvm-project/commit/9299ace0a20d3ea4d921c033a49364ea6f24263e
DIFF: https://github.com/llvm/llvm-project/commit/9299ace0a20d3ea4d921c033a49364ea6f24263e.diff
LOG: [clang-format][NFC] Remove extraneous newlines in remaining unit tests
Added:
Modified:
clang/unittests/Format/FormatTestJS.cpp
clang/unittests/Format/NamespaceEndCommentsFixerTest.cpp
clang/unittests/Format/SortImportsTestJava.cpp
clang/unittests/Format/SortIncludesTest.cpp
Removed:
################################################################################
diff --git a/clang/unittests/Format/FormatTestJS.cpp b/clang/unittests/Format/FormatTestJS.cpp
index 23b010dbc982684..e185eceb3530579 100644
--- a/clang/unittests/Format/FormatTestJS.cpp
+++ b/clang/unittests/Format/FormatTestJS.cpp
@@ -328,7 +328,7 @@ TEST_F(FormatTestJS, ReservedWords) {
" switch: string;\n"
" case: string;\n"
" default: string;\n"
- "}\n");
+ "}");
verifyFormat("const Axis = {\n"
" for: 'for',\n"
" x: 'x'\n"
@@ -354,7 +354,7 @@ TEST_F(FormatTestJS, ReservedWordsMethods) {
" let() {\n"
" x();\n"
" }\n"
- "}\n");
+ "}");
verifyFormat("class KeywordNamedMethods {\n"
" do() {\n"
" }\n"
@@ -370,7 +370,7 @@ TEST_F(FormatTestJS, ReservedWordsMethods) {
" }\n"
" catch() {\n"
" }\n"
- "}\n");
+ "}");
}
TEST_F(FormatTestJS, ReservedWordsParenthesized) {
@@ -380,7 +380,7 @@ TEST_F(FormatTestJS, ReservedWordsParenthesized) {
"typeof (x) === 'string';\n"
"void (0);\n"
"delete (x.y);\n"
- "return (x);\n");
+ "return (x);");
}
TEST_F(FormatTestJS, ES6DestructuringAssignment) {
@@ -618,33 +618,33 @@ TEST_F(FormatTestJS, GoogModules) {
" goog.module.get('my.long.module.name.followedBy.MyLongClassName');");
verifyFormat("function a() {\n"
" goog.setTestOnly();\n"
- "}\n",
+ "}",
"function a() {\n"
"goog.setTestOnly();\n"
- "}\n");
+ "}");
}
TEST_F(FormatTestJS, FormatsNamespaces) {
verifyFormat("namespace Foo {\n"
" export let x = 1;\n"
- "}\n");
+ "}");
verifyFormat("declare namespace Foo {\n"
" export let x: number;\n"
- "}\n");
+ "}");
}
TEST_F(FormatTestJS, NamespacesMayNotWrap) {
verifyFormat("declare namespace foobarbaz {\n"
- "}\n",
+ "}",
getGoogleJSStyleWithColumns(18));
verifyFormat("declare module foobarbaz {\n"
- "}\n",
+ "}",
getGoogleJSStyleWithColumns(15));
verifyFormat("namespace foobarbaz {\n"
- "}\n",
+ "}",
getGoogleJSStyleWithColumns(10));
verifyFormat("module foobarbaz {\n"
- "}\n",
+ "}",
getGoogleJSStyleWithColumns(7));
}
@@ -657,15 +657,15 @@ TEST_F(FormatTestJS, AmbientDeclarations) {
"x();", // TODO(martinprobst): should ideally be indented.
NineCols);
verifyFormat("declare function foo();\n"
- "let x = 1;\n");
+ "let x = 1;");
verifyFormat("declare function foo(): string;\n"
- "let x = 1;\n");
+ "let x = 1;");
verifyFormat("declare function foo(): {x: number};\n"
- "let x = 1;\n");
+ "let x = 1;");
verifyFormat("declare class X {}\n"
- "let x = 1;\n");
+ "let x = 1;");
verifyFormat("declare interface Y {}\n"
- "let x = 1;\n");
+ "let x = 1;");
verifyFormat("declare enum X {\n"
"}",
NineCols);
@@ -691,12 +691,12 @@ TEST_F(FormatTestJS, FormatsFreestandingFunctions) {
verifyFormat("function aFunction() {}\n"
"(function f() {\n"
" var x = 1;\n"
- "}());\n");
+ "}());");
verifyFormat("function aFunction() {}\n"
"{\n"
" let x = 1;\n"
" console.log(x);\n"
- "}\n");
+ "}");
EXPECT_EQ("a = function(x) {}\n"
"\n"
"function f(x) {}",
@@ -781,7 +781,7 @@ TEST_F(FormatTestJS, GeneratorFunctions) {
getGoogleJSStyleWithColumns(8));
verifyFormat("export function* f() {\n"
" yield 1;\n"
- "}\n");
+ "}");
verifyFormat("class X {\n"
" * generatorMethod() {\n"
" yield x;\n"
@@ -791,7 +791,7 @@ TEST_F(FormatTestJS, GeneratorFunctions) {
" a: function*() {\n"
" //\n"
" }\n"
- "}\n");
+ "}");
}
TEST_F(FormatTestJS, AsyncFunctions) {
@@ -805,14 +805,14 @@ TEST_F(FormatTestJS, AsyncFunctions) {
"\n"
"function a() {\n"
" return 1;\n"
- "}\n",
+ "}",
" async function f() {\n"
" return 1;\n"
"}\n"
"\n"
" function a() {\n"
" return 1;\n"
- "} \n");
+ "} ");
// clang-format must not insert breaks between async and function, otherwise
// automatic semicolon insertion may trigger (in particular in a class body).
verifyFormat("async function\n"
@@ -848,15 +848,15 @@ TEST_F(FormatTestJS, AsyncFunctions) {
verifyFormat("function initialize() {\n"
" // Comment.\n"
" return async.then();\n"
- "}\n");
+ "}");
verifyFormat("for await (const x of y) {\n"
" console.log(x);\n"
- "}\n");
+ "}");
verifyFormat("function asyncLoop() {\n"
" for await (const x of y) {\n"
" console.log(x);\n"
" }\n"
- "}\n");
+ "}");
}
TEST_F(FormatTestJS, OverriddenMembers) {
@@ -865,18 +865,18 @@ TEST_F(FormatTestJS, OverriddenMembers) {
" protected override "
"anOverlyLongPropertyNameSoLongItHasToGoInASeparateLineWhenOverriden:\n"
" undefined;\n"
- "}\n");
+ "}");
verifyFormat(
"class C extends P {\n"
" protected override "
"anOverlyLongMethodNameSoLongItHasToGoInASeparateLineWhenOverriden() {\n"
" }\n"
- "}\n");
+ "}");
verifyFormat("class C extends P {\n"
" protected override aMethodName<ATypeParam extends {},\n"
" BTypeParam "
"extends {}>() {}\n"
- "}\n");
+ "}");
}
TEST_F(FormatTestJS, FunctionParametersTrailingComma) {
@@ -886,21 +886,21 @@ TEST_F(FormatTestJS, FunctionParametersTrailingComma) {
" p3,\n"
") {\n"
" a; //\n"
- "}\n",
+ "}",
"function trailingComma(p1, p2, p3,) {\n"
" a; //\n"
- "}\n");
+ "}");
verifyFormat("trailingComma(\n"
" p1,\n"
" p2,\n"
" p3,\n"
- ");\n",
- "trailingComma(p1, p2, p3,);\n");
+ ");",
+ "trailingComma(p1, p2, p3,);");
verifyFormat("trailingComma(\n"
" p1 // hello\n"
- ");\n",
+ ");",
"trailingComma(p1 // hello\n"
- ");\n");
+ ");");
}
TEST_F(FormatTestJS, ArrayLiterals) {
@@ -1177,7 +1177,7 @@ TEST_F(FormatTestJS, MultipleFunctionLiterals) {
" doFoo();\n"
" doBaz();\n"
" },\n"
- " []);\n");
+ " []);");
verifyFormat("promise.then(\n"
" function success() {\n"
" doFoo();\n"
@@ -1187,7 +1187,7 @@ TEST_F(FormatTestJS, MultipleFunctionLiterals) {
" function error() {\n"
" doFoo();\n"
" doBaz();\n"
- " });\n");
+ " });");
verifyFormat("promise.then(\n"
" [],\n"
" function success() {\n"
@@ -1197,7 +1197,7 @@ TEST_F(FormatTestJS, MultipleFunctionLiterals) {
" function error() {\n"
" doFoo();\n"
" doBaz();\n"
- " });\n");
+ " });");
verifyFormat("getSomeLongPromise()\n"
" .then(function(value) { body(); })\n"
@@ -1232,7 +1232,7 @@ TEST_F(FormatTestJS, ArrowFunctions) {
verifyFormat("var x = (a) => {\n"
" x;\n"
" return a;\n"
- "};\n");
+ "};");
verifyFormat("var x = (a) => {\n"
" function y() {\n"
" return 42;\n"
@@ -1269,7 +1269,7 @@ TEST_F(FormatTestJS, ArrowFunctions) {
verifyFormat("const f = (x: string|null): string|null => {\n"
" y;\n"
" return x;\n"
- "}\n");
+ "}");
}
TEST_F(FormatTestJS, ArrowFunctionStyle) {
@@ -1347,9 +1347,9 @@ TEST_F(FormatTestJS, WrapRespectsAutomaticSemicolonInsertion) {
"}",
getGoogleJSStyleWithColumns(20));
verifyFormat("const x = (5 + 9)\n"
- "const y = 3\n",
+ "const y = 3",
"const x = ( 5 + 9)\n"
- "const y = 3\n");
+ "const y = 3");
// Ideally the foo() bit should be indented relative to the async function().
verifyFormat("async function\n"
"foo() {}",
@@ -1477,11 +1477,11 @@ TEST_F(FormatTestJS, ImportExportType) {
verifyFormat("import type {x, y} from 'y';\n"
"import type * as x from 'y';\n"
"import type x from 'y';\n"
- "import {x, type yu, z} from 'y';\n");
+ "import {x, type yu, z} from 'y';");
verifyFormat("export type {x, y} from 'y';\n"
"export {x, type yu, z} from 'y';\n"
"export type {x, y};\n"
- "export {x, type yu, z};\n");
+ "export {x, type yu, z};");
}
TEST_F(FormatTestJS, ClosureStyleCasts) {
@@ -1717,7 +1717,7 @@ TEST_F(FormatTestJS, ClassDeclarations) {
verifyFormat("class C {\n"
" foo() {}\n"
" [bar]() {}\n"
- "}\n");
+ "}");
verifyFormat("class C {\n private x: string = 12;\n}");
verifyFormat("class C {\n private static x: string = 12;\n}");
verifyFormat("class C {\n static x(): string {\n return 'asd';\n }\n}");
@@ -1836,7 +1836,7 @@ TEST_F(FormatTestJS, Decorators) {
"class Y {}");
verifyFormat("class X {\n"
" @property() private isReply = false;\n"
- "}\n");
+ "}");
}
TEST_F(FormatTestJS, TypeAliases) {
@@ -1850,18 +1850,18 @@ TEST_F(FormatTestJS, TypeAliases) {
verifyFormat("export type X = {\n"
" a: string,\n"
" b?: string,\n"
- "};\n");
+ "};");
}
TEST_F(FormatTestJS, TypeInterfaceLineWrapping) {
const FormatStyle &Style = getGoogleJSStyleWithColumns(20);
verifyFormat("type LongTypeIsReallyUnreasonablyLong =\n"
- " string;\n",
- "type LongTypeIsReallyUnreasonablyLong = string;\n", Style);
+ " string;",
+ "type LongTypeIsReallyUnreasonablyLong = string;", Style);
verifyFormat("interface AbstractStrategyFactoryProvider {\n"
" a: number\n"
- "}\n",
- "interface AbstractStrategyFactoryProvider { a: number }\n",
+ "}",
+ "interface AbstractStrategyFactoryProvider { a: number }",
Style);
}
@@ -1869,13 +1869,13 @@ TEST_F(FormatTestJS, RemoveEmptyLinesInArrowFunctions) {
verifyFormat("x = () => {\n"
" foo();\n"
" bar();\n"
- "};\n",
+ "};",
"x = () => {\n"
"\n"
" foo();\n"
" bar();\n"
"\n"
- "};\n");
+ "};");
}
TEST_F(FormatTestJS, Modules) {
@@ -2091,7 +2091,7 @@ TEST_F(FormatTestJS, TemplateStrings) {
"var x = ` \\` a`;\n"
"var y;");
// Escaped dollar.
- verifyFormat("var x = ` \\${foo}`;\n");
+ verifyFormat("var x = ` \\${foo}`;");
// The token stream can contain two string_literals in sequence, but that
// doesn't mean that they are implicitly concatenated in JavaScript.
@@ -2217,7 +2217,7 @@ TEST_F(FormatTestJS, UserDefinedTypeGuards) {
"function foo(check: Object):\n"
" check is {foo: string, bar: string, baz: string, foobar: string} {\n"
" return 'bar' in check;\n"
- "}\n");
+ "}");
}
TEST_F(FormatTestJS, OptionalTypes) {
@@ -2293,10 +2293,10 @@ TEST_F(FormatTestJS, JSDocAnnotations) {
// make sure clang-format doesn't break before *any* '{'
verifyFormat("/**\n"
" * @lala {lala {lalala\n"
- " */\n",
+ " */",
"/**\n"
" * @lala {lala {lalala\n"
- " */\n",
+ " */",
getGoogleJSStyleWithColumns(20));
// cases where '{' is around the column limit
for (int ColumnLimit = 6; ColumnLimit < 13; ++ColumnLimit) {
@@ -2407,11 +2407,11 @@ TEST_F(FormatTestJS, RequoteStringsSingle) {
verifyFormat("// clang-format off\n"
"let x = \"double\";\n"
"// clang-format on\n"
- "let x = 'single';\n",
+ "let x = 'single';",
"// clang-format off\n"
"let x = \"double\";\n"
"// clang-format on\n"
- "let x = \"single\";\n");
+ "let x = \"single\";");
}
TEST_F(FormatTestJS, RequoteAndIndent) {
@@ -2452,25 +2452,25 @@ TEST_F(FormatTestJS, SupportShebangLines) {
}
TEST_F(FormatTestJS, NonNullAssertionOperator) {
- verifyFormat("let x = foo!.bar();\n");
- verifyFormat("let x = foo ? bar! : baz;\n");
- verifyFormat("let x = !foo;\n");
+ verifyFormat("let x = foo!.bar();");
+ verifyFormat("let x = foo ? bar! : baz;");
+ verifyFormat("let x = !foo;");
verifyFormat("if (!+a) {\n}");
- verifyFormat("let x = foo[0]!;\n");
- verifyFormat("let x = (foo)!;\n");
- verifyFormat("let x = x(foo!);\n");
+ verifyFormat("let x = foo[0]!;");
+ verifyFormat("let x = (foo)!;");
+ verifyFormat("let x = x(foo!);");
verifyFormat("a.aaaaaa(a.a!).then(\n"
- " x => x(x));\n",
+ " x => x(x));",
getGoogleJSStyleWithColumns(20));
- verifyFormat("let x = foo! - 1;\n");
- verifyFormat("let x = {foo: 1}!;\n");
+ verifyFormat("let x = foo! - 1;");
+ verifyFormat("let x = {foo: 1}!;");
verifyFormat("let x = hello.foo()!\n"
" .foo()!\n"
" .foo()!\n"
- " .foo()!;\n",
+ " .foo()!;",
getGoogleJSStyleWithColumns(20));
- verifyFormat("let x = namespace!;\n");
- verifyFormat("return !!x;\n");
+ verifyFormat("let x = namespace!;");
+ verifyFormat("return !!x;");
}
TEST_F(FormatTestJS, CppKeywords) {
@@ -2534,27 +2534,26 @@ TEST_F(FormatTestJS, CppKeywords) {
}
TEST_F(FormatTestJS, NullPropagatingOperator) {
- verifyFormat("let x = foo?.bar?.baz();\n");
- verifyFormat("let x = foo?.(foo);\n");
- verifyFormat("let x = foo?.['arr'];\n");
+ verifyFormat("let x = foo?.bar?.baz();");
+ verifyFormat("let x = foo?.(foo);");
+ verifyFormat("let x = foo?.['arr'];");
}
TEST_F(FormatTestJS, NullishCoalescingOperator) {
- verifyFormat("const val = something ?? 'some other default';\n");
- verifyFormat(
- "const val = something ?? otherDefault ??\n"
- " evenMore ?? evenMore;\n",
- "const val = something ?? otherDefault ?? evenMore ?? evenMore;\n",
- getGoogleJSStyleWithColumns(40));
+ verifyFormat("const val = something ?? 'some other default';");
+ verifyFormat("const val = something ?? otherDefault ??\n"
+ " evenMore ?? evenMore;",
+ "const val = something ?? otherDefault ?? evenMore ?? evenMore;",
+ getGoogleJSStyleWithColumns(40));
}
TEST_F(FormatTestJS, AssignmentOperators) {
- verifyFormat("a &&= b;\n");
- verifyFormat("a ||= b;\n");
+ verifyFormat("a &&= b;");
+ verifyFormat("a ||= b;");
// NB: need to split ? ?= to avoid it being interpreted by C++ as a trigraph
// for #.
verifyFormat("a ?"
- "?= b;\n");
+ "?= b;");
}
TEST_F(FormatTestJS, Conditional) {
@@ -2626,24 +2625,24 @@ TEST_F(FormatTestJS, NestedLiterals) {
TEST_F(FormatTestJS, BackslashesInComments) {
verifyFormat("// hello \\\n"
- "if (x) foo();\n",
+ "if (x) foo();",
"// hello \\\n"
" if ( x) \n"
- " foo();\n");
+ " foo();");
verifyFormat("/* ignore \\\n"
" */\n"
- "if (x) foo();\n",
+ "if (x) foo();",
"/* ignore \\\n"
" */\n"
- " if ( x) foo();\n");
+ " if ( x) foo();");
verifyFormat("// st \\ art\\\n"
"// comment"
"// continue \\\n"
- "formatMe();\n",
+ "formatMe();",
"// st \\ art\\\n"
"// comment"
"// continue \\\n"
- "formatMe( );\n");
+ "formatMe( );");
}
TEST_F(FormatTestJS, AddsLastLinePenaltyIfEndingIsBroken) {
@@ -2698,14 +2697,14 @@ TEST_F(FormatTestJS, SupportPrivateFieldsAndMethods) {
" #privateMethod() {\n"
" this.#privateMethod(); // infinite loop\n"
" }\n"
- " static #staticPrivateMethod() {}\n");
+ " static #staticPrivateMethod() {}");
}
TEST_F(FormatTestJS, DeclaredFields) {
verifyFormat("class Example {\n"
" declare pub: string;\n"
" declare private priv: string;\n"
- "}\n");
+ "}");
}
TEST_F(FormatTestJS, NoBreakAfterAsserts) {
@@ -2715,12 +2714,12 @@ TEST_F(FormatTestJS, NoBreakAfterAsserts) {
"State>(\n"
" callback: Callback<ExportedState, DependencyState>):\n"
" asserts this is ExtendedState<DependencyState&ExportedState>;\n"
- "}\n",
+ "}",
"interface Assertable<State extends {}> {\n"
" assert<ExportedState extends {}, DependencyState extends State = "
"State>(callback: Callback<ExportedState, DependencyState>): asserts "
"this is ExtendedState<DependencyState&ExportedState>;\n"
- "}\n");
+ "}");
}
TEST_F(FormatTestJS, NumericSeparators) {
diff --git a/clang/unittests/Format/NamespaceEndCommentsFixerTest.cpp b/clang/unittests/Format/NamespaceEndCommentsFixerTest.cpp
index 1ebcba551e4c9d2..fe097e9961e2e6c 100644
--- a/clang/unittests/Format/NamespaceEndCommentsFixerTest.cpp
+++ b/clang/unittests/Format/NamespaceEndCommentsFixerTest.cpp
@@ -67,11 +67,11 @@ TEST_F(NamespaceEndCommentsFixerTest, AddsEndComment) {
EXPECT_EQ("namespace {\n"
"int i;\n"
"int j;\n"
- "} // namespace\n",
+ "} // namespace",
fixNamespaceEndComments("namespace {\n"
"int i;\n"
"int j;\n"
- "}\n"));
+ "}"));
EXPECT_EQ("namespace A {\n"
"int i;\n"
"int j;\n"
@@ -980,7 +980,7 @@ TEST_F(NamespaceEndCommentsFixerTest,
"#endif\n"
"int i;\n"
"}\n"
- "}\n",
+ "}",
fixNamespaceEndComments("#ifdef 1\n"
"namespace A {\n"
"#elseif\n"
@@ -988,7 +988,7 @@ TEST_F(NamespaceEndCommentsFixerTest,
"#endif\n"
"int i;\n"
"}\n"
- "}\n"));
+ "}"));
}
TEST_F(NamespaceEndCommentsFixerTest, AddsEndCommentForNamespacesAroundMacros) {
@@ -1063,12 +1063,12 @@ TEST_F(NamespaceEndCommentsFixerTest, AddsEndCommentForNamespacesAroundMacros) {
"int i;\n"
"int j;\n"
"} // namespace A\n"
- "#define FOO\n",
+ "#define FOO",
fixNamespaceEndComments("namespace A {\n"
"int i;\n"
"int j;\n"
"}\n"
- "#define FOO\n"));
+ "#define FOO"));
// No replacement if open & close in
diff erent conditional blocks
EXPECT_EQ("#if 1\n"
@@ -1128,7 +1128,7 @@ TEST_F(NamespaceEndCommentsFixerTest,
"#endif\n"
"int i;\n"
"}\n"
- "}\n",
+ "}",
fixNamespaceEndComments("#ifdef 1\n"
"namespace A {\n"
"#elseif\n"
@@ -1136,7 +1136,7 @@ TEST_F(NamespaceEndCommentsFixerTest,
"#endif\n"
"int i;\n"
"}\n"
- "}\n"));
+ "}"));
EXPECT_EQ("namespace {\n"
"int i;\n"
"int j;\n"
@@ -1255,41 +1255,41 @@ TEST_F(NamespaceEndCommentsFixerTest, HandlesInlineAtEndOfLine_PR32438) {
"}\n"
"#define c inline\n"
"void d() {\n"
- "}\n",
+ "}",
fixNamespaceEndComments("template <int> struct a {};\n"
"struct a<bool{}> b() {\n"
"}\n"
"#define c inline\n"
"void d() {\n"
- "}\n"));
+ "}"));
}
TEST_F(NamespaceEndCommentsFixerTest, IgnoreUnbalanced) {
EXPECT_EQ("namespace A {\n"
"class Foo {\n"
"}\n"
- "} // namespace A\n",
+ "} // namespace A",
fixNamespaceEndComments("namespace A {\n"
"class Foo {\n"
"}\n"
- "}\n"));
+ "}"));
EXPECT_EQ("namespace A {\n"
"class Foo {\n"
- "}\n",
+ "}",
fixNamespaceEndComments("namespace A {\n"
"class Foo {\n"
- "}\n"));
+ "}"));
EXPECT_EQ("namespace A {\n"
"class Foo {\n"
"}\n"
"}\n"
- "}\n",
+ "}",
fixNamespaceEndComments("namespace A {\n"
"class Foo {\n"
"}\n"
"}\n"
- "}\n"));
+ "}"));
}
using ShortNamespaceLinesTest = NamespaceEndCommentsFixerTest;
@@ -1298,19 +1298,19 @@ TEST_F(ShortNamespaceLinesTest, ZeroUnwrappedLines) {
auto Style = getLLVMStyle();
Style.ShortNamespaceLines = 0u;
- EXPECT_EQ("namespace OneLinerNamespace {}\n",
- fixNamespaceEndComments("namespace OneLinerNamespace {}\n", Style));
+ EXPECT_EQ("namespace OneLinerNamespace {}",
+ fixNamespaceEndComments("namespace OneLinerNamespace {}", Style));
EXPECT_EQ("namespace ShortNamespace {\n"
- "}\n",
+ "}",
fixNamespaceEndComments("namespace ShortNamespace {\n"
- "}\n",
+ "}",
Style));
EXPECT_EQ("namespace LongNamespace {\n"
"int i;\n"
- "} // namespace LongNamespace\n",
+ "} // namespace LongNamespace",
fixNamespaceEndComments("namespace LongNamespace {\n"
"int i;\n"
- "}\n",
+ "}",
Style));
}
@@ -1321,18 +1321,18 @@ TEST_F(ShortNamespaceLinesTest, OneUnwrappedLine) {
EXPECT_EQ(DefaultUnwrappedLines, Style.ShortNamespaceLines);
EXPECT_EQ("namespace ShortNamespace {\n"
"int i;\n"
- "}\n",
+ "}",
fixNamespaceEndComments("namespace ShortNamespace {\n"
"int i;\n"
- "}\n"));
+ "}"));
EXPECT_EQ("namespace LongNamespace {\n"
"int i;\n"
"int j;\n"
- "} // namespace LongNamespace\n",
+ "} // namespace LongNamespace",
fixNamespaceEndComments("namespace LongNamespace {\n"
"int i;\n"
"int j;\n"
- "}\n"));
+ "}"));
}
TEST_F(ShortNamespaceLinesTest, MultipleUnwrappedLine) {
@@ -1342,22 +1342,22 @@ TEST_F(ShortNamespaceLinesTest, MultipleUnwrappedLine) {
EXPECT_EQ("namespace ShortNamespace {\n"
"int i;\n"
"int j;\n"
- "}\n",
+ "}",
fixNamespaceEndComments("namespace ShortNamespace {\n"
"int i;\n"
"int j;\n"
- "}\n",
+ "}",
Style));
EXPECT_EQ("namespace LongNamespace {\n"
"int i;\n"
"int j;\n"
"int k;\n"
- "} // namespace LongNamespace\n",
+ "} // namespace LongNamespace",
fixNamespaceEndComments("namespace LongNamespace {\n"
"int i;\n"
"int j;\n"
"int k;\n"
- "}\n",
+ "}",
Style));
// The namespace body has 5 unwrapped/annotated lines.
@@ -1384,36 +1384,36 @@ TEST_F(ShortNamespaceLinesTest, NamespaceAlias) {
"{\n"
" int i;\n"
" int j;\n"
- "}\n",
+ "}",
fixNamespaceEndComments("namespace n = nn;\n"
"{\n"
" int i;\n"
" int j;\n"
- "}\n",
+ "}",
Style));
EXPECT_EQ("namespace n = nn; // comment\n"
"{\n"
" int i;\n"
" int j;\n"
- "}\n",
+ "}",
fixNamespaceEndComments("namespace n = nn; // comment\n"
"{\n"
" int i;\n"
" int j;\n"
- "}\n",
+ "}",
Style));
EXPECT_EQ("namespace n = nn; /* comment */\n"
"{\n"
" int i;\n"
" int j;\n"
- "}\n",
+ "}",
fixNamespaceEndComments("namespace n = nn; /* comment */\n"
"{\n"
" int i;\n"
" int j;\n"
- "}\n",
+ "}",
Style));
EXPECT_EQ(
@@ -1421,35 +1421,35 @@ TEST_F(ShortNamespaceLinesTest, NamespaceAlias) {
"{\n"
" int i;\n"
" int j;\n"
- "}\n",
+ "}",
fixNamespaceEndComments("namespace n = nn; /* comment */ /* comment2 */\n"
"{\n"
" int i;\n"
" int j;\n"
- "}\n",
+ "}",
Style));
EXPECT_EQ("namespace n = nn; {\n"
" int i;\n"
" int j;\n"
- "}\n",
+ "}",
fixNamespaceEndComments("namespace n = nn; {\n"
" int i;\n"
" int j;\n"
- "}\n",
+ "}",
Style));
EXPECT_EQ("int foo;\n"
"namespace n\n"
"{\n"
" int i;\n"
" int j;\n"
- "} // namespace n\n",
+ "} // namespace n",
fixNamespaceEndComments("int foo;\n"
"namespace n\n"
"{\n"
" int i;\n"
" int j;\n"
- "}\n",
+ "}",
Style));
}
} // end namespace
diff --git a/clang/unittests/Format/SortImportsTestJava.cpp b/clang/unittests/Format/SortImportsTestJava.cpp
index 5a1d0de8b4221ed..98a6826b1ff5823 100644
--- a/clang/unittests/Format/SortImportsTestJava.cpp
+++ b/clang/unittests/Format/SortImportsTestJava.cpp
@@ -39,18 +39,18 @@ class SortImportsTestJava : public ::testing::Test {
TEST_F(SortImportsTestJava, StaticSplitFromNormal) {
EXPECT_EQ("import static org.b;\n"
"\n"
- "import org.a;\n",
+ "import org.a;",
sort("import org.a;\n"
- "import static org.b;\n"));
+ "import static org.b;"));
}
TEST_F(SortImportsTestJava, CapitalBeforeLowercase) {
EXPECT_EQ("import org.Test;\n"
"import org.a.Test;\n"
- "import org.b;\n",
+ "import org.b;",
sort("import org.a.Test;\n"
"import org.Test;\n"
- "import org.b;\n"));
+ "import org.b;"));
}
TEST_F(SortImportsTestJava, KeepSplitGroupsWithOneNewImport) {
@@ -65,7 +65,7 @@ TEST_F(SortImportsTestJava, KeepSplitGroupsWithOneNewImport) {
"\n"
"import org.b;\n"
"\n"
- "import com.b;\n",
+ "import com.b;",
sort("import static com.test.a;\n"
"\n"
"import static org.a;\n"
@@ -77,7 +77,7 @@ TEST_F(SortImportsTestJava, KeepSplitGroupsWithOneNewImport) {
"import org.b;\n"
"\n"
"import com.b;\n"
- "import com.test.c;\n"));
+ "import com.test.c;"));
}
TEST_F(SortImportsTestJava, SplitGroupsWithNewline) {
@@ -91,13 +91,13 @@ TEST_F(SortImportsTestJava, SplitGroupsWithNewline) {
"\n"
"import org.b;\n"
"\n"
- "import com.b;\n",
+ "import com.b;",
sort("import static com.test.a;\n"
"import static org.a;\n"
"import static com.a;\n"
"import com.test.b;\n"
"import org.b;\n"
- "import com.b;\n"));
+ "import com.b;"));
}
TEST_F(SortImportsTestJava, UnspecifiedGroupAfterAllGroups) {
@@ -108,12 +108,12 @@ TEST_F(SortImportsTestJava, UnspecifiedGroupAfterAllGroups) {
"import com.a;\n"
"\n"
"import abc.a;\n"
- "import xyz.b;\n",
+ "import xyz.b;",
sort("import com.test.a;\n"
"import com.a;\n"
"import xyz.b;\n"
"import abc.a;\n"
- "import org.a;\n"));
+ "import org.a;"));
}
TEST_F(SortImportsTestJava, NoSortOutsideRange) {
@@ -122,12 +122,12 @@ TEST_F(SortImportsTestJava, NoSortOutsideRange) {
"import org.a;\n"
"// comments\n"
"// that do\n"
- "// nothing\n",
+ "// nothing",
sort("import org.b;\n"
"import org.a;\n"
"// comments\n"
"// that do\n"
- "// nothing\n",
+ "// nothing",
Ranges));
}
@@ -139,13 +139,13 @@ TEST_F(SortImportsTestJava, SortWhenRangeContainsOneLine) {
"import com.a;\n"
"// comments\n"
"// that do\n"
- "// nothing\n",
+ "// nothing",
sort("import org.b;\n"
"import org.a;\n"
"import com.a;\n"
"// comments\n"
"// that do\n"
- "// nothing\n",
+ "// nothing",
Ranges));
}
@@ -153,20 +153,20 @@ TEST_F(SortImportsTestJava, SortLexicographically) {
EXPECT_EQ("import org.a.*;\n"
"import org.a.a;\n"
"import org.aA;\n"
- "import org.aa;\n",
+ "import org.aa;",
sort("import org.aa;\n"
"import org.a.a;\n"
"import org.a.*;\n"
- "import org.aA;\n"));
+ "import org.aA;"));
}
TEST_F(SortImportsTestJava, StaticInCommentHasNoEffect) {
EXPECT_EQ("import org.a; // static\n"
"import org.b;\n"
- "import org.c; // static\n",
+ "import org.c; // static",
sort("import org.a; // static\n"
"import org.c; // static\n"
- "import org.b;\n"));
+ "import org.b;"));
}
TEST_F(SortImportsTestJava, CommentsWithAffectedImports) {
@@ -176,63 +176,63 @@ TEST_F(SortImportsTestJava, CommentsWithAffectedImports) {
" commentB*/\n"
"import org.b;\n"
"// commentC\n"
- "import org.c;\n",
+ "import org.c;",
sort("import org.a;\n"
"// commentC\n"
"import org.c;\n"
"// commentB\n"
"/* commentB\n"
" commentB*/\n"
- "import org.b;\n"));
+ "import org.b;"));
}
TEST_F(SortImportsTestJava, CommentWithUnaffectedImports) {
EXPECT_EQ("import org.a;\n"
"// comment\n"
- "import org.b;\n",
+ "import org.b;",
sort("import org.a;\n"
"// comment\n"
- "import org.b;\n"));
+ "import org.b;"));
}
TEST_F(SortImportsTestJava, CommentAfterAffectedImports) {
EXPECT_EQ("import org.a;\n"
"import org.b;\n"
- "// comment\n",
+ "// comment",
sort("import org.b;\n"
"import org.a;\n"
- "// comment\n"));
+ "// comment"));
}
TEST_F(SortImportsTestJava, CommentBeforeAffectedImports) {
EXPECT_EQ("// comment\n"
"import org.a;\n"
- "import org.b;\n",
+ "import org.b;",
sort("// comment\n"
"import org.b;\n"
- "import org.a;\n"));
+ "import org.a;"));
}
TEST_F(SortImportsTestJava, FormatTotallyOff) {
EXPECT_EQ("// clang-format off\n"
"import org.b;\n"
"import org.a;\n"
- "// clang-format on\n",
+ "// clang-format on",
sort("// clang-format off\n"
"import org.b;\n"
"import org.a;\n"
- "// clang-format on\n"));
+ "// clang-format on"));
}
TEST_F(SortImportsTestJava, FormatTotallyOn) {
EXPECT_EQ("// clang-format off\n"
"// clang-format on\n"
"import org.a;\n"
- "import org.b;\n",
+ "import org.b;",
sort("// clang-format off\n"
"// clang-format on\n"
"import org.b;\n"
- "import org.a;\n"));
+ "import org.a;"));
}
TEST_F(SortImportsTestJava, FormatPariallyOnShouldNotReorder) {
@@ -241,13 +241,13 @@ TEST_F(SortImportsTestJava, FormatPariallyOnShouldNotReorder) {
"import org.a;\n"
"// clang-format on\n"
"import org.d;\n"
- "import org.c;\n",
+ "import org.c;",
sort("// clang-format off\n"
"import org.b;\n"
"import org.a;\n"
"// clang-format on\n"
"import org.d;\n"
- "import org.c;\n"));
+ "import org.c;"));
}
TEST_F(SortImportsTestJava, SortJavaStaticImport) {
@@ -262,13 +262,13 @@ TEST_F(SortImportsTestJava, SortJavaStaticImport) {
"\n"
"import org.b;\n"
"\n"
- "import com.b;\n",
+ "import com.b;",
sort("import static com.test.a;\n"
"import static org.a;\n"
"import static com.a;\n"
"import com.test.b;\n"
"import org.b;\n"
- "import com.b;\n"));
+ "import com.b;"));
FmtStyle.SortJavaStaticImport = FormatStyle::SJSIO_After;
EXPECT_EQ("import com.test.b;\n"
@@ -282,14 +282,14 @@ TEST_F(SortImportsTestJava, SortJavaStaticImport) {
"\n"
"import static org.a;\n"
"\n"
- "import static com.a;\n",
+ "import static com.a;",
sort("import static com.test.a;\n"
"import static org.a;\n"
"import static com.a;\n"
"import com.test.b;\n"
"import org.b;\n"
"import com.b;\n"
- "import com.test.c;\n"));
+ "import com.test.c;"));
}
TEST_F(SortImportsTestJava, SortJavaStaticImportAsGroup) {
@@ -299,16 +299,16 @@ TEST_F(SortImportsTestJava, SortJavaStaticImportAsGroup) {
"import com.test.b;\n"
"\n"
"import static org.a;\n"
- "import static org.b;\n",
+ "import static org.b;",
sort("import com.test.a;\n"
"import static org.a;\n"
"import com.test.b;\n"
- "import static org.b;\n"));
+ "import static org.b;"));
}
TEST_F(SortImportsTestJava, DeduplicateImports) {
- EXPECT_EQ("import org.a;\n", sort("import org.a;\n"
- "import org.a;\n"));
+ EXPECT_EQ("import org.a;", sort("import org.a;\n"
+ "import org.a;"));
}
TEST_F(SortImportsTestJava, NoNewlineAtEnd) {
@@ -324,13 +324,13 @@ TEST_F(SortImportsTestJava, ImportNamedFunction) {
" void m() {\n"
" importFile();\n"
" }\n"
- "}\n",
+ "}",
sort("import X;\n"
"class C {\n"
" void m() {\n"
" importFile();\n"
" }\n"
- "}\n"));
+ "}"));
}
TEST_F(SortImportsTestJava, NoReplacementsForValidImports) {
diff --git a/clang/unittests/Format/SortIncludesTest.cpp b/clang/unittests/Format/SortIncludesTest.cpp
index 966a7da293d340b..ec142e03b12854e 100644
--- a/clang/unittests/Format/SortIncludesTest.cpp
+++ b/clang/unittests/Format/SortIncludesTest.cpp
@@ -55,17 +55,17 @@ class SortIncludesTest : public ::testing::Test {
TEST_F(SortIncludesTest, BasicSorting) {
EXPECT_EQ("#include \"a.h\"\n"
"#include \"b.h\"\n"
- "#include \"c.h\"\n",
+ "#include \"c.h\"",
sort("#include \"a.h\"\n"
"#include \"c.h\"\n"
- "#include \"b.h\"\n"));
+ "#include \"b.h\""));
EXPECT_EQ("// comment\n"
"#include <a>\n"
- "#include <b>\n",
+ "#include <b>",
sort("// comment\n"
"#include <b>\n"
- "#include <a>\n",
+ "#include <a>",
{tooling::Range(25, 1)}));
}
@@ -75,13 +75,13 @@ TEST_F(SortIncludesTest, TrailingComments) {
" * long\n"
" * comment*/\n"
"#include \"c.h\"\n"
- "#include \"d.h\"\n",
+ "#include \"d.h\"",
sort("#include \"a.h\"\n"
"#include \"c.h\"\n"
"#include \"b.h\" /* long\n"
" * long\n"
" * comment*/\n"
- "#include \"d.h\"\n"));
+ "#include \"d.h\""));
}
TEST_F(SortIncludesTest, SortedIncludesUsingSortPriorityAttribute) {
@@ -121,7 +121,7 @@ TEST_F(SortIncludesTest, SortedIncludesUsingSortPriorityAttribute) {
"\n"
"#include <paths.h>\n"
"\n"
- "#include \"pathnames.h\"\n",
+ "#include \"pathnames.h\"",
sort("#include <sys/param.h>\n"
"#include <sys/types.h>\n"
"#include <sys/ioctl.h>\n"
@@ -139,7 +139,7 @@ TEST_F(SortIncludesTest, SortedIncludesUsingSortPriorityAttribute) {
"#include <errno.h>\n"
"#include <inttypes.h>\n"
"#include <stdio.h>\n"
- "#include <stdlib.h>\n"));
+ "#include <stdlib.h>"));
}
TEST_F(SortIncludesTest, SortPriorityNotDefined) {
FmtStyle = getLLVMStyle();
@@ -147,12 +147,12 @@ TEST_F(SortIncludesTest, SortPriorityNotDefined) {
"#include \"clang/Format/Format.h\"\n"
"#include \"llvm/ADT/None.h\"\n"
"#include \"llvm/Support/Debug.h\"\n"
- "#include \"gtest/gtest.h\"\n",
+ "#include \"gtest/gtest.h\"",
sort("#include \"clang/Format/Format.h\"\n"
"#include \"llvm/ADT/None.h\"\n"
"#include \"FormatTestUtils.h\"\n"
"#include \"gtest/gtest.h\"\n"
- "#include \"llvm/Support/Debug.h\"\n"));
+ "#include \"llvm/Support/Debug.h\""));
}
TEST_F(SortIncludesTest, NoReplacementsForValidIncludes) {
@@ -177,9 +177,9 @@ TEST_F(SortIncludesTest, MainFileHeader) {
EXPECT_EQ("#include \"foo.bar.h\"\n"
"\n"
- "#include \"a.h\"\n",
+ "#include \"a.h\"",
sort("#include \"a.h\"\n"
- "#include \"foo.bar.h\"\n",
+ "#include \"foo.bar.h\"",
"foo.bar.cc"));
}
@@ -187,22 +187,22 @@ TEST_F(SortIncludesTest, SortedIncludesInMultipleBlocksAreMerged) {
Style.IncludeBlocks = tooling::IncludeStyle::IBS_Merge;
EXPECT_EQ("#include \"a.h\"\n"
"#include \"b.h\"\n"
- "#include \"c.h\"\n",
+ "#include \"c.h\"",
sort("#include \"a.h\"\n"
"#include \"c.h\"\n"
"\n"
"\n"
- "#include \"b.h\"\n"));
+ "#include \"b.h\""));
Style.IncludeBlocks = tooling::IncludeStyle::IBS_Regroup;
EXPECT_EQ("#include \"a.h\"\n"
"#include \"b.h\"\n"
- "#include \"c.h\"\n",
+ "#include \"c.h\"",
sort("#include \"a.h\"\n"
"#include \"c.h\"\n"
"\n"
"\n"
- "#include \"b.h\"\n"));
+ "#include \"b.h\""));
}
TEST_F(SortIncludesTest, SupportClangFormatOff) {
@@ -213,7 +213,7 @@ TEST_F(SortIncludesTest, SupportClangFormatOff) {
"#include <b>\n"
"#include <a>\n"
"#include <c>\n"
- "// clang-format on\n",
+ "// clang-format on",
sort("#include <b>\n"
"#include <a>\n"
"#include <c>\n"
@@ -221,7 +221,7 @@ TEST_F(SortIncludesTest, SupportClangFormatOff) {
"#include <b>\n"
"#include <a>\n"
"#include <c>\n"
- "// clang-format on\n"));
+ "// clang-format on"));
Style.IncludeBlocks = Style.IBS_Merge;
std::string Code = "// clang-format off\r\n"
@@ -253,7 +253,7 @@ TEST_F(SortIncludesTest, SupportClangFormatOffCStyle) {
"#include <b>\n"
"#include <a>\n"
"#include <c>\n"
- "/* clang-format on */\n",
+ "/* clang-format on */",
sort("#include <b>\n"
"#include <a>\n"
"#include <c>\n"
@@ -261,7 +261,7 @@ TEST_F(SortIncludesTest, SupportClangFormatOffCStyle) {
"#include <b>\n"
"#include <a>\n"
"#include <c>\n"
- "/* clang-format on */\n"));
+ "/* clang-format on */"));
// Not really turning it off
EXPECT_EQ("#include <a>\n"
@@ -271,7 +271,7 @@ TEST_F(SortIncludesTest, SupportClangFormatOffCStyle) {
"#include <a>\n"
"#include <b>\n"
"#include <c>\n"
- "/* clang-format onwards */\n",
+ "/* clang-format onwards */",
sort("#include <b>\n"
"#include <a>\n"
"#include <c>\n"
@@ -279,7 +279,7 @@ TEST_F(SortIncludesTest, SupportClangFormatOffCStyle) {
"#include <b>\n"
"#include <a>\n"
"#include <c>\n"
- "/* clang-format onwards */\n",
+ "/* clang-format onwards */",
"input.h", 2));
}
@@ -287,77 +287,77 @@ TEST_F(SortIncludesTest, IncludeSortingCanBeDisabled) {
FmtStyle.SortIncludes = FormatStyle::SI_Never;
EXPECT_EQ("#include \"a.h\"\n"
"#include \"c.h\"\n"
- "#include \"b.h\"\n",
+ "#include \"b.h\"",
sort("#include \"a.h\"\n"
"#include \"c.h\"\n"
- "#include \"b.h\"\n",
+ "#include \"b.h\"",
"input.h", 0));
}
TEST_F(SortIncludesTest, MixIncludeAndImport) {
EXPECT_EQ("#include \"a.h\"\n"
"#import \"b.h\"\n"
- "#include \"c.h\"\n",
+ "#include \"c.h\"",
sort("#include \"a.h\"\n"
"#include \"c.h\"\n"
- "#import \"b.h\"\n"));
+ "#import \"b.h\""));
}
TEST_F(SortIncludesTest, FixTrailingComments) {
EXPECT_EQ("#include \"a.h\" // comment\n"
"#include \"bb.h\" // comment\n"
- "#include \"ccc.h\"\n",
+ "#include \"ccc.h\"",
sort("#include \"a.h\" // comment\n"
"#include \"ccc.h\"\n"
- "#include \"bb.h\" // comment\n"));
+ "#include \"bb.h\" // comment"));
}
TEST_F(SortIncludesTest, LeadingWhitespace) {
EXPECT_EQ("#include \"a.h\"\n"
"#include \"b.h\"\n"
- "#include \"c.h\"\n",
+ "#include \"c.h\"",
sort(" #include \"a.h\"\n"
" #include \"c.h\"\n"
- " #include \"b.h\"\n"));
+ " #include \"b.h\""));
EXPECT_EQ("#include \"a.h\"\n"
"#include \"b.h\"\n"
- "#include \"c.h\"\n",
+ "#include \"c.h\"",
sort("# include \"a.h\"\n"
"# include \"c.h\"\n"
- "# include \"b.h\"\n"));
- EXPECT_EQ("#include \"a.h\"\n", sort("#include \"a.h\"\n"
- " #include \"a.h\"\n"));
+ "# include \"b.h\""));
+ EXPECT_EQ("#include \"a.h\"", sort("#include \"a.h\"\n"
+ " #include \"a.h\""));
}
TEST_F(SortIncludesTest, TrailingWhitespace) {
EXPECT_EQ("#include \"a.h\"\n"
"#include \"b.h\"\n"
- "#include \"c.h\"\n",
+ "#include \"c.h\"",
sort("#include \"a.h\" \n"
"#include \"c.h\" \n"
- "#include \"b.h\" \n"));
- EXPECT_EQ("#include \"a.h\"\n", sort("#include \"a.h\"\n"
- "#include \"a.h\" \n"));
+ "#include \"b.h\" "));
+ EXPECT_EQ("#include \"a.h\"", sort("#include \"a.h\"\n"
+ "#include \"a.h\" "));
}
TEST_F(SortIncludesTest, GreaterInComment) {
EXPECT_EQ("#include \"a.h\"\n"
"#include \"b.h\" // >\n"
- "#include \"c.h\"\n",
+ "#include \"c.h\"",
sort("#include \"a.h\"\n"
"#include \"c.h\"\n"
- "#include \"b.h\" // >\n"));
+ "#include \"b.h\" // >"));
}
TEST_F(SortIncludesTest, SortsLocallyInEachBlock) {
EXPECT_EQ("#include \"a.h\"\n"
"#include \"c.h\"\n"
"\n"
- "#include \"b.h\"\n",
+ "#include \"b.h\"",
sort("#include \"a.h\"\n"
"#include \"c.h\"\n"
"\n"
- "#include \"b.h\"\n",
+ "#include \"b.h\"",
"input.h", 0));
}
@@ -365,42 +365,42 @@ TEST_F(SortIncludesTest, SortsAllBlocksWhenMerging) {
Style.IncludeBlocks = tooling::IncludeStyle::IBS_Merge;
EXPECT_EQ("#include \"a.h\"\n"
"#include \"b.h\"\n"
- "#include \"c.h\"\n",
+ "#include \"c.h\"",
sort("#include \"a.h\"\n"
"#include \"c.h\"\n"
"\n"
- "#include \"b.h\"\n"));
+ "#include \"b.h\""));
}
TEST_F(SortIncludesTest, CommentsAlwaysSeparateGroups) {
EXPECT_EQ("#include \"a.h\"\n"
"#include \"c.h\"\n"
"// comment\n"
- "#include \"b.h\"\n",
+ "#include \"b.h\"",
sort("#include \"c.h\"\n"
"#include \"a.h\"\n"
"// comment\n"
- "#include \"b.h\"\n"));
+ "#include \"b.h\""));
Style.IncludeBlocks = tooling::IncludeStyle::IBS_Merge;
EXPECT_EQ("#include \"a.h\"\n"
"#include \"c.h\"\n"
"// comment\n"
- "#include \"b.h\"\n",
+ "#include \"b.h\"",
sort("#include \"c.h\"\n"
"#include \"a.h\"\n"
"// comment\n"
- "#include \"b.h\"\n"));
+ "#include \"b.h\""));
Style.IncludeBlocks = tooling::IncludeStyle::IBS_Regroup;
EXPECT_EQ("#include \"a.h\"\n"
"#include \"c.h\"\n"
"// comment\n"
- "#include \"b.h\"\n",
+ "#include \"b.h\"",
sort("#include \"c.h\"\n"
"#include \"a.h\"\n"
"// comment\n"
- "#include \"b.h\"\n"));
+ "#include \"b.h\""));
}
TEST_F(SortIncludesTest, HandlesAngledIncludesAsSeparateBlocks) {
@@ -409,13 +409,13 @@ TEST_F(SortIncludesTest, HandlesAngledIncludesAsSeparateBlocks) {
"#include <array>\n"
"#include <b.h>\n"
"#include <d.h>\n"
- "#include <vector>\n",
+ "#include <vector>",
sort("#include <vector>\n"
"#include <d.h>\n"
"#include <array>\n"
"#include <b.h>\n"
"#include \"c.h\"\n"
- "#include \"a.h\"\n"));
+ "#include \"a.h\""));
FmtStyle = getGoogleStyle(FormatStyle::LK_Cpp);
EXPECT_EQ("#include <b.h>\n"
@@ -425,13 +425,13 @@ TEST_F(SortIncludesTest, HandlesAngledIncludesAsSeparateBlocks) {
"#include <vector>\n"
"\n"
"#include \"a.h\"\n"
- "#include \"c.h\"\n",
+ "#include \"c.h\"",
sort("#include <vector>\n"
"#include <d.h>\n"
"#include <array>\n"
"#include <b.h>\n"
"#include \"c.h\"\n"
- "#include \"a.h\"\n"));
+ "#include \"a.h\""));
}
TEST_F(SortIncludesTest, RegroupsAngledIncludesInSeparateBlocks) {
@@ -440,21 +440,21 @@ TEST_F(SortIncludesTest, RegroupsAngledIncludesInSeparateBlocks) {
"#include \"c.h\"\n"
"\n"
"#include <b.h>\n"
- "#include <d.h>\n",
+ "#include <d.h>",
sort("#include <d.h>\n"
"#include <b.h>\n"
"#include \"c.h\"\n"
- "#include \"a.h\"\n"));
+ "#include \"a.h\""));
}
TEST_F(SortIncludesTest, HandlesMultilineIncludes) {
EXPECT_EQ("#include \"a.h\"\n"
"#include \"b.h\"\n"
- "#include \"c.h\"\n",
+ "#include \"c.h\"",
sort("#include \"a.h\"\n"
"#include \\\n"
"\"c.h\"\n"
- "#include \"b.h\"\n"));
+ "#include \"b.h\""));
}
TEST_F(SortIncludesTest, HandlesTrailingCommentsWithAngleBrackets) {
@@ -462,11 +462,11 @@ TEST_F(SortIncludesTest, HandlesTrailingCommentsWithAngleBrackets) {
EXPECT_EQ("#include <cstdint>\n"
"\n"
"#include \"util/bar.h\"\n"
- "#include \"util/foo/foo.h\" // foo<T>\n",
+ "#include \"util/foo/foo.h\" // foo<T>",
sort("#include <cstdint>\n"
"\n"
"#include \"util/bar.h\"\n"
- "#include \"util/foo/foo.h\" // foo<T>\n",
+ "#include \"util/foo/foo.h\" // foo<T>",
/*FileName=*/"input.cc",
/*ExpectedNumRanges=*/0));
}
@@ -475,51 +475,51 @@ TEST_F(SortIncludesTest, LeavesMainHeaderFirst) {
Style.IncludeIsMainRegex = "([-_](test|unittest))?$";
EXPECT_EQ("#include \"llvm/a.h\"\n"
"#include \"b.h\"\n"
- "#include \"c.h\"\n",
+ "#include \"c.h\"",
sort("#include \"llvm/a.h\"\n"
"#include \"c.h\"\n"
- "#include \"b.h\"\n",
+ "#include \"b.h\"",
"a.cc"));
EXPECT_EQ("#include \"llvm/a.h\"\n"
"#include \"b.h\"\n"
- "#include \"c.h\"\n",
+ "#include \"c.h\"",
sort("#include \"llvm/a.h\"\n"
"#include \"c.h\"\n"
- "#include \"b.h\"\n",
+ "#include \"b.h\"",
"a_test.cc"));
EXPECT_EQ("#include \"llvm/input.h\"\n"
"#include \"b.h\"\n"
- "#include \"c.h\"\n",
+ "#include \"c.h\"",
sort("#include \"llvm/input.h\"\n"
"#include \"c.h\"\n"
- "#include \"b.h\"\n",
+ "#include \"b.h\"",
"input.mm"));
// Don't allow prefixes.
EXPECT_EQ("#include \"b.h\"\n"
"#include \"c.h\"\n"
- "#include \"llvm/not_a.h\"\n",
+ "#include \"llvm/not_a.h\"",
sort("#include \"llvm/not_a.h\"\n"
"#include \"c.h\"\n"
- "#include \"b.h\"\n",
+ "#include \"b.h\"",
"a.cc"));
// Don't do this for _main and other suffixes.
EXPECT_EQ("#include \"b.h\"\n"
"#include \"c.h\"\n"
- "#include \"llvm/a.h\"\n",
+ "#include \"llvm/a.h\"",
sort("#include \"llvm/a.h\"\n"
"#include \"c.h\"\n"
- "#include \"b.h\"\n",
+ "#include \"b.h\"",
"a_main.cc"));
// Don't do this in headers.
EXPECT_EQ("#include \"b.h\"\n"
"#include \"c.h\"\n"
- "#include \"llvm/a.h\"\n",
+ "#include \"llvm/a.h\"",
sort("#include \"llvm/a.h\"\n"
"#include \"c.h\"\n"
- "#include \"b.h\"\n",
+ "#include \"b.h\"",
"a.h"));
// Only do this in the first #include block.
@@ -527,23 +527,23 @@ TEST_F(SortIncludesTest, LeavesMainHeaderFirst) {
"\n"
"#include \"b.h\"\n"
"#include \"c.h\"\n"
- "#include \"llvm/a.h\"\n",
+ "#include \"llvm/a.h\"",
sort("#include <a>\n"
"\n"
"#include \"llvm/a.h\"\n"
"#include \"c.h\"\n"
- "#include \"b.h\"\n",
+ "#include \"b.h\"",
"a.cc"));
// Only recognize the first #include with a matching basename as main include.
EXPECT_EQ("#include \"a.h\"\n"
"#include \"b.h\"\n"
"#include \"c.h\"\n"
- "#include \"llvm/a.h\"\n",
+ "#include \"llvm/a.h\"",
sort("#include \"b.h\"\n"
"#include \"a.h\"\n"
"#include \"c.h\"\n"
- "#include \"llvm/a.h\"\n",
+ "#include \"llvm/a.h\"",
"a.cc"));
}
@@ -551,50 +551,50 @@ TEST_F(SortIncludesTest, LeavesMainHeaderFirstInAdditionalExtensions) {
Style.IncludeIsMainRegex = "([-_](test|unittest))?|(Impl)?$";
EXPECT_EQ("#include \"b.h\"\n"
"#include \"c.h\"\n"
- "#include \"llvm/a.h\"\n",
+ "#include \"llvm/a.h\"",
sort("#include \"llvm/a.h\"\n"
"#include \"c.h\"\n"
- "#include \"b.h\"\n",
+ "#include \"b.h\"",
"a_test.xxx"));
EXPECT_EQ("#include \"b.h\"\n"
"#include \"c.h\"\n"
- "#include \"llvm/a.h\"\n",
+ "#include \"llvm/a.h\"",
sort("#include \"llvm/a.h\"\n"
"#include \"c.h\"\n"
- "#include \"b.h\"\n",
+ "#include \"b.h\"",
"aImpl.hpp"));
// .cpp extension is considered "main" by default
EXPECT_EQ("#include \"llvm/a.h\"\n"
"#include \"b.h\"\n"
- "#include \"c.h\"\n",
+ "#include \"c.h\"",
sort("#include \"llvm/a.h\"\n"
"#include \"c.h\"\n"
- "#include \"b.h\"\n",
+ "#include \"b.h\"",
"aImpl.cpp"));
EXPECT_EQ("#include \"llvm/a.h\"\n"
"#include \"b.h\"\n"
- "#include \"c.h\"\n",
+ "#include \"c.h\"",
sort("#include \"llvm/a.h\"\n"
"#include \"c.h\"\n"
- "#include \"b.h\"\n",
+ "#include \"b.h\"",
"a_test.cpp"));
// Allow additional filenames / extensions
Style.IncludeIsMainSourceRegex = "(Impl\\.hpp)|(\\.xxx)$";
EXPECT_EQ("#include \"llvm/a.h\"\n"
"#include \"b.h\"\n"
- "#include \"c.h\"\n",
+ "#include \"c.h\"",
sort("#include \"llvm/a.h\"\n"
"#include \"c.h\"\n"
- "#include \"b.h\"\n",
+ "#include \"b.h\"",
"a_test.xxx"));
EXPECT_EQ("#include \"llvm/a.h\"\n"
"#include \"b.h\"\n"
- "#include \"c.h\"\n",
+ "#include \"c.h\"",
sort("#include \"llvm/a.h\"\n"
"#include \"c.h\"\n"
- "#include \"b.h\"\n",
+ "#include \"b.h\"",
"aImpl.hpp"));
}
@@ -604,11 +604,11 @@ TEST_F(SortIncludesTest, RecognizeMainHeaderInAllGroups) {
EXPECT_EQ("#include \"c.h\"\n"
"#include \"a.h\"\n"
- "#include \"b.h\"\n",
+ "#include \"b.h\"",
sort("#include \"b.h\"\n"
"\n"
"#include \"a.h\"\n"
- "#include \"c.h\"\n",
+ "#include \"c.h\"",
"c.cc"));
}
@@ -619,11 +619,11 @@ TEST_F(SortIncludesTest, MainHeaderIsSeparatedWhenRegroupping) {
EXPECT_EQ("#include \"a.h\"\n"
"\n"
"#include \"b.h\"\n"
- "#include \"c.h\"\n",
+ "#include \"c.h\"",
sort("#include \"b.h\"\n"
"\n"
"#include \"a.h\"\n"
- "#include \"c.h\"\n",
+ "#include \"c.h\"",
"a.cc"));
}
@@ -636,12 +636,12 @@ TEST_F(SortIncludesTest, SupportOptionalCaseSensitiveSorting) {
"#include \"A/b.h\"\n"
"#include \"a/b.h\"\n"
"#include \"B/A.h\"\n"
- "#include \"B/a.h\"\n",
+ "#include \"B/a.h\"",
sort("#include \"B/a.h\"\n"
"#include \"B/A.h\"\n"
"#include \"A/B.h\"\n"
"#include \"a/b.h\"\n"
- "#include \"A/b.h\"\n",
+ "#include \"A/b.h\"",
"a.h"));
Style.IncludeBlocks = clang::tooling::IncludeStyle::IBS_Regroup;
@@ -655,7 +655,7 @@ TEST_F(SortIncludesTest, SupportOptionalCaseSensitiveSorting) {
"#include <Algorithm>\n"
"#include \"vlib.h\"\n"
"#include \"Vlib.h\"\n"
- "#include \"AST.h\"\n";
+ "#include \"AST.h\"";
EXPECT_EQ("#include \"AST.h\"\n"
"#include \"qt.h\"\n"
@@ -666,7 +666,7 @@ TEST_F(SortIncludesTest, SupportOptionalCaseSensitiveSorting) {
"#include <qtwhatever.h>\n"
"\n"
"#include <Algorithm>\n"
- "#include <algorithm>\n",
+ "#include <algorithm>",
sort(UnsortedCode));
}
@@ -682,14 +682,14 @@ TEST_F(SortIncludesTest, SupportCaseInsensitiveMatching) {
"#include \"LLVM/z.h\"\n"
"#include \"llvm/X.h\"\n"
"#include \"GTest/GTest.h\"\n"
- "#include \"gmock/gmock.h\"\n",
+ "#include \"gmock/gmock.h\"",
sort("#include \"c.h\"\n"
"#include \"b.h\"\n"
"#include \"GTest/GTest.h\"\n"
"#include \"llvm/A.h\"\n"
"#include \"gmock/gmock.h\"\n"
"#include \"llvm/X.h\"\n"
- "#include \"LLVM/z.h\"\n",
+ "#include \"LLVM/z.h\"",
"a_TEST.cc"));
}
@@ -709,7 +709,7 @@ TEST_F(SortIncludesTest, SupportOptionalCaseSensitiveMachting) {
"#include \"qa.h\"\n"
"#include <queue>\n"
"#include <qtwhatever.h>\n"
- "#include <QtGlobal>\n";
+ "#include <QtGlobal>";
EXPECT_EQ("#include \"qa.h\"\n"
"#include \"qt.h\"\n"
@@ -722,7 +722,7 @@ TEST_F(SortIncludesTest, SupportOptionalCaseSensitiveMachting) {
"#include <QtGlobal>\n"
"#include <queue>\n"
"\n"
- "#include <algorithm>\n",
+ "#include <algorithm>",
sort(UnsortedCode));
Style.IncludeCategories[2].RegexIsCaseSensitive = true;
@@ -739,7 +739,7 @@ TEST_F(SortIncludesTest, SupportOptionalCaseSensitiveMachting) {
"#include <QtGlobal>\n"
"\n"
"#include <algorithm>\n"
- "#include <queue>\n",
+ "#include <queue>",
sort(UnsortedCode));
}
@@ -748,19 +748,19 @@ TEST_F(SortIncludesTest, NegativePriorities) {
{".*", 1, 0, false}};
EXPECT_EQ("#include \"important_os_header.h\"\n"
"#include \"c_main.h\"\n"
- "#include \"a_other.h\"\n",
+ "#include \"a_other.h\"",
sort("#include \"c_main.h\"\n"
"#include \"a_other.h\"\n"
- "#include \"important_os_header.h\"\n",
+ "#include \"important_os_header.h\"",
"c_main.cc"));
// check stable when re-run
EXPECT_EQ("#include \"important_os_header.h\"\n"
"#include \"c_main.h\"\n"
- "#include \"a_other.h\"\n",
+ "#include \"a_other.h\"",
sort("#include \"important_os_header.h\"\n"
"#include \"c_main.h\"\n"
- "#include \"a_other.h\"\n",
+ "#include \"a_other.h\"",
"c_main.cc", 0));
}
@@ -773,10 +773,10 @@ TEST_F(SortIncludesTest, PriorityGroupsAreSeparatedWhenRegroupping) {
"\n"
"#include \"c_main.h\"\n"
"\n"
- "#include \"a_other.h\"\n",
+ "#include \"a_other.h\"",
sort("#include \"c_main.h\"\n"
"#include \"a_other.h\"\n"
- "#include \"important_os_header.h\"\n",
+ "#include \"important_os_header.h\"",
"c_main.cc"));
// check stable when re-run
@@ -784,12 +784,12 @@ TEST_F(SortIncludesTest, PriorityGroupsAreSeparatedWhenRegroupping) {
"\n"
"#include \"c_main.h\"\n"
"\n"
- "#include \"a_other.h\"\n",
+ "#include \"a_other.h\"",
sort("#include \"important_os_header.h\"\n"
"\n"
"#include \"c_main.h\"\n"
"\n"
- "#include \"a_other.h\"\n",
+ "#include \"a_other.h\"",
"c_main.cc", 0));
}
@@ -824,73 +824,73 @@ TEST_F(SortIncludesTest, CalculatesCorrectCursorPositionWithRegrouping) {
TEST_F(SortIncludesTest, DeduplicateIncludes) {
EXPECT_EQ("#include <a>\n"
"#include <b>\n"
- "#include <c>\n",
+ "#include <c>",
sort("#include <a>\n"
"#include <b>\n"
"#include <b>\n"
"#include <b>\n"
"#include <b>\n"
- "#include <c>\n"));
+ "#include <c>"));
Style.IncludeBlocks = tooling::IncludeStyle::IBS_Merge;
EXPECT_EQ("#include <a>\n"
"#include <b>\n"
- "#include <c>\n",
+ "#include <c>",
sort("#include <a>\n"
"#include <b>\n"
"\n"
"#include <b>\n"
"\n"
"#include <b>\n"
- "#include <c>\n"));
+ "#include <c>"));
Style.IncludeBlocks = tooling::IncludeStyle::IBS_Regroup;
EXPECT_EQ("#include <a>\n"
"#include <b>\n"
- "#include <c>\n",
+ "#include <c>",
sort("#include <a>\n"
"#include <b>\n"
"\n"
"#include <b>\n"
"\n"
"#include <b>\n"
- "#include <c>\n"));
+ "#include <c>"));
}
TEST_F(SortIncludesTest, SortAndDeduplicateIncludes) {
EXPECT_EQ("#include <a>\n"
"#include <b>\n"
- "#include <c>\n",
+ "#include <c>",
sort("#include <b>\n"
"#include <a>\n"
"#include <b>\n"
"#include <b>\n"
"#include <c>\n"
- "#include <b>\n"));
+ "#include <b>"));
Style.IncludeBlocks = tooling::IncludeStyle::IBS_Merge;
EXPECT_EQ("#include <a>\n"
"#include <b>\n"
- "#include <c>\n",
+ "#include <c>",
sort("#include <b>\n"
"#include <a>\n"
"\n"
"#include <b>\n"
"\n"
"#include <c>\n"
- "#include <b>\n"));
+ "#include <b>"));
Style.IncludeBlocks = tooling::IncludeStyle::IBS_Regroup;
EXPECT_EQ("#include <a>\n"
"#include <b>\n"
- "#include <c>\n",
+ "#include <c>",
sort("#include <b>\n"
"#include <a>\n"
"\n"
"#include <b>\n"
"\n"
"#include <c>\n"
- "#include <b>\n"));
+ "#include <b>"));
}
TEST_F(SortIncludesTest, CalculatesCorrectCursorPositionAfterDeduplicate) {
@@ -921,13 +921,13 @@ TEST_F(SortIncludesTest, DeduplicateLocallyInEachBlock) {
"#include <b>\n"
"\n"
"#include <b>\n"
- "#include <c>\n",
+ "#include <c>",
sort("#include <a>\n"
"#include <b>\n"
"\n"
"#include <c>\n"
"#include <b>\n"
- "#include <b>\n"));
+ "#include <b>"));
}
TEST_F(SortIncludesTest, ValidAffactedRangesAfterDeduplicatingIncludes) {
More information about the cfe-commits
mailing list