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

kadir çetinkaya via cfe-commits cfe-commits at lists.llvm.org
Fri Jan 5 07:28:57 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);
+}
+
----------------
kadircet wrote:

i added this test as it's more "unit" compared to the final formatting, which might be affected by all sorts of other things (column limits, bin-packing etc.). whereas this one particularly checks that we provide the "relevant" signal only in the case we care about.

we can't really have it in the FormatTest, as this is the file that has utilities for asserting on annotations of tokens.

if you think that isn't useful, i am happy to drop it completely, but i believe this is valuable for the reason i mentioned above.

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


More information about the cfe-commits mailing list