summaryrefslogtreecommitdiffstats
path: root/clang/unittests/Format/FormatTest.cpp
diff options
context:
space:
mode:
authorAlexander Kornienko <alexfh@google.com>2013-10-11 21:43:05 +0000
committerAlexander Kornienko <alexfh@google.com>2013-10-11 21:43:05 +0000
commit384b40b90dfd4f5001644f1088b95424e2dffd76 (patch)
treeec8170b40ab2367183c2f869b90be5cdc7d703b1 /clang/unittests/Format/FormatTest.cpp
parent11dd4b1b56f6a7e3c860e2db934e3b5e9b97615e (diff)
downloadbcm5719-llvm-384b40b90dfd4f5001644f1088b95424e2dffd76.tar.gz
bcm5719-llvm-384b40b90dfd4f5001644f1088b95424e2dffd76.zip
Don't break string literals inside preprocessor directives.
Summary: This way we avoid breaking code which uses unknown preprocessor directives with long string literals. The specific use case in http://llvm.org/PR17035 isn't very common, but it seems to be a good idea to avoid this kind of problem anyway. Reviewers: djasper Reviewed By: djasper CC: cfe-commits, klimek Differential Revision: http://llvm-reviews.chandlerc.com/D1813 llvm-svn: 192507
Diffstat (limited to 'clang/unittests/Format/FormatTest.cpp')
-rw-r--r--clang/unittests/Format/FormatTest.cpp24
1 files changed, 19 insertions, 5 deletions
diff --git a/clang/unittests/Format/FormatTest.cpp b/clang/unittests/Format/FormatTest.cpp
index d49d49ffe3b..f80dc6fc34b 100644
--- a/clang/unittests/Format/FormatTest.cpp
+++ b/clang/unittests/Format/FormatTest.cpp
@@ -1873,14 +1873,28 @@ TEST_F(FormatTest, FormatsSmallMacroDefinitionsInSingleLine) {
}
TEST_F(FormatTest, DoesNotBreakPureVirtualFunctionDefinition) {
- verifyFormat(
- "virtual void write(ELFWriter *writerrr,\n"
- " OwningPtr<FileOutputBuffer> &buffer) = 0;");
+ verifyFormat("virtual void write(ELFWriter *writerrr,\n"
+ " OwningPtr<FileOutputBuffer> &buffer) = 0;");
}
-TEST_F(FormatTest, LayoutUnknownPPDirective) {
- EXPECT_EQ("#123 \"A string literal\"",
+TEST_F(FormatTest, BreaksStringLiteralsOnlyInDefine) {
+ verifyFormat("# 1111 \"/aaaaaaaaa/aaaaaaaaaaaaaaaaaaa/aaaaaaaa.cpp\" 2 3",
+ getLLVMStyleWithColumns(40));
+ verifyFormat("#line 11111 \"/aaaaaaaaa/aaaaaaaaaaaaaaaaaaa/aaaaaaaa.cpp\"",
+ getLLVMStyleWithColumns(40));
+ EXPECT_EQ("#define Q \\\n"
+ " \"/aaaaaaaaa/aaaaaaaaaaaaaaaaaaa/\" \\\n"
+ " \"aaaaaaaa.cpp\"",
+ format("#define Q \"/aaaaaaaaa/aaaaaaaaaaaaaaaaaaa/aaaaaaaa.cpp\"",
+ getLLVMStyleWithColumns(40)));
+}
+
+TEST_F(FormatTest, UnderstandsLinePPDirective) {
+ EXPECT_EQ("# 123 \"A string literal\"",
format(" # 123 \"A string literal\""));
+}
+
+TEST_F(FormatTest, LayoutUnknownPPDirective) {
EXPECT_EQ("#;", format("#;"));
verifyFormat("#\n;\n;\n;");
}
OpenPOWER on IntegriCloud