diff options
author | Owen Pan <owenpiano@gmail.com> | 2025-07-21 19:11:17 -0700 |
---|---|---|
committer | GitHub <noreply@github.com> | 2025-07-21 19:11:17 -0700 |
commit | 4d48996ff05305d4a5774f3e232c2ee4a06c3d2a (patch) | |
tree | a6f08b86c182c819423a05b7233aab85babb31a4 /clang/unittests/Format | |
parent | fcdcc4ea7ac960c79246b3bd428f14ea350e63e2 (diff) | |
download | llvm-4d48996ff05305d4a5774f3e232c2ee4a06c3d2a.zip llvm-4d48996ff05305d4a5774f3e232c2ee4a06c3d2a.tar.gz llvm-4d48996ff05305d4a5774f3e232c2ee4a06c3d2a.tar.bz2 |
[clang-format][NFC] Clean up around StringRef initializations (#149765)
Consistently use `constexpr StringRef Code("string literal");`.
Diffstat (limited to 'clang/unittests/Format')
-rw-r--r-- | clang/unittests/Format/BracesInserterTest.cpp | 6 | ||||
-rw-r--r-- | clang/unittests/Format/FormatTest.cpp | 55 | ||||
-rw-r--r-- | clang/unittests/Format/FormatTestComments.cpp | 10 | ||||
-rw-r--r-- | clang/unittests/Format/FormatTestJava.cpp | 12 | ||||
-rw-r--r-- | clang/unittests/Format/FormatTestSelective.cpp | 17 | ||||
-rw-r--r-- | clang/unittests/Format/IntegerLiteralSeparatorTest.cpp | 26 | ||||
-rw-r--r-- | clang/unittests/Format/SortIncludesTest.cpp | 4 | ||||
-rw-r--r-- | clang/unittests/Format/TokenAnnotatorTest.cpp | 4 |
8 files changed, 67 insertions, 67 deletions
diff --git a/clang/unittests/Format/BracesInserterTest.cpp b/clang/unittests/Format/BracesInserterTest.cpp index e0c447d..572e53e 100644 --- a/clang/unittests/Format/BracesInserterTest.cpp +++ b/clang/unittests/Format/BracesInserterTest.cpp @@ -257,9 +257,9 @@ TEST_F(BracesInserterTest, InsertBracesRange) { FormatStyle Style = getLLVMStyle(); Style.InsertBraces = true; - const StringRef Code("while (a)\n" - " if (b)\n" - " return;"); + constexpr StringRef Code("while (a)\n" + " if (b)\n" + " return;"); verifyFormat("while (a) {\n" " if (b)\n" diff --git a/clang/unittests/Format/FormatTest.cpp b/clang/unittests/Format/FormatTest.cpp index 7e3d2a9..dbf6950 100644 --- a/clang/unittests/Format/FormatTest.cpp +++ b/clang/unittests/Format/FormatTest.cpp @@ -4803,12 +4803,13 @@ TEST_F(FormatTest, FormatsInlineASM) { "int i;"); auto Style = getLLVMStyleWithColumns(0); - const StringRef Code1{"asm(\"xyz\" : \"=a\"(a), \"=d\"(b) : \"a\"(data));"}; - const StringRef Code2{"asm(\"xyz\"\n" - " : \"=a\"(a), \"=d\"(b)\n" - " : \"a\"(data));"}; - const StringRef Code3{"asm(\"xyz\" : \"=a\"(a), \"=d\"(b)\n" - " : \"a\"(data));"}; + constexpr StringRef Code1( + "asm(\"xyz\" : \"=a\"(a), \"=d\"(b) : \"a\"(data));"); + constexpr StringRef Code2("asm(\"xyz\"\n" + " : \"=a\"(a), \"=d\"(b)\n" + " : \"a\"(data));"); + constexpr StringRef Code3("asm(\"xyz\" : \"=a\"(a), \"=d\"(b)\n" + " : \"a\"(data));"); Style.BreakBeforeInlineASMColon = FormatStyle::BBIAS_OnlyMultiline; verifyFormat(Code1, Style); @@ -6704,16 +6705,16 @@ TEST_F(FormatTest, EscapedNewlines) { " int x(int a);", AlignLeft); - constexpr StringRef Code{"#define A \\\n" + constexpr StringRef Code("#define A \\\n" " int a123; \\\n" " int a; \\\n" - " int a1234;"}; + " int a1234;"); verifyFormat(Code, AlignLeft); - constexpr StringRef Code2{"#define A \\\n" + constexpr StringRef Code2("#define A \\\n" " int a123; \\\n" " int a; \\\n" - " int a1234;"}; + " int a1234;"); auto LastLine = getLLVMStyle(); LastLine.AlignEscapedNewlines = FormatStyle::ENAS_LeftWithLastLine; verifyFormat(Code2, LastLine); @@ -12108,9 +12109,9 @@ TEST_F(FormatTest, PointerAlignmentFallback) { FormatStyle Style = getLLVMStyle(); Style.DerivePointerAlignment = true; - const StringRef Code("int* p;\n" - "int *q;\n" - "int * r;"); + constexpr StringRef Code("int* p;\n" + "int *q;\n" + "int * r;"); EXPECT_EQ(Style.PointerAlignment, FormatStyle::PAS_Right); verifyFormat("int *p;\n" @@ -15025,7 +15026,7 @@ TEST_F(FormatTest, PullTrivialFunctionDefinitionsIntoSingleLine) { " aaaaaaaaaaaaaaaaaa,\n" " aaaaaaaaaaaaaaaaaabbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbb) {}"); - constexpr StringRef Code{"void foo() { /* Empty */ }"}; + constexpr StringRef Code("void foo() { /* Empty */ }"); verifyFormat(Code); verifyFormat(Code, "void foo() { /* Empty */\n" "}"); @@ -27255,7 +27256,7 @@ TEST_F(FormatTest, IndentAccessModifiers) { TEST_F(FormatTest, LimitlessStringsAndComments) { auto Style = getLLVMStyleWithColumns(0); - constexpr StringRef Code = + constexpr StringRef Code( "/**\n" " * This is a multiline comment with quite some long lines, at least for " "the LLVM Style.\n" @@ -27276,7 +27277,7 @@ TEST_F(FormatTest, LimitlessStringsAndComments) { " const std::string SmallString = \"Hello World\";\n" " // Small line comment\n" " return String.size() > SmallString.size();\n" - "}"; + "}"); verifyNoChange(Code, Style); } @@ -28400,9 +28401,9 @@ TEST_F(FormatTest, InsertNewlineAtEOF) { verifyNoChange("int i;\n", Style); verifyFormat("int i;\n", "int i;", Style); - constexpr StringRef Code{"namespace {\n" + constexpr StringRef Code("namespace {\n" "int i;\n" - "} // namespace"}; + "} // namespace"); verifyFormat(Code.str() + '\n', Code, Style, {tooling::Range(19, 13)}); // line 3 } @@ -28411,7 +28412,7 @@ TEST_F(FormatTest, KeepEmptyLinesAtEOF) { FormatStyle Style = getLLVMStyle(); Style.KeepEmptyLines.AtEndOfFile = true; - const StringRef Code{"int i;\n\n"}; + constexpr StringRef Code("int i;\n\n"); verifyNoChange(Code, Style); verifyFormat(Code, "int i;\n\n\n", Style); } @@ -28644,8 +28645,8 @@ TEST_F(FormatTest, PPDirectivesAndCommentsInBracedInit) { } TEST_F(FormatTest, BreakAdjacentStringLiterals) { - constexpr StringRef Code{ - "return \"Code\" \"\\0\\52\\26\\55\\55\\0\" \"x013\" \"\\02\\xBA\";"}; + constexpr StringRef Code( + "return \"Code\" \"\\0\\52\\26\\55\\55\\0\" \"x013\" \"\\02\\xBA\";"); verifyFormat("return \"Code\"\n" " \"\\0\\52\\26\\55\\55\\0\"\n" @@ -29056,9 +29057,9 @@ TEST_F(FormatTest, KeepFormFeed) { auto Style = getLLVMStyle(); Style.KeepFormFeed = true; - constexpr StringRef NoFormFeed{"int i;\n" + constexpr StringRef NoFormFeed("int i;\n" "\n" - "void f();"}; + "void f();"); verifyFormat(NoFormFeed, "int i;\n" " \f\n" @@ -29080,9 +29081,9 @@ TEST_F(FormatTest, KeepFormFeed) { "void f();\f", Style); - constexpr StringRef FormFeed{"int i;\n" + constexpr StringRef FormFeed("int i;\n" "\f\n" - "void f();"}; + "void f();"); verifyNoChange(FormFeed, Style); Style.LineEnding = FormatStyle::LE_LF; @@ -29092,10 +29093,10 @@ TEST_F(FormatTest, KeepFormFeed) { "void f();", Style); - constexpr StringRef FormFeedBeforeEmptyLine{"int i;\n" + constexpr StringRef FormFeedBeforeEmptyLine("int i;\n" "\f\n" "\n" - "void f();"}; + "void f();"); Style.MaxEmptyLinesToKeep = 2; verifyFormat(FormFeedBeforeEmptyLine, "int i;\n" diff --git a/clang/unittests/Format/FormatTestComments.cpp b/clang/unittests/Format/FormatTestComments.cpp index 8870755..69026bc 100644 --- a/clang/unittests/Format/FormatTestComments.cpp +++ b/clang/unittests/Format/FormatTestComments.cpp @@ -1120,11 +1120,11 @@ TEST_F(FormatTestComments, KeepsLevelOfCommentBeforePPDirective) { " }\n" "}")); - const StringRef Code("void func() {\n" - " // clang-format off\n" - " #define KV(value) #value, value\n" - " // clang-format on\n" - "}"); + constexpr StringRef Code("void func() {\n" + " // clang-format off\n" + " #define KV(value) #value, value\n" + " // clang-format on\n" + "}"); verifyNoChange(Code); auto Style = getLLVMStyle(); diff --git a/clang/unittests/Format/FormatTestJava.cpp b/clang/unittests/Format/FormatTestJava.cpp index ca5aba0..1275564 100644 --- a/clang/unittests/Format/FormatTestJava.cpp +++ b/clang/unittests/Format/FormatTestJava.cpp @@ -631,17 +631,17 @@ TEST_F(FormatTestJava, SwitchExpression) { "});", Style); - constexpr StringRef Code1{"i = switch (day) {\n" + constexpr StringRef Code1("i = switch (day) {\n" " case THURSDAY, SATURDAY -> 8;\n" " case WEDNESDAY -> 9;\n" " default -> 0;\n" - "};"}; + "};"); verifyFormat(Code1, Style); Style.IndentCaseLabels = true; verifyFormat(Code1, Style); - constexpr StringRef Code2{"i = switch (day) {\n" + constexpr StringRef Code2("i = switch (day) {\n" " case THURSDAY, SATURDAY -> {\n" " foo();\n" " yield 8;\n" @@ -653,17 +653,17 @@ TEST_F(FormatTestJava, SwitchExpression) { " default -> {\n" " yield 0;\n" " }\n" - "};"}; + "};"); verifyFormat(Code2, Style); Style.IndentCaseLabels = false; verifyFormat(Code2, Style); - constexpr StringRef Code3{"switch (day) {\n" + constexpr StringRef Code3("switch (day) {\n" "case THURSDAY, SATURDAY -> i = 8;\n" "case WEDNESDAY -> i = 9;\n" "default -> i = 0;\n" - "};"}; + "};"); verifyFormat(Code3, Style); Style.IndentCaseLabels = true; diff --git a/clang/unittests/Format/FormatTestSelective.cpp b/clang/unittests/Format/FormatTestSelective.cpp index fa7630a..1a01153 100644 --- a/clang/unittests/Format/FormatTestSelective.cpp +++ b/clang/unittests/Format/FormatTestSelective.cpp @@ -672,15 +672,14 @@ TEST_F(FormatTestSelective, FormatMacroRegardlessOfPreviousIndent) { // need to be adapted. Style = getLLVMStyle(); - const StringRef Code{" class Foo {\n" - " void test() {\n" - " #ifdef 1\n" - " #define some\n" // format this line - " #endif\n" - " }};"}; - - EXPECT_EQ(Style.IndentPPDirectives, - FormatStyle::PPDirectiveIndentStyle::PPDIS_None); + constexpr StringRef Code(" class Foo {\n" + " void test() {\n" + " #ifdef 1\n" + " #define some\n" // format this line + " #endif\n" + " }};"); + + EXPECT_EQ(Style.IndentPPDirectives, FormatStyle::PPDIS_None); EXPECT_EQ(" class Foo {\n" " void test() {\n" " #ifdef 1\n" diff --git a/clang/unittests/Format/IntegerLiteralSeparatorTest.cpp b/clang/unittests/Format/IntegerLiteralSeparatorTest.cpp index b1e42e9..8681c3d 100644 --- a/clang/unittests/Format/IntegerLiteralSeparatorTest.cpp +++ b/clang/unittests/Format/IntegerLiteralSeparatorTest.cpp @@ -24,7 +24,7 @@ TEST_F(IntegerLiteralSeparatorTest, SingleQuoteAsSeparator) { EXPECT_EQ(Style.IntegerLiteralSeparator.Decimal, 0); EXPECT_EQ(Style.IntegerLiteralSeparator.Hex, 0); - const StringRef Binary("b = 0b10011'11'0110'1u;"); + constexpr StringRef Binary("b = 0b10011'11'0110'1u;"); verifyFormat(Binary, Style); Style.IntegerLiteralSeparator.Binary = -1; verifyFormat("b = 0b100111101101u;", Binary, Style); @@ -33,14 +33,14 @@ TEST_F(IntegerLiteralSeparatorTest, SingleQuoteAsSeparator) { Style.IntegerLiteralSeparator.Binary = 4; verifyFormat("b = 0b1001'1110'1101u;", Binary, Style); - const StringRef Decimal("d = 184467'440737'0'95505'92Ull;"); + constexpr StringRef Decimal("d = 184467'440737'0'95505'92Ull;"); verifyFormat(Decimal, Style); Style.IntegerLiteralSeparator.Decimal = -1; verifyFormat("d = 18446744073709550592Ull;", Decimal, Style); Style.IntegerLiteralSeparator.Decimal = 3; verifyFormat("d = 18'446'744'073'709'550'592Ull;", Decimal, Style); - const StringRef Hex("h = 0xDEAD'BEEF'DE'AD'BEE'Fuz;"); + constexpr StringRef Hex("h = 0xDEAD'BEEF'DE'AD'BEE'Fuz;"); verifyFormat(Hex, Style); Style.IntegerLiteralSeparator.Hex = -1; verifyFormat("h = 0xDEADBEEFDEADBEEFuz;", Hex, Style); @@ -87,9 +87,9 @@ TEST_F(IntegerLiteralSeparatorTest, SingleQuoteAsSeparator) { TEST_F(IntegerLiteralSeparatorTest, UnderscoreAsSeparator) { FormatStyle Style = getLLVMStyle(); - const StringRef Binary("B = 0B10011_11_0110_1;"); - const StringRef Decimal("d = 184467_440737_0_95505_92;"); - const StringRef Hex("H = 0XDEAD_BEEF_DE_AD_BEE_F;"); + constexpr StringRef Binary("B = 0B10011_11_0110_1;"); + constexpr StringRef Decimal("d = 184467_440737_0_95505_92;"); + constexpr StringRef Hex("H = 0XDEAD_BEEF_DE_AD_BEE_F;"); auto TestUnderscore = [&](auto Language) { Style.Language = Language; @@ -173,16 +173,16 @@ TEST_F(IntegerLiteralSeparatorTest, FixRanges) { FormatStyle Style = getLLVMStyle(); Style.IntegerLiteralSeparator.Decimal = 3; - const StringRef Code("i = -12'34;\n" - "// clang-format off\n" - "j = 123'4;\n" - "// clang-format on\n" - "k = +1'23'4;"); - const StringRef Expected("i = -1'234;\n" + constexpr StringRef Code("i = -12'34;\n" "// clang-format off\n" "j = 123'4;\n" "// clang-format on\n" - "k = +1'234;"); + "k = +1'23'4;"); + constexpr StringRef Expected("i = -1'234;\n" + "// clang-format off\n" + "j = 123'4;\n" + "// clang-format on\n" + "k = +1'234;"); verifyFormat(Expected, Code, Style); diff --git a/clang/unittests/Format/SortIncludesTest.cpp b/clang/unittests/Format/SortIncludesTest.cpp index 5194d65..48ecd5d 100644 --- a/clang/unittests/Format/SortIncludesTest.cpp +++ b/clang/unittests/Format/SortIncludesTest.cpp @@ -1084,10 +1084,10 @@ TEST_F(SortIncludesTest, DoNotSortLikelyXml) { } TEST_F(SortIncludesTest, DoNotSortCSharp) { - constexpr StringRef Code{"const string expectedDataStruct = @\"\n" + constexpr StringRef Code("const string expectedDataStruct = @\"\n" " #include <b.h>\n" " #include <a.h>\n" - " \";"}; + " \";"); FmtStyle.Language = FormatStyle::LK_CSharp; EXPECT_TRUE(sortIncludes(FmtStyle, Code, GetCodeRange(Code), "a.cs").empty()); } diff --git a/clang/unittests/Format/TokenAnnotatorTest.cpp b/clang/unittests/Format/TokenAnnotatorTest.cpp index ce7787e..7f99655 100644 --- a/clang/unittests/Format/TokenAnnotatorTest.cpp +++ b/clang/unittests/Format/TokenAnnotatorTest.cpp @@ -618,7 +618,7 @@ TEST_F(TokenAnnotatorTest, UnderstandsStructs) { EXPECT_TOKEN(Tokens[19], tok::l_brace, TT_StructLBrace); EXPECT_TOKEN(Tokens[20], tok::r_brace, TT_StructRBrace); - constexpr StringRef Code{"struct EXPORT StructName {};"}; + constexpr StringRef Code("struct EXPORT StructName {};"); Tokens = annotate(Code); ASSERT_EQ(Tokens.size(), 7u) << Tokens; @@ -3958,7 +3958,7 @@ TEST_F(TokenAnnotatorTest, SplitPenalty) { } TEST_F(TokenAnnotatorTest, TemplateName) { - constexpr StringRef Code{"return Foo < A || B > (C ^ D);"}; + constexpr StringRef Code("return Foo < A || B > (C ^ D);"); auto Tokens = annotate(Code); ASSERT_EQ(Tokens.size(), 14u) << Tokens; |