aboutsummaryrefslogtreecommitdiff
path: root/unittests/Format/FormatTest.cpp
diff options
context:
space:
mode:
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