aboutsummaryrefslogtreecommitdiff
path: root/unittests/Format/FormatTest.cpp
diff options
context:
space:
mode:
authorManuel Klimek <klimek@google.com>2013-02-20 10:15:13 +0000
committerManuel Klimek <klimek@google.com>2013-02-20 10:15:13 +0000
commit8092a940922f307edb569036a3bb6bb722fb3a3d (patch)
tree35f73db10c7125bbf0a684c00a05aaa9ace7a33b /unittests/Format/FormatTest.cpp
parent2f98ad38b8e02146ecfc1760160dec676ce6d1e0 (diff)
Implements breaking of string literals if they stick out.
An alternative strategy to calculating the break on demand when hitting a token that would need to be broken would be to put all possible breaks inside the token into the optimizer. Currently only supports breaking at spaces; more break points to come. git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@175613 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'unittests/Format/FormatTest.cpp')
-rw-r--r--unittests/Format/FormatTest.cpp60
1 files changed, 60 insertions, 0 deletions
diff --git a/unittests/Format/FormatTest.cpp b/unittests/Format/FormatTest.cpp
index 05e5d37171..4fefb9627e 100644
--- a/unittests/Format/FormatTest.cpp
+++ b/unittests/Format/FormatTest.cpp
@@ -2843,5 +2843,65 @@ TEST_F(FormatTest, ReformatRegionAdjustsIndent) {
13, 0, getLLVMStyle()));
}
+TEST_F(FormatTest, BreakStringLiterals) {
+ EXPECT_EQ("\"some text \"\n"
+ "\"other\";",
+ format("\"some text other\";", getLLVMStyleWithColumns(12)));
+ EXPECT_EQ(
+ "#define A \\\n"
+ " \"some \" \\\n"
+ " \"text \" \\\n"
+ " \"other\";",
+ format("#define A \"some text other\";", getLLVMStyleWithColumns(12)));
+ EXPECT_EQ(
+ "#define A \\\n"
+ " \"so \" \\\n"
+ " \"text \" \\\n"
+ " \"other\";",
+ format("#define A \"so text other\";", getLLVMStyleWithColumns(12)));
+
+ EXPECT_EQ("\"some text\"",
+ format("\"some text\"", getLLVMStyleWithColumns(1)));
+ EXPECT_EQ("\"some text\"",
+ format("\"some text\"", getLLVMStyleWithColumns(11)));
+ EXPECT_EQ("\"some \"\n"
+ "\"text\"",
+ format("\"some text\"", getLLVMStyleWithColumns(10)));
+ EXPECT_EQ("\"some \"\n"
+ "\"text\"",
+ format("\"some text\"", getLLVMStyleWithColumns(7)));
+ EXPECT_EQ("\"some text\"",
+ format("\"some text\"", getLLVMStyleWithColumns(6)));
+
+ EXPECT_EQ("variable =\n"
+ " \"long string \"\n"
+ " \"literal\";",
+ format("variable = \"long string literal\";",
+ getLLVMStyleWithColumns(20)));
+
+ EXPECT_EQ("variable = f(\n"
+ " \"long string \"\n"
+ " \"literal\", short,\n"
+ " loooooooooooooooooooong);",
+ format("variable = f(\"long string literal\", short, "
+ "loooooooooooooooooooong);",
+ getLLVMStyleWithColumns(20)));
+ EXPECT_EQ(
+ "f(\"one two\".split(\n"
+ " variable));",
+ format("f(\"one two\".split(variable));", getLLVMStyleWithColumns(20)));
+ EXPECT_EQ("f(\"one two three four five six \"\n"
+ " \"seven\".split(\n"
+ " really_looooong_variable));",
+ format("f(\"one two three four five six seven\"."
+ "split(really_looooong_variable));",
+ getLLVMStyleWithColumns(33)));
+
+ EXPECT_EQ("f(\"some \"\n"
+ " \"text\",\n"
+ " other);",
+ format("f(\"some text\", other);", getLLVMStyleWithColumns(10)));
+}
+
} // end namespace tooling
} // end namespace clang