aboutsummaryrefslogtreecommitdiff
path: root/unittests/Format/FormatTest.cpp
diff options
context:
space:
mode:
authorManuel Klimek <klimek@google.com>2013-01-02 18:33:23 +0000
committerManuel Klimek <klimek@google.com>2013-01-02 18:33:23 +0000
commit060143e4ad7f80c4349d472c06a63a953650c2a9 (patch)
tree66bc38156700622107b3459855ba1ebc84892c0f /unittests/Format/FormatTest.cpp
parent5eda31ee30106c769b5829683761d42e6e50467f (diff)
Fixes multiple formatting bugs.
Fixes: - incorrect handling of multiple consecutive preprocessor directives - crash when trying to right align the escpaed newline for a line that is longer than the column limit - using only ColumnLimit-1 columns when layouting with escaped newlines inside preprocessor directives git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@171401 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'unittests/Format/FormatTest.cpp')
-rw-r--r--unittests/Format/FormatTest.cpp34
1 files changed, 31 insertions, 3 deletions
diff --git a/unittests/Format/FormatTest.cpp b/unittests/Format/FormatTest.cpp
index eac8f4c7f3..e713280d91 100644
--- a/unittests/Format/FormatTest.cpp
+++ b/unittests/Format/FormatTest.cpp
@@ -64,12 +64,19 @@ protected:
return MessedUp;
}
- void verifyFormat(llvm::StringRef Code) {
- EXPECT_EQ(Code.str(), format(messUp(Code)));
+ FormatStyle getLLVMStyleWithColumns(unsigned ColumnLimit) {
+ FormatStyle Style = getLLVMStyle();
+ Style.ColumnLimit = ColumnLimit;
+ return Style;
+ }
+
+ void verifyFormat(llvm::StringRef Code,
+ const FormatStyle &Style = getLLVMStyle()) {
+ EXPECT_EQ(Code.str(), format(messUp(Code), Style));
}
void verifyGoogleFormat(llvm::StringRef Code) {
- EXPECT_EQ(Code.str(), format(messUp(Code), getGoogleStyle()));
+ verifyFormat(Code, getGoogleStyle());
}
};
@@ -396,6 +403,27 @@ TEST_F(FormatTest, EndOfFileEndsPPDirective) {
EXPECT_EQ("#define A B", format("# \\\n define \\\n A \\\n B"));
}
+TEST_F(FormatTest, IndentsPPDirectiveInReducedSpace) {
+ // If the macro fits in one line, we have the full width.
+ verifyFormat("#define A(B)", getLLVMStyleWithColumns(12));
+
+ verifyFormat("#define A(\\\n B)", getLLVMStyleWithColumns(11));
+ verifyFormat("#define AA(\\\n B)", getLLVMStyleWithColumns(11));
+ verifyFormat("#define A( \\\n A, B)", getLLVMStyleWithColumns(12));
+}
+
+TEST_F(FormatTest, HandlePreprocessorDirectiveContext) {
+ verifyFormat(
+ "// some comment\n"
+ "\n"
+ "#include \"a.h\"\n"
+ "#define A(A,\\\n"
+ " B)\n"
+ "#include \"b.h\"\n"
+ "\n"
+ "// some comment\n", getLLVMStyleWithColumns(13));
+}
+
TEST_F(FormatTest, MixingPreprocessorDirectivesAndNormalCode) {
verifyFormat("#define ALooooooooooooooooooooooooooooooooooooooongMacro("
" \\\n"