// Basic function tests.
//===----------------------------------------------------------------------===//
-TEST_F(FormatTest, DoesNotChangeCorrectlyFormattedCode) {
- EXPECT_EQ(";", format(";"));
-}
+TEST_F(FormatTest, DoesNotChangeCorrectlyFormattedCode) { verifyFormat(";"); }
TEST_F(FormatTest, FormatsGlobalStatementsAt0) {
EXPECT_EQ("int i;", format(" int i;"));
}
TEST_F(FormatTest, LayoutUnknownPPDirective) {
- EXPECT_EQ("#;", format("#;"));
+ verifyFormat("#;");
verifyFormat("#\n;\n;\n;");
}
getLLVMStyleWithColumns(13)));
}
-TEST_F(FormatTest, LayoutSingleHash) { EXPECT_EQ("#\na;", format("#\na;")); }
+TEST_F(FormatTest, LayoutSingleHash) { verifyFormat("#\na;"); }
TEST_F(FormatTest, LayoutCodeInMacroDefinitions) {
EXPECT_EQ("#define A \\\n"
getLLVMStyleWithColumns(14)));
}
-TEST_F(FormatTest, LayoutRemainingTokens) { EXPECT_EQ("{}", format("{}")); }
+TEST_F(FormatTest, LayoutRemainingTokens) { verifyFormat("{}"); }
TEST_F(FormatTest, MacroDefinitionInsideStatement) {
EXPECT_EQ("int x,\n"
}
TEST_F(FormatTest, HashInMacroDefinition) {
- EXPECT_EQ("#define A(c) L#c", format("#define A(c) L#c", getLLVMStyle()));
- EXPECT_EQ("#define A(c) u#c", format("#define A(c) u#c", getLLVMStyle()));
- EXPECT_EQ("#define A(c) U#c", format("#define A(c) U#c", getLLVMStyle()));
- EXPECT_EQ("#define A(c) u8#c", format("#define A(c) u8#c", getLLVMStyle()));
- EXPECT_EQ("#define A(c) LR#c", format("#define A(c) LR#c", getLLVMStyle()));
- EXPECT_EQ("#define A(c) uR#c", format("#define A(c) uR#c", getLLVMStyle()));
- EXPECT_EQ("#define A(c) UR#c", format("#define A(c) UR#c", getLLVMStyle()));
- EXPECT_EQ("#define A(c) u8R#c", format("#define A(c) u8R#c", getLLVMStyle()));
+ verifyFormat("#define A(c) L#c", getLLVMStyle());
+ verifyFormat("#define A(c) u#c", getLLVMStyle());
+ verifyFormat("#define A(c) U#c", getLLVMStyle());
+ verifyFormat("#define A(c) u8#c", getLLVMStyle());
+ verifyFormat("#define A(c) LR#c", getLLVMStyle());
+ verifyFormat("#define A(c) uR#c", getLLVMStyle());
+ verifyFormat("#define A(c) UR#c", getLLVMStyle());
+ verifyFormat("#define A(c) u8R#c", getLLVMStyle());
verifyFormat("#define A \\\n b #c;", getLLVMStyleWithColumns(11));
verifyFormat("#define A \\\n"
" { \\\n"
}
TEST_F(FormatTest, RespectWhitespaceInMacroDefinitions) {
- EXPECT_EQ("#define A (x)", format("#define A (x)"));
- EXPECT_EQ("#define A(x)", format("#define A(x)"));
+ verifyFormat("#define A (x)");
+ verifyFormat("#define A(x)");
FormatStyle Style = getLLVMStyle();
Style.SpaceBeforeParens = FormatStyle::SBPO_Never;
"} // namespace"));
// Only if the identifier contains at least 5 characters.
EXPECT_EQ("HTTP f();", format("HTTP\nf();"));
- EXPECT_EQ("MACRO\nf();", format("MACRO\nf();"));
+ verifyNoChange("MACRO\nf();");
// Only if everything is upper case.
EXPECT_EQ("class A : public QObject {\n"
" Q_Object A() {}\n"
"# define C 0\n"
"#endif";
EXPECT_EQ(Expected, format(ToFormat, Style));
- EXPECT_EQ(Expected, format(Expected, Style));
+ verifyFormat(Expected, Style);
}
// Keep block quotes aligned.
{
"# define C 0\n"
"#endif";
EXPECT_EQ(Expected, format(ToFormat, Style));
- EXPECT_EQ(Expected, format(Expected, Style));
+ verifyNoChange(Expected, Style);
}
// Keep comments aligned with un-indented directives.
{
" // Code. Not aligned with #\n"
"#define C 0\n";
EXPECT_EQ(Expected, format(ToFormat, Style));
- EXPECT_EQ(Expected, format(Expected, Style));
+ verifyFormat(Expected, Style);
}
// Test AfterHash with tabs.
{
"#endif\n"
"}";
EXPECT_EQ(Expected, format(ToFormat, Style));
- EXPECT_EQ(Expected, format(Expected, Style));
+ verifyFormat(Expected, Style);
}
{
const char *Expected = "void f() {\n"
"#endif\n"
"}";
EXPECT_EQ(Expected, format(ToFormat, Style));
- EXPECT_EQ(Expected, format(Expected, Style));
+ verifyNoChange(Expected, Style);
}
// Test single comment before preprocessor
EXPECT_EQ("#define A\n\nint i;", format("#define A \\\n\n int i;"));
EXPECT_EQ("template <class T> f();", format("\\\ntemplate <class T> f();"));
EXPECT_EQ("/* \\ \\ \\\n */", format("\\\n/* \\ \\ \\\n */"));
- EXPECT_EQ("<a\n\\\\\n>", format("<a\n\\\\\n>"));
+ verifyNoChange("<a\n\\\\\n>");
FormatStyle AlignLeft = getLLVMStyle();
AlignLeft.AlignEscapedNewlines = FormatStyle::ENAS_Left;
EXPECT_EQ("#define A\r\n\r\nint i;", format("#define A \\\r\n\r\n int i;"));
EXPECT_EQ("template <class T> f();", format("\\\ntemplate <class T> f();"));
EXPECT_EQ("/* \\ \\ \\\r\n */", format("\\\r\n/* \\ \\ \\\r\n */"));
- EXPECT_EQ("<a\r\n\\\\\r\n>", format("<a\r\n\\\\\r\n>"));
+ verifyNoChange("<a\r\n\\\\\r\n>");
EXPECT_EQ("#define MACRO(x) \\\r\n"
"private: \\\r\n"
" int x(int a);\r\n",
}
TEST_F(FormatTest, PutEmptyBlocksIntoOneLine) {
- EXPECT_EQ("{}", format("{}"));
+ verifyFormat("{}");
verifyFormat("enum E {};");
verifyFormat("enum E {}");
FormatStyle Style = getLLVMStyle();
"private:\n"
" int j;\n"
"};\n",
- "struct foo { /* comment */\n"
- "private:\n"
- " int i;\n"
- " // comment\n"
- "\n"
- "private:\n"
- " int j;\n"
- "};\n",
Style);
verifyFormat("struct foo {\n"
"#ifdef FOO\n"
}
TEST_F(FormatTest, DoNotInterfereWithErrorAndWarning) {
- EXPECT_EQ("#error Leave all white!!!!! space* alone!\n",
- format("#error Leave all white!!!!! space* alone!\n"));
+ verifyNoChange("#error Leave all white!!!!! space* alone!\n");
EXPECT_EQ(
"#warning Leave all white!!!!! space* alone!\n",
format("#warning Leave all white!!!!! space* alone!\n"));
format("-(NSInteger)Method4:(id)anObject;"));
EXPECT_EQ("- (NSInteger)Method5:(id)anObject:(id)AnotherObject;",
format("-(NSInteger)Method5:(id)anObject:(id)AnotherObject;"));
- EXPECT_EQ("- (id)Method6:(id)A:(id)B:(id)C:(id)D;",
- format("- (id)Method6:(id)A:(id)B:(id)C:(id)D;"));
+ verifyFormat("- (id)Method6:(id)A:(id)B:(id)C:(id)D;");
EXPECT_EQ("- (void)sendAction:(SEL)aSelector to:(id)anObject "
"forAllCells:(BOOL)flag;",
format("- (void)sendAction:(SEL)aSelector to:(id)anObject "
" \"other\";",
format("#define A \"so text other\";", getLLVMStyleWithColumns(12)));
- EXPECT_EQ("\"some text\"",
- format("\"some text\"", getLLVMStyleWithColumns(1)));
- EXPECT_EQ("\"some text\"",
- format("\"some text\"", getLLVMStyleWithColumns(11)));
+ verifyFormat("\"some text\"", getLLVMStyleWithColumns(1));
+ verifyFormat("\"some text\"", getLLVMStyleWithColumns(11));
EXPECT_EQ("\"some \"\n"
"\"text\"",
format("\"some text\"", getLLVMStyleWithColumns(10)));
FormatStyle Style = getLLVMStyleWithColumns(12);
Style.BreakStringLiterals = false;
- EXPECT_EQ("\"some text other\";", format("\"some text other\";", Style));
+ verifyFormat("\"some text other\";", Style);
FormatStyle AlignLeft = getLLVMStyleWithColumns(12);
AlignLeft.AlignEscapedNewlines = FormatStyle::ENAS_Left;
TEST_F(FormatTest, DoesNotBreakRawStringLiterals) {
FormatStyle Style = getGoogleStyleWithColumns(15);
- EXPECT_EQ("R\"x(raw literal)x\";", format("R\"x(raw literal)x\";", Style));
- EXPECT_EQ("uR\"x(raw literal)x\";", format("uR\"x(raw literal)x\";", Style));
- EXPECT_EQ("LR\"x(raw literal)x\";", format("LR\"x(raw literal)x\";", Style));
- EXPECT_EQ("UR\"x(raw literal)x\";", format("UR\"x(raw literal)x\";", Style));
- EXPECT_EQ("u8R\"x(raw literal)x\";",
- format("u8R\"x(raw literal)x\";", Style));
+ verifyFormat("R\"x(raw literal)x\";", Style);
+ verifyFormat("uR\"x(raw literal)x\";", Style);
+ verifyFormat("LR\"x(raw literal)x\";", Style);
+ verifyFormat("UR\"x(raw literal)x\";", Style);
+ verifyFormat("u8R\"x(raw literal)x\";", Style);
}
TEST_F(FormatTest, BreaksStringLiteralsWithin_TMacro) {
}
TEST_F(FormatTest, DoNotBreakStringLiteralsInEscapeSequence) {
- EXPECT_EQ("\"\\a\"", format("\"\\a\"", getLLVMStyleWithColumns(3)));
- EXPECT_EQ("\"\\\"", format("\"\\\"", getLLVMStyleWithColumns(2)));
+ verifyFormat("\"\\a\"", getLLVMStyleWithColumns(3));
+ verifyFormat("\"\\\"", getLLVMStyleWithColumns(2));
EXPECT_EQ("\"test\"\n"
"\"\\n\"",
format("\"test\\n\"", getLLVMStyleWithColumns(7)));
EXPECT_EQ("\"\\\\\\\\\"\n"
"\"\\n\"",
format("\"\\\\\\\\\\n\"", getLLVMStyleWithColumns(7)));
- EXPECT_EQ("\"\\uff01\"", format("\"\\uff01\"", getLLVMStyleWithColumns(7)));
+ verifyFormat("\"\\uff01\"", getLLVMStyleWithColumns(7));
EXPECT_EQ("\"\\uff01\"\n"
"\"test\"",
format("\"\\uff01test\"", getLLVMStyleWithColumns(8)));
- EXPECT_EQ("\"\\Uff01ff02\"",
- format("\"\\Uff01ff02\"", getLLVMStyleWithColumns(11)));
+ verifyFormat("\"\\Uff01ff02\"", getLLVMStyleWithColumns(11));
EXPECT_EQ("\"\\x000000000001\"\n"
"\"next\"",
format("\"\\x000000000001next\"", getLLVMStyleWithColumns(16)));
- EXPECT_EQ("\"\\x000000000001next\"",
- format("\"\\x000000000001next\"", getLLVMStyleWithColumns(15)));
- EXPECT_EQ("\"\\x000000000001\"",
- format("\"\\x000000000001\"", getLLVMStyleWithColumns(7)));
+ verifyFormat("\"\\x000000000001next\"", getLLVMStyleWithColumns(15));
+ verifyFormat("\"\\x000000000001\"", getLLVMStyleWithColumns(7));
EXPECT_EQ("\"test\"\n"
"\"\\000000\"\n"
"\"000001\"",
}
TEST_F(FormatTest, HandlesUTF8BOM) {
- EXPECT_EQ("\xef\xbb\xbf", format("\xef\xbb\xbf"));
- EXPECT_EQ("\xef\xbb\xbf#include <iostream>",
- format("\xef\xbb\xbf#include <iostream>"));
- EXPECT_EQ("\xef\xbb\xbf\n#include <iostream>",
- format("\xef\xbb\xbf\n#include <iostream>"));
+ verifyFormat("\xef\xbb\xbf");
+ verifyFormat("\xef\xbb\xbf#include <iostream>");
+ verifyFormat("\xef\xbb\xbf\n#include <iostream>");
}
// FIXME: Encode Cyrillic and CJK characters below to appease MS compilers.
}
TEST_F(FormatTest, SplitsUTF8LineComments) {
- EXPECT_EQ("// aaaaÄ\xc2\x8d",
- format("// aaaaÄ\xc2\x8d", getLLVMStyleWithColumns(10)));
+ verifyFormat("// aaaaÄ\xc2\x8d", getLLVMStyleWithColumns(10));
EXPECT_EQ("// Я из лесу\n"
"// вышел; был\n"
"// сильный\n"
" return b;\n"
"};",
"auto c = []() { return b; };", MergeInline);
- verifyFormat("function([]() { return b; })", "function([]() { return b; })",
- MergeInline);
- verifyFormat("function([]() { return b; }, a)",
- "function([]() { return b; }, a)", MergeInline);
- verifyFormat("function(a, []() { return b; })",
- "function(a, []() { return b; })", MergeInline);
+ verifyFormat("function([]() { return b; })", MergeInline);
+ verifyFormat("function([]() { return b; }, a)", MergeInline);
+ verifyFormat("function(a, []() { return b; })", MergeInline);
// Check option "BraceWrapping.BeforeLambdaBody" and different state of
// AllowShortLambdasOnASingleLine
"#if C\n"
"#else\n"
"#endif\n";
- EXPECT_EQ(code, format(code));
+ verifyFormat(code);
}
TEST_F(FormatTest, HandleConflictMarkers) {
TEST_F(FormatTest, UTF8CharacterLiteralCpp11) {
// u8'a' is a C++17 feature, utf8 literal character, LS_Cpp11 covers
// all modes, including C++11, C++14 and C++17
- EXPECT_EQ("auto c = u8'a';", format("auto c = u8'a';"));
+ verifyFormat("auto c = u8'a';");
}
TEST_F(FormatTest, DoNotFormatLikelyXml) {
- EXPECT_EQ("<!-- ;> -->", format("<!-- ;> -->", getGoogleStyle()));
- EXPECT_EQ(" <!-- >; -->", format(" <!-- >; -->", getGoogleStyle()));
+ verifyFormat("<!-- ;> -->", getGoogleStyle());
+ verifyNoChange(" <!-- >; -->", getGoogleStyle());
}
TEST_F(FormatTest, StructuredBindings) {
// Don't use the helpers here, since 'mess up' will change the whitespace
// and these are all whitespace sensitive by definition
- EXPECT_EQ("FOO(String-ized&Messy+But(: :Still)=Intentional);",
- format("FOO(String-ized&Messy+But(: :Still)=Intentional);", Style));
+ verifyFormat("FOO(String-ized&Messy+But(: :Still)=Intentional);", Style);
EXPECT_EQ(
"FOO(String-ized&Messy+But\\(: :Still)=Intentional);",
format("FOO(String-ized&Messy+But\\(: :Still)=Intentional);", Style));
- EXPECT_EQ("FOO(String-ized&Messy+But,: :Still=Intentional);",
- format("FOO(String-ized&Messy+But,: :Still=Intentional);", Style));
+ verifyFormat("FOO(String-ized&Messy+But,: :Still=Intentional);", Style);
EXPECT_EQ("FOO(String-ized&Messy+But,: :\n"
" Still=Intentional);",
format("FOO(String-ized&Messy+But,: :\n"
Style));
Style.ColumnLimit = 21;
- EXPECT_EQ("FOO(String-ized&Messy+But: :Still=Intentional);",
- format("FOO(String-ized&Messy+But: :Still=Intentional);", Style));
+ verifyFormat("FOO(String-ized&Messy+But: :Still=Intentional);", Style);
}
TEST_F(FormatTest, VeryLongNamespaceCommentSplit) {
" Q_EMIT signal(MyChar);\n"
"}";
- EXPECT_EQ(Source, format(Source, Style));
+ verifyFormat(Source, Style);
Style.AlignConsecutiveDeclarations.Enabled = true;
EXPECT_EQ("void Foo::slot() {\n"
format(Source, Style));
Style.StatementAttributeLikeMacros.push_back("emit");
- EXPECT_EQ(Source, format(Source, Style));
+ verifyFormat(Source, Style);
Style.StatementAttributeLikeMacros = {};
EXPECT_EQ("void Foo::slot() {\n"
" // Small line comment\n"
" return String.size() > SmallString.size();\n"
"}";
- EXPECT_EQ(Code, format(Code, Style));
+ verifyNoChange(Code, Style);
}
TEST_F(FormatTest, FormatDecayCopy) {
Code, Style);
Style.BreakAfterAttributes = FormatStyle::ABS_Leave;
- EXPECT_EQ(Code, format(Code, Style));
+ verifyNoChange(Code, Style);
}
TEST_F(FormatTest, InsertNewlineAtEOF) {
Style.KeepEmptyLinesAtEOF = true;
const StringRef Code{"int i;\n\n"};
- verifyFormat(Code, Code, Style);
+ verifyNoChange(Code, Style);
verifyFormat(Code, "int i;\n\n\n", Style);
}
Style.QualifierOrder = {"friend", "inline", "constexpr", "static",
"const", "volatile", "type"};
- verifyFormat("const volatile int a;", "const volatile int a;", Style);
+ verifyFormat("const volatile int a;", Style);
verifyFormat("const volatile int a;", "volatile const int a;", Style);
verifyFormat("const volatile int a;", "int const volatile a;", Style);
verifyFormat("const volatile int a;", "int volatile const a;", Style);
verifyFormat("int const *a;", "const int *a;", Style);
verifyFormat("int const &a;", "const int &a;", Style);
verifyFormat("foo(int const &a)", "foo(const int &a)", Style);
- verifyFormat("unsigned char *a;", "unsigned char *a;", Style);
+ verifyFormat("unsigned char *a;", Style);
verifyFormat("unsigned char const *a;", "const unsigned char *a;", Style);
verifyFormat("vector<int, int const, int &, int const &> args1",
"vector<int, const int, int &, const int &> args1", Style);
Style);
verifyFormat("static int const bat;", "static const int bat;", Style);
- verifyFormat("static int const bat;", "static int const bat;", Style);
+ verifyFormat("static int const bat;", Style);
// static is not configured, unchanged on the left of the right hand
// qualifiers.
verifyFormat("Foo inline static const;", "const Foo inline static;", Style);
verifyFormat("Foo inline static const;", "Foo const inline static;", Style);
verifyFormat("Foo inline static const;", "Foo inline const static;", Style);
- verifyFormat("Foo inline static const;", "Foo inline static const;", Style);
+ verifyFormat("Foo inline static const;", Style);
verifyFormat("Foo<T volatile>::Bar<Type const, 5> const volatile A::*;",
"volatile const Foo<volatile T>::Bar<const Type, 5> A::*;",
verifyFormat("int const Foo<int>::bat = 0;", "const int Foo<int>::bat = 0;",
Style);
- verifyFormat("int const Foo<int>::bat = 0;", "int const Foo<int>::bat = 0;",
- Style);
+ verifyFormat("int const Foo<int>::bat = 0;", Style);
verifyFormat("void fn(Foo<T> const &i);", "void fn(const Foo<T> &i);", Style);
- verifyFormat("int const Foo<int>::fn() {", "int const Foo<int>::fn() {",
- Style);
+ verifyFormat("int const Foo<int>::fn() {", Style);
verifyFormat("Foo<Foo<int>> const *p;", "const Foo<Foo<int>> *p;", Style);
verifyFormat(
"Foo<Foo<int>> const *p = const_cast<Foo<Foo<int>> const *>(&ffi);",
Style);
// Don't move past C-style struct/class.
- verifyFormat("void foo(const struct A a);", "void foo(const struct A a);",
- Style);
- verifyFormat("void foo(const class A a);", "void foo(const class A a);",
- Style);
+ verifyFormat("void foo(const struct A a);", Style);
+ verifyFormat("void foo(const class A a);", Style);
// Don't move past struct/class combined declaration and variable
// definition.
- verifyFormat("const struct {\n} var;", "const struct {\n} var;", Style);
- verifyFormat("struct {\n} const var;", "struct {\n} const var;", Style);
- verifyFormat("const class {\n} var;", "const class {\n} var;", Style);
- verifyFormat("class {\n} const var;", "class {\n} const var;", Style);
+ verifyFormat("const struct {\n} var;", Style);
+ verifyFormat("struct {\n} const var;", Style);
+ verifyFormat("const class {\n} var;", Style);
+ verifyFormat("class {\n} const var;", Style);
// Leave left qualifers unchanged for combined declaration and variable
// definition.
- verifyFormat("volatile const class {\n} var;",
- "volatile const class {\n} var;", Style);
- verifyFormat("const volatile class {\n} var;",
- "const volatile class {\n} var;", Style);
+ verifyFormat("volatile const class {\n} var;", Style);
+ verifyFormat("const volatile class {\n} var;", Style);
// Also do no sorting with respect to not-configured tokens.
- verifyFormat("const static volatile class {\n} var;",
- "const static volatile class {\n} var;", Style);
+ verifyFormat("const static volatile class {\n} var;", Style);
// Sort right qualifiers for combined declaration and variable definition.
- verifyFormat("class {\n} const volatile var;",
- "class {\n} const volatile var;", Style);
+ verifyFormat("class {\n} const volatile var;", Style);
verifyFormat("class {\n} const volatile var;",
"class {\n} volatile const var;", Style);
// Static keyword is not configured, should end up on the left of the right
// side.
- verifyFormat("class {\n} static const volatile var;",
- "class {\n} static const volatile var;", Style);
+ verifyFormat("class {\n} static const volatile var;", Style);
verifyFormat("class {\n} static const volatile var;",
"class {\n} volatile static const var;", Style);
Style);
// Don't move past decltype, typeof, or _Atomic.
- verifyFormat("const decltype(foo)", "const decltype(foo)", Style);
- verifyFormat("const typeof(foo)", "const typeof(foo)", Style);
- verifyFormat("const _Atomic(foo)", "const _Atomic(foo)", Style);
+ verifyFormat("const decltype(foo)", Style);
+ verifyFormat("const typeof(foo)", Style);
+ verifyFormat("const _Atomic(foo)", Style);
// Comments
const int ColumnLimit = Style.ColumnLimit;
"const unsigned /*c*/ long /*c*/ long a;", Style);
// Not changed
- verifyFormat("foo() /*c*/ const", "foo() /*c*/ const", Style);
- verifyFormat("const /*c*/ struct a;", "const /*c*/ struct a;", Style);
- verifyFormat("const /*c*/ class a;", "const /*c*/ class a;", Style);
- verifyFormat("const /*c*/ decltype(v) a;", "const /*c*/ decltype(v) a;",
- Style);
- verifyFormat("const /*c*/ typeof(v) a;", "const /*c*/ typeof(v) a;", Style);
- verifyFormat("const /*c*/ _Atomic(v) a;", "const /*c*/ _Atomic(v) a;", Style);
- verifyFormat("const decltype /*c*/ (v) a;", "const decltype /*c*/ (v) a;",
- Style);
- verifyFormat("const /*c*/ class {\n} volatile /*c*/ foo = {};",
- "const /*c*/ class {\n} volatile /*c*/ foo = {};", Style);
+ verifyFormat("foo() /*c*/ const", Style);
+ verifyFormat("const /*c*/ struct a;", Style);
+ verifyFormat("const /*c*/ class a;", Style);
+ verifyFormat("const /*c*/ decltype(v) a;", Style);
+ verifyFormat("const /*c*/ typeof(v) a;", Style);
+ verifyFormat("const /*c*/ _Atomic(v) a;", Style);
+ verifyFormat("const decltype /*c*/ (v) a;", Style);
+ verifyFormat("const /*c*/ class {\n} volatile /*c*/ foo = {};", Style);
Style.ColumnLimit = ColumnLimit;
// Don't adjust macros
- verifyFormat("const INTPTR a;", "const INTPTR a;", Style);
+ verifyFormat("const INTPTR a;", Style);
// Pointers to members
verifyFormat("int S::*a;", Style);
verifyFormat("const int *a;", "int const *a;", Style);
verifyFormat("const int &a;", "int const &a;", Style);
verifyFormat("foo(const int &a)", "foo(int const &a)", Style);
- verifyFormat("unsigned char *a;", "unsigned char *a;", Style);
+ verifyFormat("unsigned char *a;", Style);
verifyFormat("const unsigned int &get_nu() const",
"unsigned int const &get_nu() const", Style);
verifyFormat("const volatile int;", "volatile const int;", Style);
- verifyFormat("const volatile int;", "const volatile int;", Style);
+ verifyFormat("const volatile int;", Style);
verifyFormat("const volatile int;", "const int volatile;", Style);
verifyFormat("const volatile int *restrict;", "volatile const int *restrict;",
Style);
- verifyFormat("const volatile int *restrict;", "const volatile int *restrict;",
- Style);
+ verifyFormat("const volatile int *restrict;", Style);
verifyFormat("const volatile int *restrict;", "const int volatile *restrict;",
Style);
"template <typename Func> explicit Action(Action<Func> const &action);",
Style);
- verifyFormat("static const int bat;", "static const int bat;", Style);
+ verifyFormat("static const int bat;", Style);
verifyFormat("static const int bat;", "static int const bat;", Style);
- verifyFormat("static const int Foo<int>::bat = 0;",
- "static const int Foo<int>::bat = 0;", Style);
+ verifyFormat("static const int Foo<int>::bat = 0;", Style);
verifyFormat("static const int Foo<int>::bat = 0;",
"static int const Foo<int>::bat = 0;", Style);
verifyFormat("void fn(const Foo<T> &i);");
- verifyFormat("const int Foo<int>::bat = 0;", "const int Foo<int>::bat = 0;",
- Style);
+ verifyFormat("const int Foo<int>::bat = 0;", Style);
verifyFormat("const int Foo<int>::bat = 0;", "int const Foo<int>::bat = 0;",
Style);
verifyFormat("void fn(const Foo<T> &i);", "void fn( Foo<T> const &i);",
verifyFormat("const long long unsigned a;", "long const long unsigned a;",
Style);
- verifyFormat("const std::Foo", "const std::Foo", Style);
- verifyFormat("const std::Foo<>", "const std::Foo<>", Style);
+ verifyFormat("const std::Foo", Style);
+ verifyFormat("const std::Foo<>", Style);
verifyFormat("const std::Foo < int", "const std::Foo<int", Style);
- verifyFormat("const std::Foo<int>", "const std::Foo<int>", Style);
+ verifyFormat("const std::Foo<int>", Style);
// Multiple template parameters.
verifyFormat("Bar<const std::Foo, 32>;", "Bar<std::Foo const, 32>;", Style);
Style);
// Don't move past C-style struct/class.
- verifyFormat("void foo(struct A const a);", "void foo(struct A const a);",
- Style);
- verifyFormat("void foo(class A const a);", "void foo(class A const a);",
- Style);
+ verifyFormat("void foo(struct A const a);", Style);
+ verifyFormat("void foo(class A const a);", Style);
// Don't move past struct/class combined declaration and variable
// definition.
- verifyFormat("const struct {\n} var;", "const struct {\n} var;", Style);
- verifyFormat("struct {\n} const var;", "struct {\n} const var;", Style);
- verifyFormat("const class {\n} var;", "const class {\n} var;", Style);
- verifyFormat("class {\n} const var;", "class {\n} const var;", Style);
+ verifyFormat("const struct {\n} var;", Style);
+ verifyFormat("struct {\n} const var;", Style);
+ verifyFormat("const class {\n} var;", Style);
+ verifyFormat("class {\n} const var;", Style);
// Sort left qualifiers for struct/class combined declaration and variable
// definition.
- verifyFormat("const volatile class {\n} var;",
- "const volatile class {\n} var;", Style);
+ verifyFormat("const volatile class {\n} var;", Style);
verifyFormat("const volatile class {\n} var;",
"volatile const class {\n} var;", Style);
// Leave right qualifers unchanged for struct/class combined declaration and
// variable definition.
- verifyFormat("class {\n} const volatile var;",
- "class {\n} const volatile var;", Style);
- verifyFormat("class {\n} volatile const var;",
- "class {\n} volatile const var;", Style);
+ verifyFormat("class {\n} const volatile var;", Style);
+ verifyFormat("class {\n} volatile const var;", Style);
verifyFormat("foo<const Bar<Baz<T>>>();", "foo<Bar<Baz<T>> const>();", Style);
verifyFormat("foo<const Bar<Baz<T>>>();", "foo<Bar<Baz<T> > const>();",
Style);
// Don't move past decltype, typeof, or _Atomic.
- verifyFormat("decltype(foo) const", "decltype(foo) const", Style);
- verifyFormat("typeof(foo) const", "typeof(foo) const", Style);
- verifyFormat("_Atomic(foo) const", "_Atomic(foo) const", Style);
+ verifyFormat("decltype(foo) const", Style);
+ verifyFormat("typeof(foo) const", Style);
+ verifyFormat("_Atomic(foo) const", Style);
// ::template for dependent names
verifyFormat("const volatile ::template Foo<T> var;",
"unsigned /*c*/ long /*c*/ long const a;", Style);
// Not changed
- verifyFormat("foo() /*c*/ const", "foo() /*c*/ const", Style);
- verifyFormat("struct /*c*/ const a;", "struct /*c*/ const a;", Style);
- verifyFormat("class /*c*/ const a;", "class /*c*/ const a;", Style);
- verifyFormat("decltype(v) /*c*/ const a;", "decltype(v) /*c*/ const a;",
- Style);
- verifyFormat("typeof(v) /*c*/ const a;", "typeof(v) /*c*/ const a;", Style);
- verifyFormat("_Atomic(v) /*c*/ const a;", "_Atomic(v) /*c*/ const a;", Style);
- verifyFormat("decltype /*c*/ (v) const a;", "decltype /*c*/ (v) const a;",
- Style);
- verifyFormat("const /*c*/ class {\n} /*c*/ volatile /*c*/ foo = {};",
- "const /*c*/ class {\n} /*c*/ volatile /*c*/ foo = {};", Style);
+ verifyFormat("foo() /*c*/ const", Style);
+ verifyFormat("struct /*c*/ const a;", Style);
+ verifyFormat("class /*c*/ const a;", Style);
+ verifyFormat("decltype(v) /*c*/ const a;", Style);
+ verifyFormat("typeof(v) /*c*/ const a;", Style);
+ verifyFormat("_Atomic(v) /*c*/ const a;", Style);
+ verifyFormat("decltype /*c*/ (v) const a;", Style);
+ verifyFormat("const /*c*/ class {\n} /*c*/ volatile /*c*/ foo = {};", Style);
Style.ColumnLimit = ColumnLimit;
// Don't adjust macros
- verifyFormat("INTPTR const a;", "INTPTR const a;", Style);
+ verifyFormat("INTPTR const a;", Style);
// Pointers to members
verifyFormat("int S::*a;", Style);
// The Default
EXPECT_EQ(Style.QualifierOrder.size(), (size_t)5);
- verifyFormat("const volatile int a;", "const volatile int a;", Style);
+ verifyFormat("const volatile int a;", Style);
verifyFormat("const volatile int a;", "volatile const int a;", Style);
verifyFormat("const volatile int a;", "int const volatile a;", Style);
verifyFormat("const volatile int a;", "int volatile const a;", Style);
verifyFormat("const volatile int a;", "const int volatile a;", Style);
- verifyFormat("const volatile Foo a;", "const volatile Foo a;", Style);
+ verifyFormat("const volatile Foo a;", Style);
verifyFormat("const volatile Foo a;", "volatile const Foo a;", Style);
verifyFormat("const volatile Foo a;", "Foo const volatile a;", Style);
verifyFormat("const volatile Foo a;", "Foo volatile const a;", Style);
verifyFormat("int const volatile a;", "const volatile int a;", Style);
verifyFormat("int const volatile a;", "volatile const int a;", Style);
- verifyFormat("int const volatile a;", "int const volatile a;", Style);
+ verifyFormat("int const volatile a;", Style);
verifyFormat("int const volatile a;", "int volatile const a;", Style);
verifyFormat("int const volatile a;", "const int volatile a;", Style);
verifyFormat("Foo const volatile a;", "const volatile Foo a;", Style);
verifyFormat("Foo const volatile a;", "volatile const Foo a;", Style);
- verifyFormat("Foo const volatile a;", "Foo const volatile a;", Style);
+ verifyFormat("Foo const volatile a;", Style);
verifyFormat("Foo const volatile a;", "Foo volatile const a;", Style);
verifyFormat("Foo const volatile a;", "const Foo volatile a;", Style);
Style.QualifierOrder = {"volatile", "const", "type"};
verifyFormat("volatile const int a;", "const volatile int a;", Style);
- verifyFormat("volatile const int a;", "volatile const int a;", Style);
+ verifyFormat("volatile const int a;", Style);
verifyFormat("volatile const int a;", "int const volatile a;", Style);
verifyFormat("volatile const int a;", "int volatile const a;", Style);
verifyFormat("volatile const int a;", "const int volatile a;", Style);
verifyFormat("volatile const Foo a;", "const volatile Foo a;", Style);
- verifyFormat("volatile const Foo a;", "volatile const Foo a;", Style);
+ verifyFormat("volatile const Foo a;", Style);
verifyFormat("volatile const Foo a;", "Foo const volatile a;", Style);
verifyFormat("volatile const Foo a;", "Foo volatile const a;", Style);
verifyFormat("volatile const Foo a;", "const Foo volatile a;", Style);
verifyFormat("int volatile const a;", "const volatile int a;", Style);
verifyFormat("int volatile const a;", "volatile const int a;", Style);
verifyFormat("int volatile const a;", "int const volatile a;", Style);
- verifyFormat("int volatile const a;", "int volatile const a;", Style);
+ verifyFormat("int volatile const a;", Style);
verifyFormat("int volatile const a;", "const int volatile a;", Style);
verifyFormat("Foo volatile const a;", "const volatile Foo a;", Style);
verifyFormat("Foo volatile const a;", "volatile const Foo a;", Style);
verifyFormat("Foo volatile const a;", "Foo const volatile a;", Style);
- verifyFormat("Foo volatile const a;", "Foo volatile const a;", Style);
+ verifyFormat("Foo volatile const a;", Style);
verifyFormat("Foo volatile const a;", "const Foo volatile a;", Style);
Style.QualifierAlignment = FormatStyle::QAS_Custom;
verifyFormat("int volatile const a;", "const volatile int a;", Style);
verifyFormat("int volatile const a;", "volatile const int a;", Style);
verifyFormat("int volatile const a;", "int const volatile a;", Style);
- verifyFormat("int volatile const a;", "int volatile const a;", Style);
+ verifyFormat("int volatile const a;", Style);
verifyFormat("int volatile const a;", "const int volatile a;", Style);
verifyFormat("Foo volatile const a;", "const volatile Foo a;", Style);
verifyFormat("Foo volatile const a;", "volatile const Foo a;", Style);
verifyFormat("Foo volatile const a;", "Foo const volatile a;", Style);
- verifyFormat("Foo volatile const a;", "Foo volatile const a;", Style);
+ verifyFormat("Foo volatile const a;", Style);
verifyFormat("Foo volatile const a;", "const Foo volatile a;", Style);
}
Style.QualifierOrder = {"static", "const", "type"};
verifyFormat("inline static const int a;", Style);
- verifyFormat("static inline const int a;", "static inline const int a;",
- Style);
+ verifyFormat("static inline const int a;", Style);
verifyFormat("static const int a;", "const static int a;", Style);
Style);
verifyFormat("inline static const Foo;", "inline static Foo const;", Style);
- verifyFormat("inline static const Foo;", "inline static const Foo;", Style);
+ verifyFormat("inline static const Foo;", Style);
// Don't move qualifiers to the right for aestethics only.
- verifyFormat("inline const static Foo;", "inline const static Foo;", Style);
- verifyFormat("const inline static Foo;", "const inline static Foo;", Style);
+ verifyFormat("inline const static Foo;", Style);
+ verifyFormat("const inline static Foo;", Style);
}
TEST_F(QualifierFixerTest, UnsignedQualifier) {