clang-format: Enable formatting of protocol buffer definitions.
Almost by accident, clang-format seems to be able to format protocol
buffer definitions (https://code.google.com/p/protobuf/).
The only change is that a space is required between numeric constants
and opening square brackets (for default values). While this might in
theory be used for array subscripts (int val = 4[MyArray]), I have not
seen this pattern in practice much. If this is wrong, we can make this
smarter in the future.
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@189663 91177308-0d34-0410-b5e6-96231b3b80d8
diff --git a/unittests/Format/FormatTest.cpp b/unittests/Format/FormatTest.cpp
index aef1dae..c30133a 100644
--- a/unittests/Format/FormatTest.cpp
+++ b/unittests/Format/FormatTest.cpp
@@ -6242,5 +6242,14 @@
format("if (aaaaaaaaaaaaaaa || bbbbbbbbbbbbbbb) { i++; }", Style));
}
+TEST_F(FormatTest, FormatsProtocolBufferDefinitions) {
+ // It seems that clang-format can format protocol buffer definitions
+ // (see https://code.google.com/p/protobuf/).
+ verifyFormat("message SomeMessage {\n"
+ " required int32 field1 = 1;\n"
+ " optional string field2 = 2 [default = \"2\"]\n"
+ "}");
+}
+
} // end namespace tooling
} // end namespace clang