[clang] [clang-format] Break after string literals with trailing line breaks (PR #76795)

Björn Schäpers via cfe-commits cfe-commits at lists.llvm.org
Sat Jan 6 08:27:32 PST 2024


================
@@ -2499,6 +2499,15 @@ TEST_F(TokenAnnotatorTest, BraceKind) {
   EXPECT_BRACE_KIND(Tokens[6], BK_Block);
 }
 
+TEST_F(TokenAnnotatorTest, StreamOperator) {
+  auto Tokens = annotate("\"foo\\n\" << aux << \"foo\\n\" << \"foo\";");
+  ASSERT_EQ(Tokens.size(), 9u) << Tokens;
+  EXPECT_FALSE(Tokens[1]->MustBreakBefore);
+  EXPECT_FALSE(Tokens[3]->MustBreakBefore);
+  // Only break between string literals if the former ends with \n.
+  EXPECT_TRUE(Tokens[5]->MustBreakBefore);
+}
+
----------------
HazardyKnusperkeks wrote:

It hasn't been done. But I think it's the right place. The formatting test just tests that it breaks at a position. This here intents to test that it the flag `MustBreakBefore` is set.

I'm in favor of this kind of test, but don't insist on it.

https://github.com/llvm/llvm-project/pull/76795


More information about the cfe-commits mailing list