summaryrefslogtreecommitdiffstats
path: root/clang/unittests/Format
diff options
context:
space:
mode:
Diffstat (limited to 'clang/unittests/Format')
-rw-r--r--clang/unittests/Format/FormatTestProto.cpp30
-rw-r--r--clang/unittests/Format/FormatTestTextProto.cpp50
2 files changed, 76 insertions, 4 deletions
diff --git a/clang/unittests/Format/FormatTestProto.cpp b/clang/unittests/Format/FormatTestProto.cpp
index 40a069b3f3d..4c61ec1398f 100644
--- a/clang/unittests/Format/FormatTestProto.cpp
+++ b/clang/unittests/Format/FormatTestProto.cpp
@@ -438,5 +438,35 @@ TEST_F(FormatTestProto, NoSpaceAfterPercent) {
"};");
}
+TEST_F(FormatTestProto, FormatsRepeatedListInitializersInOptions) {
+ verifyFormat("option (MyProto.options) = {\n"
+ " key: item\n"
+ " keys: [\n"
+ " 'ala',\n"
+ " 'bala',\n"
+ " 'porto',\n"
+ " 'kala',\n"
+ " 'too',\n"
+ " 'long',\n"
+ " 'long',\n"
+ " 'long'\n"
+ " ]\n"
+ " key: [ item ]\n"
+ " msg {\n"
+ " key: item\n"
+ " keys: [\n"
+ " 'ala',\n"
+ " 'bala',\n"
+ " 'porto',\n"
+ " 'kala',\n"
+ " 'too',\n"
+ " 'long',\n"
+ " 'long'\n"
+ " ]\n"
+ " }\n"
+ " key: value\n"
+ "};");
+}
+
} // end namespace tooling
} // end namespace clang
diff --git a/clang/unittests/Format/FormatTestTextProto.cpp b/clang/unittests/Format/FormatTestTextProto.cpp
index 151774b9e2e..97326cfe0ac 100644
--- a/clang/unittests/Format/FormatTestTextProto.cpp
+++ b/clang/unittests/Format/FormatTestTextProto.cpp
@@ -31,14 +31,18 @@ protected:
return *Result;
}
- static std::string format(llvm::StringRef Code) {
- FormatStyle Style = getGoogleStyle(FormatStyle::LK_TextProto);
- Style.ColumnLimit = 60; // To make writing tests easier.
+ static std::string format(llvm::StringRef Code, const FormatStyle &Style) {
return format(Code, 0, Code.size(), Style);
}
+ static void verifyFormat(llvm::StringRef Code, const FormatStyle &Style) {
+ EXPECT_EQ(Code.str(), format(test::messUp(Code), Style));
+ }
+
static void verifyFormat(llvm::StringRef Code) {
- EXPECT_EQ(Code.str(), format(test::messUp(Code)));
+ FormatStyle Style = getGoogleStyle(FormatStyle::LK_TextProto);
+ Style.ColumnLimit = 60; // To make writing tests easier.
+ verifyFormat(Code, Style);
}
};
@@ -390,5 +394,43 @@ TEST_F(FormatTestTextProto, FormatsExtensions) {
TEST_F(FormatTestTextProto, NoSpaceAfterPercent) {
verifyFormat("key: %d");
}
+
+TEST_F(FormatTestTextProto, FormatsRepeatedListInitializers) {
+ verifyFormat("keys: []");
+ verifyFormat("keys: [ 1 ]");
+ verifyFormat("keys: [ 'ala', 'bala' ]");
+ verifyFormat("keys:\n"
+ " [ 'ala', 'bala', 'porto', 'kala', 'too', 'long', 'ng' ]");
+ verifyFormat("key: item\n"
+ "keys: [\n"
+ " 'ala',\n"
+ " 'bala',\n"
+ " 'porto',\n"
+ " 'kala',\n"
+ " 'too',\n"
+ " 'long',\n"
+ " 'long',\n"
+ " 'long'\n"
+ "]\n"
+ "key: item\n"
+ "msg {\n"
+ " key: item\n"
+ " keys: [\n"
+ " 'ala',\n"
+ " 'bala',\n"
+ " 'porto',\n"
+ " 'kala',\n"
+ " 'too',\n"
+ " 'long',\n"
+ " 'long'\n"
+ " ]\n"
+ "}\n"
+ "key: value"
+ );
+ FormatStyle Style = getGoogleStyle(FormatStyle::LK_TextProto);
+ Style.ColumnLimit = 60; // To make writing tests easier.
+ Style.Cpp11BracedListStyle = true;
+ verifyFormat("keys: [1]", Style);
+}
} // end namespace tooling
} // end namespace clang
OpenPOWER on IntegriCloud