Optionally derive formatting information from the input file.
With this patch, clang-format can analyze the input file for two
properties:
1. Is "int *a" or "int* a" more common.
2. Are non-C++03 constructs used, e.g. A<A<A>>.
With Google-style, clang-format will now use the more common style for
(1) and format C++03 compatible, unless it finds C++11 constructs in the
input.
llvm-svn: 174504
diff --git a/clang/unittests/Format/FormatTest.cpp b/clang/unittests/Format/FormatTest.cpp
index f5250bc..0f46983 100644
--- a/clang/unittests/Format/FormatTest.cpp
+++ b/clang/unittests/Format/FormatTest.cpp
@@ -1437,6 +1437,11 @@
verifyGoogleFormat("A<A<int>> a;");
verifyGoogleFormat("A<A<A<int>>> a;");
verifyGoogleFormat("A<A<A<A<int>>>> a;");
+ verifyGoogleFormat("A<A<int> > a;");
+ verifyGoogleFormat("A<A<A<int> > > a;");
+ verifyGoogleFormat("A<A<A<A<int> > > > a;");
+ EXPECT_EQ("A<A<A<A>>> a;", format("A<A<A<A> >> a;", getGoogleStyle()));
+ EXPECT_EQ("A<A<A<A>>> a;", format("A<A<A<A>> > a;", getGoogleStyle()));
verifyFormat("test >> a >> b;");
verifyFormat("test << a >> b;");
@@ -1597,6 +1602,22 @@
verifyIndependentOfContext("A = new SomeType *[Length]();");
verifyGoogleFormat("A = new SomeType* [Length]();");
+
+ EXPECT_EQ("int *a;\n"
+ "int *a;\n"
+ "int *a;", format("int *a;\n"
+ "int* a;\n"
+ "int *a;", getGoogleStyle()));
+ EXPECT_EQ("int* a;\n"
+ "int* a;\n"
+ "int* a;", format("int* a;\n"
+ "int* a;\n"
+ "int *a;", getGoogleStyle()));
+ EXPECT_EQ("int *a;\n"
+ "int *a;\n"
+ "int *a;", format("int *a;\n"
+ "int * a;\n"
+ "int * a;", getGoogleStyle()));
}
TEST_F(FormatTest, FormatsBinaryOperatorsPrecedingEquals) {