[clang] [clang-format] Correctly annotate designated initializer with PP if (PR #65409)
via cfe-commits
cfe-commits at lists.llvm.org
Wed Sep 6 23:52:49 PDT 2023
================
@@ -1998,6 +1998,41 @@ TEST_F(TokenAnnotatorTest, UnderstandsNestedBlocks) {
EXPECT_BRACE_KIND(Tokens[10], BK_Block);
}
+TEST_F(TokenAnnotatorTest, UnderstandDesignatedInitializers) {
+ auto Tokens = annotate("SomeStruct { .a = 1 };");
+ ASSERT_EQ(Tokens.size(), 9u) << Tokens;
+ EXPECT_BRACE_KIND(Tokens[1], BK_BracedInit);
+ EXPECT_TOKEN(Tokens[2], tok::period, TT_DesignatedInitializerPeriod);
+
+ Tokens = annotate("SomeStruct { .a = 1, .b = 2 };");
+ ASSERT_EQ(Tokens.size(), 14u) << Tokens;
+ EXPECT_BRACE_KIND(Tokens[1], BK_BracedInit);
+ EXPECT_TOKEN(Tokens[2], tok::period, TT_DesignatedInitializerPeriod);
+ EXPECT_TOKEN(Tokens[7], tok::period, TT_DesignatedInitializerPeriod);
+
+ Tokens = annotate("SomeStruct {\n"
+ "#ifdef FOO\n"
+ " .a = 1,\n"
+ "#endif\n"
+ " .b = 2\n"
+ "};");
+ ASSERT_EQ(Tokens.size(), 19u) << Tokens;
+ EXPECT_BRACE_KIND(Tokens[1], BK_BracedInit);
+ EXPECT_TOKEN(Tokens[5], tok::period, TT_DesignatedInitializerPeriod);
+ EXPECT_TOKEN(Tokens[12], tok::period, TT_DesignatedInitializerPeriod);
+
+ Tokens = annotate("SomeStruct {\n"
+ "#if defined FOO\n"
+ " .a = 1,\n"
+ "#endif\n"
+ " .b = 2\n"
+ "};");
----------------
owenca wrote:
Ditto.
https://github.com/llvm/llvm-project/pull/65409
More information about the cfe-commits
mailing list