summaryrefslogtreecommitdiffstats
path: root/clang/unittests/Format/FormatTest.cpp
diff options
context:
space:
mode:
authorDaniel Jasper <djasper@google.com>2013-07-31 23:16:02 +0000
committerDaniel Jasper <djasper@google.com>2013-07-31 23:16:02 +0000
commit65ee347285832ef21c6850e4820fcc4d6fa16cb6 (patch)
treeee0f987c3e20f2014b0bcac97b4b5fb204d337b2 /clang/unittests/Format/FormatTest.cpp
parent44a6ed8d4e0a3f9a99b5e506a7e83ce4dda8ff54 (diff)
downloadbcm5719-llvm-65ee347285832ef21c6850e4820fcc4d6fa16cb6.tar.gz
bcm5719-llvm-65ee347285832ef21c6850e4820fcc4d6fa16cb6.zip
clang-format: Add more options to namespace indentation.
With this patch, clang-format can be configured to: * not indent in namespace at all (former behavior). * indent in namespace as in other blocks. * indent only in inner namespaces (as required by WebKit style). Also fix alignment of access specifiers in WebKit style. Patch started by Marek Kurdej. Thank you! llvm-svn: 187540
Diffstat (limited to 'clang/unittests/Format/FormatTest.cpp')
-rw-r--r--clang/unittests/Format/FormatTest.cpp52
1 files changed, 49 insertions, 3 deletions
diff --git a/clang/unittests/Format/FormatTest.cpp b/clang/unittests/Format/FormatTest.cpp
index 4a28cca222e..61d06145950 100644
--- a/clang/unittests/Format/FormatTest.cpp
+++ b/clang/unittests/Format/FormatTest.cpp
@@ -842,10 +842,10 @@ TEST_F(FormatTest, AlignsBlockComments) {
" 1.1.1. to keep the formatting.\n"
" */"));
EXPECT_EQ("/*\n"
- "Don't try to outdent if there's not enough inentation.\n"
+ "Don't try to outdent if there's not enough indentation.\n"
"*/",
format(" /*\n"
- " Don't try to outdent if there's not enough inentation.\n"
+ " Don't try to outdent if there's not enough indentation.\n"
" */"));
EXPECT_EQ("int i; /* Comment with empty...\n"
@@ -1565,6 +1565,37 @@ TEST_F(FormatTest, FormatsNamespaces) {
"int i;\n"
"} // my_namespace\n"
"#endif // HEADER_GUARD"));
+
+ FormatStyle Style = getLLVMStyle();
+ Style.NamespaceIndentation = FormatStyle::NI_All;
+ EXPECT_EQ("namespace out {\n"
+ " int i;\n"
+ " namespace in {\n"
+ " int i;\n"
+ " } // namespace\n"
+ "} // namespace",
+ format("namespace out {\n"
+ "int i;\n"
+ "namespace in {\n"
+ "int i;\n"
+ "} // namespace\n"
+ "} // namespace",
+ Style));
+
+ Style.NamespaceIndentation = FormatStyle::NI_Inner;
+ EXPECT_EQ("namespace out {\n"
+ "int i;\n"
+ "namespace in {\n"
+ " int i;\n"
+ "} // namespace\n"
+ "} // namespace",
+ format("namespace out {\n"
+ "int i;\n"
+ "namespace in {\n"
+ "int i;\n"
+ "} // namespace\n"
+ "} // namespace",
+ Style));
}
TEST_F(FormatTest, FormatsExternC) { verifyFormat("extern \"C\" {\nint a;"); }
@@ -5485,6 +5516,14 @@ TEST_F(FormatTest, ParsesConfiguration) {
CHECK_PARSE("BreakBeforeBraces: Stroustrup", BreakBeforeBraces,
FormatStyle::BS_Stroustrup);
+ Style.NamespaceIndentation = FormatStyle::NI_All;
+ CHECK_PARSE("NamespaceIndentation: None", NamespaceIndentation,
+ FormatStyle::NI_None);
+ CHECK_PARSE("NamespaceIndentation: Inner", NamespaceIndentation,
+ FormatStyle::NI_Inner);
+ CHECK_PARSE("NamespaceIndentation: All", NamespaceIndentation,
+ FormatStyle::NI_All);
+
#undef CHECK_PARSE
#undef CHECK_PARSE_BOOL
}
@@ -5586,7 +5625,7 @@ TEST_F(FormatTest, FormatsWithWebKitStyle) {
verifyFormat("namespace outer {\n"
"int i;\n"
"namespace inner {\n"
- "int i;\n" // FIXME: This should be indented.
+ " int i;\n"
"} // namespace inner\n"
"} // namespace outer\n"
"namespace other_outer {\n"
@@ -5632,6 +5671,13 @@ TEST_F(FormatTest, FormatsWithWebKitStyle) {
" , aaaaaaaaaaaaaaaaaaaaaaa()\n{\n}",
Style);
+ // Access specifiers should be aligned left.
+ verifyFormat("class C {\n"
+ "public:\n"
+ " int i;\n"
+ "};",
+ Style);
+
// Do not align comments.
// FIXME: Implement option to suppress comment alignment.
// verifyFormat("int a; // Do not\n"
OpenPOWER on IntegriCloud