summaryrefslogtreecommitdiffstats
path: root/clang/unittests/Format/FormatTestProto.cpp
diff options
context:
space:
mode:
authorKrasimir Georgiev <krasimir@google.com>2018-04-13 13:37:09 +0000
committerKrasimir Georgiev <krasimir@google.com>2018-04-13 13:37:09 +0000
commitf28347ea7d082d629bdb29a6511b8cc66a6716ef (patch)
tree972d63465b8627c706974d66541ad196f95c7de8 /clang/unittests/Format/FormatTestProto.cpp
parent308f8b7a66dcbd629e39ed7fd9010642d433bab8 (diff)
downloadbcm5719-llvm-f28347ea7d082d629bdb29a6511b8cc66a6716ef.tar.gz
bcm5719-llvm-f28347ea7d082d629bdb29a6511b8cc66a6716ef.zip
[clang-format] Improve Incomplete detection for (text) protos
Summary: This patch improves detection of incomplete code for protos and text protos. This is especially important for text protos in raw string literals, since they might be partial strings concatenated, and we'd like to disable formatting in these cases. Reviewers: sammccall Reviewed By: sammccall Subscribers: klimek, cfe-commits Differential Revision: https://reviews.llvm.org/D44203 llvm-svn: 330016
Diffstat (limited to 'clang/unittests/Format/FormatTestProto.cpp')
-rw-r--r--clang/unittests/Format/FormatTestProto.cpp25
1 files changed, 23 insertions, 2 deletions
diff --git a/clang/unittests/Format/FormatTestProto.cpp b/clang/unittests/Format/FormatTestProto.cpp
index 4b1480b074a..8634a36b9d9 100644
--- a/clang/unittests/Format/FormatTestProto.cpp
+++ b/clang/unittests/Format/FormatTestProto.cpp
@@ -18,13 +18,21 @@ namespace clang {
namespace format {
class FormatTestProto : public ::testing::Test {
+ enum StatusCheck { SC_ExpectComplete, SC_ExpectIncomplete };
+
protected:
static std::string format(llvm::StringRef Code, unsigned Offset,
- unsigned Length, const FormatStyle &Style) {
+ unsigned Length, const FormatStyle &Style,
+ StatusCheck CheckComplete = SC_ExpectComplete) {
DEBUG(llvm::errs() << "---\n");
DEBUG(llvm::errs() << Code << "\n\n");
std::vector<tooling::Range> Ranges(1, tooling::Range(Offset, Length));
- tooling::Replacements Replaces = reformat(Style, Code, Ranges);
+ FormattingAttemptStatus Status;
+ tooling::Replacements Replaces =
+ reformat(Style, Code, Ranges, "<stdin>", &Status);
+ bool ExpectedCompleteFormat = CheckComplete == SC_ExpectComplete;
+ EXPECT_EQ(ExpectedCompleteFormat, Status.FormatComplete)
+ << Code << "\n\n";
auto Result = applyAllReplacements(Code, Replaces);
EXPECT_TRUE(static_cast<bool>(Result));
DEBUG(llvm::errs() << "\n" << *Result << "\n\n");
@@ -41,6 +49,12 @@ protected:
EXPECT_EQ(Code.str(), format(Code)) << "Expected code is not stable";
EXPECT_EQ(Code.str(), format(test::messUp(Code)));
}
+
+ static void verifyIncompleteFormat(llvm::StringRef Code) {
+ FormatStyle Style = getGoogleStyle(FormatStyle::LK_Proto);
+ EXPECT_EQ(Code.str(),
+ format(Code, 0, Code.size(), Style, SC_ExpectIncomplete));
+ }
};
TEST_F(FormatTestProto, FormatsMessages) {
@@ -492,5 +506,12 @@ TEST_F(FormatTestProto, AcceptsOperatorAsKeyInOptions) {
"};");
}
+TEST_F(FormatTestProto, IncompleteFormat) {
+ verifyIncompleteFormat("option (");
+ verifyIncompleteFormat("option (MyProto.options) = { bbbbbbbbb:");
+ verifyIncompleteFormat("option (MyProto.options) = { bbbbbbbbb: <\n");
+ verifyIncompleteFormat("option (MyProto.options) = { bbbbbbbbb: [\n");
+}
+
} // end namespace tooling
} // end namespace clang
OpenPOWER on IntegriCloud