aboutsummaryrefslogtreecommitdiff
path: root/clang/unittests/Format
diff options
context:
space:
mode:
Diffstat (limited to 'clang/unittests/Format')
-rw-r--r--clang/unittests/Format/BracesInserterTest.cpp6
-rw-r--r--clang/unittests/Format/ConfigParseTest.cpp1
-rw-r--r--clang/unittests/Format/FormatTest.cpp136
-rw-r--r--clang/unittests/Format/FormatTestComments.cpp10
-rw-r--r--clang/unittests/Format/FormatTestJava.cpp12
-rw-r--r--clang/unittests/Format/FormatTestSelective.cpp23
-rw-r--r--clang/unittests/Format/IntegerLiteralSeparatorTest.cpp26
-rw-r--r--clang/unittests/Format/SortIncludesTest.cpp4
-rw-r--r--clang/unittests/Format/TokenAnnotatorTest.cpp4
9 files changed, 132 insertions, 90 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/ConfigParseTest.cpp b/clang/unittests/Format/ConfigParseTest.cpp
index 65d8b36..9de3cca 100644
--- a/clang/unittests/Format/ConfigParseTest.cpp
+++ b/clang/unittests/Format/ConfigParseTest.cpp
@@ -249,6 +249,7 @@ TEST(ConfigParseTest, ParsesConfigurationBools) {
CHECK_PARSE_NESTED_BOOL(SpaceBeforeParensOptions,
AfterFunctionDefinitionName);
CHECK_PARSE_NESTED_BOOL(SpaceBeforeParensOptions, AfterIfMacros);
+ CHECK_PARSE_NESTED_BOOL(SpaceBeforeParensOptions, AfterNot);
CHECK_PARSE_NESTED_BOOL(SpaceBeforeParensOptions, AfterOverloadedOperator);
CHECK_PARSE_NESTED_BOOL(SpaceBeforeParensOptions, AfterPlacementOperator);
CHECK_PARSE_NESTED_BOOL(SpaceBeforeParensOptions, BeforeNonEmptyParentheses);
diff --git a/clang/unittests/Format/FormatTest.cpp b/clang/unittests/Format/FormatTest.cpp
index 0bc1c6d..9c5aa11 100644
--- a/clang/unittests/Format/FormatTest.cpp
+++ b/clang/unittests/Format/FormatTest.cpp
@@ -3185,7 +3185,7 @@ TEST_F(FormatTest, FormatsLabels) {
// The opening brace may either be on the same unwrapped line as the colon or
// on a separate one. The formatter should recognize both.
Style = getLLVMStyle();
- Style.BreakBeforeBraces = FormatStyle::BraceBreakingStyle::BS_Allman;
+ Style.BreakBeforeBraces = FormatStyle::BS_Allman;
verifyFormat("{\n"
" some_code();\n"
"test_label:\n"
@@ -3206,7 +3206,7 @@ TEST_F(FormatTest, FormatsLabels) {
TEST_F(FormatTest, MultiLineControlStatements) {
FormatStyle Style = getLLVMStyleWithColumns(20);
- Style.BreakBeforeBraces = FormatStyle::BraceBreakingStyle::BS_Custom;
+ Style.BreakBeforeBraces = FormatStyle::BS_Custom;
Style.BraceWrapping.AfterControlStatement = FormatStyle::BWACS_MultiLine;
// Short lines should keep opening brace on same line.
verifyFormat("if (foo) {\n"
@@ -3441,7 +3441,7 @@ TEST_F(FormatTest, MultiLineControlStatements) {
TEST_F(FormatTest, BeforeWhile) {
FormatStyle Style = getLLVMStyle();
- Style.BreakBeforeBraces = FormatStyle::BraceBreakingStyle::BS_Custom;
+ Style.BreakBeforeBraces = FormatStyle::BS_Custom;
verifyFormat("do {\n"
" foo();\n"
@@ -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);
@@ -6681,6 +6682,17 @@ TEST_F(FormatTest, EscapedNewlines) {
" int x(int a);",
AlignLeft);
+ // Escaped with a trigraph. The program just has to avoid crashing.
+ verifyNoCrash("#define A \?\?/\n"
+ "int i;\?\?/\n"
+ " int j;");
+ verifyNoCrash("#define A \?\?/\r\n"
+ "int i;\?\?/\r\n"
+ " int j;");
+ verifyNoCrash("#define A \?\?/\n"
+ "int i;",
+ getGoogleStyle(FormatStyle::LK_CSharp));
+
// CRLF line endings
verifyFormat("#define A \\\r\n int i; \\\r\n int j;",
"#define A \\\r\nint i;\\\r\n int j;", Narrow);
@@ -6693,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);
@@ -7771,6 +7783,16 @@ TEST_F(FormatTest, ConstructorInitializers) {
"Constructor() :\n"
" // Comment forcing unwanted break.\n"
" aaaa(aaaa) {}");
+
+ // Braced initializers with trailing commas.
+ verifyFormat("MyClass::MyClass()\n"
+ " : aaaa{\n"
+ " 0,\n"
+ " },\n"
+ " bbbb{\n"
+ " 0,\n"
+ " } {}",
+ "MyClass::MyClass():aaaa{0,},bbbb{0,}{}");
}
TEST_F(FormatTest, AllowAllConstructorInitializersOnNextLine) {
@@ -8571,10 +8593,10 @@ TEST_F(FormatTest, BreaksFunctionDeclarations) {
"operator<<(const SomeLooooooooooooooooooooooooogType &other);");
verifyGoogleFormat(
"SomeLoooooooooooooooooooooooooooooogType operator>>(\n"
- " const SomeLooooooooogType &a, const SomeLooooooooogType &b);");
+ " const SomeLooooooooogType& a, const SomeLooooooooogType& b);");
verifyGoogleFormat(
"SomeLoooooooooooooooooooooooooooooogType operator<<(\n"
- " const SomeLooooooooogType &a, const SomeLooooooooogType &b);");
+ " const SomeLooooooooogType& a, const SomeLooooooooogType& b);");
verifyFormat("void aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa(\n"
" int aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa = 1);");
@@ -8583,7 +8605,7 @@ TEST_F(FormatTest, BreaksFunctionDeclarations) {
verifyGoogleFormat(
"typename aaaaaaaaaa<aaaaaa>::aaaaaaaaaaa\n"
"aaaaaaaaaa<aaaaaa>::aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa(\n"
- " bool *aaaaaaaaaaaaaaaaaa, bool *aa) {}");
+ " bool* aaaaaaaaaaaaaaaaaa, bool* aa) {}");
verifyGoogleFormat("template <typename T>\n"
"aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa\n"
"aaaaaaaaaaaaaaaaaaaaaaa<T>::aaaaaaaaaaaaa(\n"
@@ -12091,15 +12113,22 @@ TEST_F(FormatTest, UnderstandsFunctionRefQualification) {
Prefix = "void a() const &;\n"
"void b() const &;\n";
verifyFormat(Prefix + "int *x;", Prefix + "int* x;", DerivePointerAlignment);
+
+ constexpr StringRef Code("MACRO(int*, std::function<void() &&>);");
+ verifyFormat(Code, DerivePointerAlignment);
+
+ auto Style = getGoogleStyle();
+ Style.DerivePointerAlignment = true;
+ verifyFormat(Code, Style);
}
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"
@@ -12891,27 +12920,31 @@ TEST_F(FormatTest, UnderstandsEllipsis) {
}
TEST_F(FormatTest, AdaptivelyFormatsPointersAndReferences) {
+ auto Style = getGoogleStyle();
+ EXPECT_FALSE(Style.DerivePointerAlignment);
+ Style.DerivePointerAlignment = true;
+
verifyFormat("int *a;\n"
"int *a;\n"
"int *a;",
"int *a;\n"
"int* a;\n"
"int *a;",
- getGoogleStyle());
+ Style);
verifyFormat("int* a;\n"
"int* a;\n"
"int* a;",
"int* a;\n"
"int* a;\n"
"int *a;",
- getGoogleStyle());
+ Style);
verifyFormat("int *a;\n"
"int *a;\n"
"int *a;",
"int *a;\n"
"int * a;\n"
"int * a;",
- getGoogleStyle());
+ Style);
verifyFormat("auto x = [] {\n"
" int *a;\n"
" int *a;\n"
@@ -12920,7 +12953,7 @@ TEST_F(FormatTest, AdaptivelyFormatsPointersAndReferences) {
"auto x=[]{int *a;\n"
"int * a;\n"
"int * a;};",
- getGoogleStyle());
+ Style);
}
TEST_F(FormatTest, UnderstandsRvalueReferences) {
@@ -13056,7 +13089,7 @@ TEST_F(FormatTest, FormatsCasts) {
verifyFormat("virtual void foo(char &) const;");
verifyFormat("virtual void foo(int *a, char *) const;");
verifyFormat("int a = sizeof(int *) + b;");
- verifyGoogleFormat("int a = alignof(int *) + b;");
+ verifyGoogleFormat("int a = alignof(int*) + b;");
verifyFormat("bool b = f(g<int>) && c;");
verifyFormat("typedef void (*f)(int i) func;");
verifyFormat("void operator++(int) noexcept;");
@@ -15014,7 +15047,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"
"}");
@@ -17652,6 +17685,12 @@ TEST_F(FormatTest, ConfigurableSpaceBeforeParens) {
verifyFormat("int x = int (y);", SomeSpace2);
verifyFormat("auto lambda = []() { return 0; };", SomeSpace2);
+ auto Style = getLLVMStyle();
+ Style.SpaceBeforeParens = FormatStyle::SBPO_Custom;
+ EXPECT_FALSE(Style.SpaceBeforeParensOptions.AfterNot);
+ Style.SpaceBeforeParensOptions.AfterNot = true;
+ verifyFormat("return not (a || b);", Style);
+
FormatStyle SpaceAfterOverloadedOperator = getLLVMStyle();
SpaceAfterOverloadedOperator.SpaceBeforeParens = FormatStyle::SBPO_Custom;
SpaceAfterOverloadedOperator.SpaceBeforeParensOptions
@@ -23779,7 +23818,7 @@ TEST_F(FormatTest, FormatsLambdas) {
LLVMWithBeforeLambdaBody.BreakBeforeBraces = FormatStyle::BS_Custom;
LLVMWithBeforeLambdaBody.BraceWrapping.BeforeLambdaBody = true;
LLVMWithBeforeLambdaBody.AllowShortLambdasOnASingleLine =
- FormatStyle::ShortLambdaStyle::SLS_None;
+ FormatStyle::SLS_None;
verifyFormat("FctWithOneNestedLambdaInline_SLS_None(\n"
" []()\n"
" {\n"
@@ -23815,7 +23854,7 @@ TEST_F(FormatTest, FormatsLambdas) {
LLVMWithBeforeLambdaBody);
LLVMWithBeforeLambdaBody.AllowShortLambdasOnASingleLine =
- FormatStyle::ShortLambdaStyle::SLS_Empty;
+ FormatStyle::SLS_Empty;
verifyFormat("FctWithOneNestedLambdaInline_SLS_Empty(\n"
" []()\n"
" {\n"
@@ -23862,7 +23901,7 @@ TEST_F(FormatTest, FormatsLambdas) {
LLVMWithBeforeLambdaBody);
LLVMWithBeforeLambdaBody.AllowShortLambdasOnASingleLine =
- FormatStyle::ShortLambdaStyle::SLS_Inline;
+ FormatStyle::SLS_Inline;
verifyFormat("FctWithOneNestedLambdaInline_SLS_Inline([]() { return 17; });",
LLVMWithBeforeLambdaBody);
verifyFormat("FctWithOneNestedLambdaEmpty_SLS_Inline([]() {});",
@@ -23893,7 +23932,7 @@ TEST_F(FormatTest, FormatsLambdas) {
LLVMWithBeforeLambdaBody);
LLVMWithBeforeLambdaBody.AllowShortLambdasOnASingleLine =
- FormatStyle::ShortLambdaStyle::SLS_All;
+ FormatStyle::SLS_All;
verifyFormat("FctWithOneNestedLambdaInline_SLS_All([]() { return 17; });",
LLVMWithBeforeLambdaBody);
verifyFormat("FctWithOneNestedLambdaEmpty_SLS_All([]() {});",
@@ -24025,7 +24064,7 @@ TEST_F(FormatTest, FormatsLambdas) {
LLVMWithBeforeLambdaBody);
LLVMWithBeforeLambdaBody.AllowShortLambdasOnASingleLine =
- FormatStyle::ShortLambdaStyle::SLS_None;
+ FormatStyle::SLS_None;
verifyFormat("auto select = [this]() -> const Library::Object *\n"
"{\n"
@@ -24273,7 +24312,7 @@ TEST_F(FormatTest, LambdaWithLineComments) {
LLVMWithBeforeLambdaBody.BreakBeforeBraces = FormatStyle::BS_Custom;
LLVMWithBeforeLambdaBody.BraceWrapping.BeforeLambdaBody = true;
LLVMWithBeforeLambdaBody.AllowShortLambdasOnASingleLine =
- FormatStyle::ShortLambdaStyle::SLS_All;
+ FormatStyle::SLS_All;
verifyFormat("auto k = []() { return; }", LLVMWithBeforeLambdaBody);
verifyFormat("auto k = []() // comment\n"
@@ -25419,7 +25458,7 @@ TEST_F(FormatTest, AtomicQualifier) {
verifyFormat("struct foo {\n"
" int a1;\n"
" _Atomic(a) a2;\n"
- " _Atomic(_Atomic(int) *const) a3;\n"
+ " _Atomic(_Atomic(int)* const) a3;\n"
"};",
Google);
verifyFormat("_Atomic(uint64_t) a;");
@@ -27244,7 +27283,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"
@@ -27265,7 +27304,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);
}
@@ -28371,10 +28410,15 @@ TEST_F(FormatTest, BreakAfterAttributes) {
"Foo &operator-(Foo &);",
Style);
- Style.ReferenceAlignment = FormatStyle::ReferenceAlignmentStyle::RAS_Left;
+ Style.ReferenceAlignment = FormatStyle::RAS_Left;
verifyFormat("[[nodiscard]]\n"
"Foo& operator-(Foo&);",
Style);
+
+ Style.BreakBeforeBinaryOperators = FormatStyle::BOS_All;
+ verifyFormat("[[deprecated]]\n"
+ "void f() = delete;",
+ Style);
}
TEST_F(FormatTest, InsertNewlineAtEOF) {
@@ -28384,9 +28428,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
}
@@ -28395,7 +28439,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);
}
@@ -28628,8 +28672,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"
@@ -29040,9 +29084,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"
@@ -29064,9 +29108,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;
@@ -29076,10 +29120,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 0b7ac21..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"
@@ -689,8 +688,7 @@ TEST_F(FormatTestSelective, FormatMacroRegardlessOfPreviousIndent) {
" }};", // Ditto: Bug?
format(Code, 57, 0));
- Style.IndentPPDirectives =
- FormatStyle::PPDirectiveIndentStyle::PPDIS_BeforeHash;
+ Style.IndentPPDirectives = FormatStyle::PPDIS_BeforeHash;
EXPECT_EQ(" class Foo {\n"
" void test() {\n"
" #ifdef 1\n"
@@ -699,8 +697,7 @@ TEST_F(FormatTestSelective, FormatMacroRegardlessOfPreviousIndent) {
" }};",
format(Code, 57, 0));
- Style.IndentPPDirectives =
- FormatStyle::PPDirectiveIndentStyle::PPDIS_AfterHash;
+ Style.IndentPPDirectives = FormatStyle::PPDIS_AfterHash;
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;