aboutsummaryrefslogtreecommitdiff
path: root/unittests/Format/FormatTest.cpp
diff options
context:
space:
mode:
authorManuel Klimek <klimek@google.com>2013-01-02 16:30:12 +0000
committerManuel Klimek <klimek@google.com>2013-01-02 16:30:12 +0000
commita080a187fa7e538da3212c7d5e678e4b7ae03253 (patch)
tree5a2c54db0a6a2ec4e1764cea7c7080d6898b8d84 /unittests/Format/FormatTest.cpp
parentef5b9c3d38a1f6d0921591cb2749e529a8cc4a2e (diff)
Fixes use of unescaped newlines when formatting preprocessor directives.
This is the first step towards handling preprocessor directives. This patch only fixes the most pressing issue, namely correctly escaping newlines for tokens within a sequence of a preprocessor directive. The next step will be to fix incorrect format decisions on #define directives. git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@171393 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'unittests/Format/FormatTest.cpp')
-rw-r--r--unittests/Format/FormatTest.cpp31
1 files changed, 31 insertions, 0 deletions
diff --git a/unittests/Format/FormatTest.cpp b/unittests/Format/FormatTest.cpp
index b52a9fd7c3..daae94bb13 100644
--- a/unittests/Format/FormatTest.cpp
+++ b/unittests/Format/FormatTest.cpp
@@ -373,6 +373,37 @@ TEST_F(FormatTest, StaticInitializers) {
" \"aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa\" };");
}
+TEST_F(FormatTest, FormatsSmallMacroDefinitionsInSingleLine) {
+ verifyFormat("#define ALooooooooooooooooooooooooooooooooooooooongMacro("
+ " \\\n"
+ " aLoooooooooooooooooooooooongFuuuuuuuuuuuuuunctiooooooooo)");
+}
+
+TEST_F(FormatTest, BreaksOnHashWhenDirectiveIsInvalid) {
+ EXPECT_EQ("#\n;", format("#;"));
+}
+
+TEST_F(FormatTest, UnescapedEndOfLineEndsPPDirective) {
+ EXPECT_EQ("#line 42 \"test\"\n",
+ format("# \\\n line \\\n 42 \\\n \"test\"\n"));
+ EXPECT_EQ("#define A B\n", format("# \\\n define \\\n A \\\n B\n"));
+}
+
+TEST_F(FormatTest, EndOfFileEndsPPDirective) {
+ EXPECT_EQ("#line 42 \"test\"",
+ format("# \\\n line \\\n 42 \\\n \"test\""));
+ EXPECT_EQ("#define A B", format("# \\\n define \\\n A \\\n B"));
+}
+
+TEST_F(FormatTest, MixingPreprocessorDirectivesAndNormalCode) {
+ verifyFormat("#define ALooooooooooooooooooooooooooooooooooooooongMacro("
+ " \\\n"
+ " aLoooooooooooooooooooooooongFuuuuuuuuuuuuuunctiooooooooo)\n"
+ "\n"
+ "AlooooooooooooooooooooooooooooooooooooooongCaaaaaaaaaal(\n"
+ " aLooooooooooooooooooooooonPaaaaaaaaaaaaaaaaaaaaarmmmm);\n");
+}
+
//===----------------------------------------------------------------------===//
// Line break tests.
//===----------------------------------------------------------------------===//