Three issues to fix:
- char_constants weren't properly treated as string literals
- Prevening the break after "label: " does not make sense in concunction
with AlwaysBreakBeforeMultilineStrings. It leads to situations where
clang-format just cannot find a viable format (it must break and yet
it must not break).
- AlwaysBreakBeforeMultilineStrings should not be on for LK_TextProto in
Google style.
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@327255
91177308-0d34-0410-b5e6-
96231b3b80d8
GoogleStyle.JavaScriptWrapImports = false;
} else if (Language == FormatStyle::LK_Proto) {
GoogleStyle.AllowShortFunctionsOnASingleLine = FormatStyle::SFS_None;
+ GoogleStyle.AlwaysBreakBeforeMultilineStrings = false;
GoogleStyle.SpacesInContainerLiterals = false;
GoogleStyle.Cpp11BracedListStyle = false;
// This affects protocol buffer options specifications and text protos.
}
}
- if (Style.Language == FormatStyle::LK_JavaScript &&
+ if ((Style.Language == FormatStyle::LK_JavaScript ||
+ Style.Language == FormatStyle::LK_Proto ||
+ Style.Language == FormatStyle::LK_TextProto) &&
Tok.is(tok::char_constant)) {
Tok.Tok.setKind(tok::string_literal);
}
if (Left.is(tok::colon) && Left.isOneOf(TT_DictLiteral, TT_ObjCMethodExpr)) {
if ((Style.Language == FormatStyle::LK_Proto ||
Style.Language == FormatStyle::LK_TextProto) &&
- Right.isStringLiteral())
+ !Style.AlwaysBreakBeforeMultilineStrings && Right.isStringLiteral())
return false;
return true;
}
" key: 'a' //\n"
" }\n"
"];");
- verifyFormat("optional string test = 1 [default =\n"
- " \"test\"\n"
- " \"test\"];");
+ verifyFormat("optional string test = 1 [default = \"test\"\n"
+ " \"test\"];");
verifyFormat("optional Aaaaaaaa aaaaaaaa = 12 [\n"
" (aaa) = aaaa,\n"
" (bbbbbbbbbbbbbbbbbbbbbbbbbb) = {\n"
"}");
}
+TEST_F(FormatTestTextProto, ImplicitStringLiteralConcatenation) {
+ verifyFormat("field_a: 'aaaaa'\n"
+ " 'bbbbb'");
+ verifyFormat("field_a: \"aaaaa\"\n"
+ " \"bbbbb\"");
+ FormatStyle Style = getGoogleStyle(FormatStyle::LK_TextProto);
+ Style.AlwaysBreakBeforeMultilineStrings = true;
+ verifyFormat("field_a:\n"
+ " 'aaaaa'\n"
+ " 'bbbbb'",
+ Style);
+ verifyFormat("field_a:\n"
+ " \"aaaaa\"\n"
+ " \"bbbbb\"",
+ Style);
+}
+
TEST_F(FormatTestTextProto, SupportsAngleBracketMessageFields) {
// Single-line tests
verifyFormat("msg_field <>");