Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions clang/lib/Format/Format.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1892,6 +1892,9 @@ FormatStyle getChromiumStyle(FormatStyle::LanguageKind Language) {
ChromiumStyle.IncludeStyle.IncludeBlocks =
tooling::IncludeStyle::IBS_Preserve;

ChromiumStyle.InsertBraces = true;
ChromiumStyle.InsertNewlineAtEOF = true;

if (Language == FormatStyle::LK_Java) {
ChromiumStyle.AllowShortIfStatementsOnASingleLine =
FormatStyle::SIS_WithoutElse;
Expand Down
14 changes: 7 additions & 7 deletions clang/unittests/Format/FormatTest.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -5407,7 +5407,7 @@ TEST_F(FormatTest, DoesntRemoveUnknownTokens) {
}

TEST_F(FormatTest, IndentsPPDirectiveWithPPIndentWidth) {
FormatStyle style = getChromiumStyle(FormatStyle::LK_Cpp);
FormatStyle style = getChromiumStyle();
style.IndentWidth = 4;
style.PPIndentWidth = 1;

Expand Down Expand Up @@ -5905,7 +5905,7 @@ TEST_F(FormatTest, MacrosWithoutTrailingSemicolon) {

verifyFormat("VISIT_GL_CALL(GenBuffers, void, (GLsizei n, GLuint* buffers), "
"(n, buffers))",
getChromiumStyle(FormatStyle::LK_Cpp));
getChromiumStyle());

// See PR41483
verifyNoChange("/**/ FOO(a)\n"
Expand Down Expand Up @@ -11605,7 +11605,7 @@ TEST_F(FormatTest, UnderstandsTemplateParameters) {
verifyFormat("auto x = [] { A<A<A<A>>> a; };", "auto x=[]{A<A<A<A> >> a;};",
getGoogleStyle());

verifyFormat("A<A<int>> a;", getChromiumStyle(FormatStyle::LK_Cpp));
verifyFormat("A<A<int>> a;", getChromiumStyle());

// template closer followed by a token that starts with > or =
verifyFormat("bool b = a<1> > 1;");
Expand Down Expand Up @@ -12814,7 +12814,7 @@ TEST_F(FormatTest, UnderstandsSquareAttributes) {
}

TEST_F(FormatTest, AttributeClass) {
FormatStyle Style = getChromiumStyle(FormatStyle::LK_Cpp);
FormatStyle Style = getChromiumStyle();
verifyFormat("class S {\n"
" S(S&&) = default;\n"
"};",
Expand Down Expand Up @@ -15732,7 +15732,7 @@ TEST_F(FormatTest, MergeHandlingInTheFaceOfPreprocessorDirectives) {
"#define a \\\n"
" if \\\n"
" 0",
getChromiumStyle(FormatStyle::LK_Cpp));
getChromiumStyle());
}

TEST_F(FormatTest, FormatStarDependingOnContext) {
Expand Down Expand Up @@ -22542,7 +22542,7 @@ TEST_F(FormatTest, UnderstandsPragmas) {
"#pragma comment(linker, \\\n"
" \"argument\" \\\n"
" \"argument\"",
getStyleWithColumns(getChromiumStyle(FormatStyle::LK_Cpp), 32));
getStyleWithColumns(getChromiumStyle(), 32));
}

TEST_F(FormatTest, UnderstandsPragmaOmpTarget) {
Expand Down Expand Up @@ -26157,7 +26157,7 @@ TEST_F(FormatTest, GoogleDefaultStyle) {
Style);
}
TEST_F(FormatTest, ChromiumDefaultStyle) {
FormatStyle Style = getChromiumStyle(FormatStyle::LK_Cpp);
FormatStyle Style = getChromiumStyle();
verifyFormat("extern \"C\" {\n"
"int foo();\n"
"}",
Expand Down
2 changes: 1 addition & 1 deletion clang/unittests/Format/FormatTestJS.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -562,7 +562,7 @@ TEST_F(FormatTestJS, SpacesInContainerLiterals) {
" b: 'bbbbbbbbbbbbbbbbbb'\n"
"};");

verifyFormat("f({a: 1, b: 2, c: 3});",
verifyFormat("f({a: 1, b: 2, c: 3});\n",
getChromiumStyle(FormatStyle::LK_JavaScript));
verifyFormat("f({'a': [{}]});");
}
Expand Down
4 changes: 2 additions & 2 deletions clang/unittests/Format/FormatTestJava.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ TEST_F(FormatTestJava, Chromium) {
" for (;;) f();\n"
" if (true) f();\n"
" }\n"
"}",
"}\n",
getChromiumStyle(FormatStyle::LK_Java));
}

Expand Down Expand Up @@ -280,7 +280,7 @@ TEST_F(FormatTestJava, Annotations) {
verifyFormat("@Partial @Mock DataLoader loader;");
verifyFormat("@Partial\n"
"@Mock\n"
"DataLoader loader;",
"DataLoader loader;\n",
getChromiumStyle(FormatStyle::LK_Java));
verifyFormat("@SuppressWarnings(value = \"aaaaaaaaaaaaaaaaaaaaaaaaaaaaaa\")\n"
"public static int iiiiiiiiiiiiiiiiiiiiiiii;");
Expand Down
2 changes: 1 addition & 1 deletion clang/unittests/Format/FormatTestObjC.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -951,7 +951,7 @@ TEST_F(FormatTestObjC, FormatObjCMethodExpr) {
" styleMask:NSBorderlessWindowMask\n"
" backing:NSBackingStoreBuffered\n"
" defer:NO]);\n"
"}");
"}\n");

// Respect continuation indent and colon alignment (e.g. when object name is
// short, and first selector is the longest one)
Expand Down
6 changes: 6 additions & 0 deletions clang/unittests/Format/FormatTestUtils.h
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,12 @@ inline FormatStyle getGoogleStyle() {
return getGoogleStyle(FormatStyle::LK_Cpp);
}

inline FormatStyle getChromiumStyle() {
auto Style = getChromiumStyle(FormatStyle::LK_Cpp);
Style.InsertNewlineAtEOF = false;
return Style;
}

// When HandleHash is false, preprocessor directives starting with hash will not
// be on separate lines. This is needed because Verilog uses hash for other
// purposes.
Expand Down
Loading