/// brackets.
BracketAlignmentStyle AlignAfterOpenBracket;
- /// Styles for alignment of consecutive tokens. Tokens can be assignment signs
- /// (see
- /// ``AlignConsecutiveAssignments``), bitfield member separators (see
- /// ``AlignConsecutiveBitFields``), names in declarations (see
- /// ``AlignConsecutiveDeclarations``) or macro definitions (see
- /// ``AlignConsecutiveMacros``).
- enum AlignConsecutiveStyle {
- ACS_None,
- ACS_Consecutive,
- ACS_AcrossEmptyLines,
- ACS_AcrossComments,
- ACS_AcrossEmptyLinesAndComments
- };
-
- /// Style of aligning consecutive macro definitions.
+ /// \brief If ``true``, aligns consecutive C/C++ preprocessor macros.
///
- /// ``Consecutive`` will result in formattings like:
+ /// This will align C/C++ preprocessor macros of consecutive lines.
+ /// Will result in formattings like
/// \code
/// #define SHORT_NAME 42
/// #define LONGER_NAME 0x007f
/// #define foo(x) (x * x)
/// #define bar(y, z) (y + z)
/// \endcode
+ bool AlignConsecutiveMacros;
+
+ /// If ``true``, aligns consecutive assignments.
///
- /// Possible values:
- ///
- /// * ``ACS_None`` (in configuration: ``None``)
- /// Do not align macro definitions on consecutive lines.
- ///
- /// * ``ACS_Consecutive`` (in configuration: ``Consecutive``)
- /// Align macro definitions on consecutive lines. This will result in
- /// formattings like:
- /// \code
- /// #define SHORT_NAME 42
- /// #define LONGER_NAME 0x007f
- /// #define EVEN_LONGER_NAME (2)
- ///
- /// #define foo(x) (x * x)
- /// /* some comment */
- /// #define bar(y, z) (y + z)
- /// \endcode
- ///
- /// * ``ACS_AcrossEmptyLines`` (in configuration: ``AcrossEmptyLines``)
- /// Same as ACS_Consecutive, but also spans over empty lines, e.g.
- /// \code
- /// #define SHORT_NAME 42
- /// #define LONGER_NAME 0x007f
- /// #define EVEN_LONGER_NAME (2)
- ///
- /// #define foo(x) (x * x)
- /// /* some comment */
- /// #define bar(y, z) (y + z)
- /// \endcode
- ///
- /// * ``ACS_AcrossComments`` (in configuration: ``AcrossComments``)
- /// Same as ACS_Consecutive, but also spans over lines only containing
- /// comments, e.g.
- /// \code
- /// #define SHORT_NAME 42
- /// #define LONGER_NAME 0x007f
- /// #define EVEN_LONGER_NAME (2)
- ///
- /// #define foo(x) (x * x)
- /// /* some comment */
- /// #define bar(y, z) (y + z)
- /// \endcode
- ///
- /// * ``ACS_AcrossEmptyLinesAndComments``
- /// (in configuration: ``AcrossEmptyLinesAndComments``)
- ///
- /// Same as ACS_Consecutive, but also spans over lines only containing
- /// comments and empty lines, e.g.
- /// \code
- /// #define SHORT_NAME 42
- /// #define LONGER_NAME 0x007f
- /// #define EVEN_LONGER_NAME (2)
- ///
- /// #define foo(x) (x * x)
- /// /* some comment */
- /// #define bar(y, z) (y + z)
- /// \endcode
- AlignConsecutiveStyle AlignConsecutiveMacros;
-
- /// Style of aligning consecutive assignments.
- ///
- /// ``Consecutive`` will result in formattings like:
- /// \code
- /// int a = 1;
- /// int somelongname = 2;
- /// double c = 3;
- /// \endcode
- ///
- /// Possible values:
- ///
- /// * ``ACS_None`` (in configuration: ``None``)
- /// Do not align assignments on consecutive lines.
- ///
- /// * ``ACS_Consecutive`` (in configuration: ``Consecutive``)
- /// Align assignments on consecutive lines. This will result in
- /// formattings like:
- /// \code
- /// int a = 1;
- /// int somelongname = 2;
- /// double c = 3;
- ///
- /// int d = 3;
- /// /* A comment. */
- /// double e = 4;
- /// \endcode
- ///
- /// * ``ACS_AcrossEmptyLines`` (in configuration: ``AcrossEmptyLines``)
- /// Same as ACS_Consecutive, but also spans over empty lines, e.g.
- /// \code
- /// int a = 1;
- /// int somelongname = 2;
- /// double c = 3;
- ///
- /// int d = 3;
- /// /* A comment. */
- /// double e = 4;
- /// \endcode
- ///
- /// * ``ACS_AcrossComments`` (in configuration: ``AcrossComments``)
- /// Same as ACS_Consecutive, but also spans over lines only containing
- /// comments, e.g.
- /// \code
- /// int a = 1;
- /// int somelongname = 2;
- /// double c = 3;
- ///
- /// int d = 3;
- /// /* A comment. */
- /// double e = 4;
- /// \endcode
- ///
- /// * ``ACS_AcrossEmptyLinesAndComments``
- /// (in configuration: ``AcrossEmptyLinesAndComments``)
- ///
- /// Same as ACS_Consecutive, but also spans over lines only containing
- /// comments and empty lines, e.g.
- /// \code
- /// int a = 1;
- /// int somelongname = 2;
- /// double c = 3;
- ///
- /// int d = 3;
- /// /* A comment. */
- /// double e = 4;
- /// \endcode
- AlignConsecutiveStyle AlignConsecutiveAssignments;
-
- /// Style of aligning consecutive bit field.
- ///
- /// ``Consecutive`` will align the bitfield separators of consecutive lines.
- /// This will result in formattings like:
+ /// This will align the assignment operators of consecutive lines. This
+ /// will result in formattings like
+ /// \code
+ /// int aaaa = 12;
+ /// int b = 23;
+ /// int ccc = 23;
+ /// \endcode
+ bool AlignConsecutiveAssignments;
+
+ /// If ``true``, aligns consecutive bitfield members.
+ ///
+ /// This will align the bitfield separators of consecutive lines. This
+ /// will result in formattings like
/// \code
/// int aaaa : 1;
/// int b : 12;
/// int ccc : 8;
/// \endcode
+ bool AlignConsecutiveBitFields;
+
+ /// If ``true``, aligns consecutive declarations.
///
- /// Possible values:
- ///
- /// * ``ACS_None`` (in configuration: ``None``)
- /// Do not align bit fields on consecutive lines.
- ///
- /// * ``ACS_Consecutive`` (in configuration: ``Consecutive``)
- /// Align bit fields on consecutive lines. This will result in
- /// formattings like:
- /// \code
- /// int aaaa : 1;
- /// int b : 12;
- /// int ccc : 8;
- ///
- /// int d : 2;
- /// /* A comment. */
- /// int ee : 3;
- /// \endcode
- ///
- /// * ``ACS_AcrossEmptyLines`` (in configuration: ``AcrossEmptyLines``)
- /// Same as ACS_Consecutive, but also spans over empty lines, e.g.
- /// \code
- /// int aaaa : 1;
- /// int b : 12;
- /// int ccc : 8;
- ///
- /// int d : 2;
- /// /* A comment. */
- /// int ee : 3;
- /// \endcode
- ///
- /// * ``ACS_AcrossComments`` (in configuration: ``AcrossComments``)
- /// Same as ACS_Consecutive, but also spans over lines only containing
- /// comments, e.g.
- /// \code
- /// int aaaa : 1;
- /// int b : 12;
- /// int ccc : 8;
- ///
- /// int d : 2;
- /// /* A comment. */
- /// int ee : 3;
- /// \endcode
- ///
- /// * ``ACS_AcrossEmptyLinesAndComments``
- /// (in configuration: ``AcrossEmptyLinesAndComments``)
- ///
- /// Same as ACS_Consecutive, but also spans over lines only containing
- /// comments and empty lines, e.g.
- /// \code
- /// int aaaa : 1;
- /// int b : 12;
- /// int ccc : 8;
- ///
- /// int d : 2;
- /// /* A comment. */
- /// int ee : 3;
- /// \endcode
- AlignConsecutiveStyle AlignConsecutiveBitFields;
-
- /// Style of aligning consecutive declarations.
- ///
- /// ``Consecutive`` will align the declaration names of consecutive lines.
- /// This will result in formattings like:
+ /// This will align the declaration names of consecutive lines. This
+ /// will result in formattings like
/// \code
/// int aaaa = 12;
/// float b = 23;
- /// std::string ccc;
- /// \endcode
- ///
- /// Possible values:
- ///
- /// * ``ACS_None`` (in configuration: ``None``)
- /// Do not align bit declarations on consecutive lines.
- ///
- /// * ``ACS_Consecutive`` (in configuration: ``Consecutive``)
- /// Align declarations on consecutive lines. This will result in
- /// formattings like:
- /// \code
- /// int aaaa = 12;
- /// float b = 23;
- /// std::string ccc;
- ///
- /// int a = 42;
- /// /* A comment. */
- /// bool c = false;
- /// \endcode
- ///
- /// * ``ACS_AcrossEmptyLines`` (in configuration: ``AcrossEmptyLines``)
- /// Same as ACS_Consecutive, but also spans over empty lines, e.g.
- /// \code
- /// int aaaa = 12;
- /// float b = 23;
- /// std::string ccc;
- ///
- /// int a = 42;
- /// /* A comment. */
- /// bool c = false;
- /// \endcode
- ///
- /// * ``ACS_AcrossComments`` (in configuration: ``AcrossComments``)
- /// Same as ACS_Consecutive, but also spans over lines only containing
- /// comments, e.g.
- /// \code
- /// int aaaa = 12;
- /// float b = 23;
- /// std::string ccc;
- ///
- /// int a = 42;
- /// /* A comment. */
- /// bool c = false;
- /// \endcode
- ///
- /// * ``ACS_AcrossEmptyLinesAndComments``
- /// (in configuration: ``AcrossEmptyLinesAndComments``)
- ///
- /// Same as ACS_Consecutive, but also spans over lines only containing
- /// comments and empty lines, e.g.
- /// \code
- /// int aaaa = 12;
- /// float b = 23;
- /// std::string ccc;
- ///
- /// int a = 42;
- /// /* A comment. */
- /// bool c = false;
- /// \endcode
- AlignConsecutiveStyle AlignConsecutiveDeclarations;
+ /// std::string ccc = 23;
+ /// \endcode
+ bool AlignConsecutiveDeclarations;
/// Different styles for aligning escaped newlines.
enum EscapedNewlineAlignmentStyle : unsigned char {
AlignConsecutiveAssignments == R.AlignConsecutiveAssignments &&
AlignConsecutiveBitFields == R.AlignConsecutiveBitFields &&
AlignConsecutiveDeclarations == R.AlignConsecutiveDeclarations &&
- AlignConsecutiveMacros == R.AlignConsecutiveMacros &&
AlignEscapedNewlines == R.AlignEscapedNewlines &&
AlignOperands == R.AlignOperands &&
AlignTrailingComments == R.AlignTrailingComments &&
"*/\n"
"}",
Tab));
- Tab.AlignConsecutiveAssignments = FormatStyle::ACS_Consecutive;
- Tab.AlignConsecutiveDeclarations = FormatStyle::ACS_Consecutive;
+ Tab.AlignConsecutiveAssignments = true;
+ Tab.AlignConsecutiveDeclarations = true;
Tab.TabWidth = 4;
Tab.IndentWidth = 4;
verifyFormat("class Assign {\n"
"*/\n"
"}",
Tab));
- Tab.AlignConsecutiveAssignments = FormatStyle::ACS_Consecutive;
- Tab.AlignConsecutiveDeclarations = FormatStyle::ACS_Consecutive;
+ Tab.AlignConsecutiveAssignments = true;
+ Tab.AlignConsecutiveDeclarations = true;
Tab.TabWidth = 4;
Tab.IndentWidth = 4;
verifyFormat("class Assign {\n"
TEST_F(FormatTest, AlignConsecutiveMacros) {
FormatStyle Style = getLLVMStyle();
- Style.AlignConsecutiveAssignments = FormatStyle::ACS_Consecutive;
- Style.AlignConsecutiveDeclarations = FormatStyle::ACS_Consecutive;
- Style.AlignConsecutiveMacros = FormatStyle::ACS_None;
+ Style.AlignConsecutiveAssignments = true;
+ Style.AlignConsecutiveDeclarations = true;
+ Style.AlignConsecutiveMacros = false;
verifyFormat("#define a 3\n"
"#define bbbb 4\n"
"#define ffff(x, y) (x - y)",
Style);
- Style.AlignConsecutiveMacros = FormatStyle::ACS_Consecutive;
+ Style.AlignConsecutiveMacros = true;
verifyFormat("#define a 3\n"
"#define bbbb 4\n"
"#define ccc (5)",
"};",
Style);
- Style.AlignConsecutiveMacros = FormatStyle::ACS_None;
+ Style.AlignConsecutiveMacros = false;
Style.ColumnLimit = 20;
verifyFormat("#define a \\\n"
" \"LLLLLLLL\"\n",
Style);
- Style.AlignConsecutiveMacros = FormatStyle::ACS_Consecutive;
+ Style.AlignConsecutiveMacros = true;
verifyFormat("#define a \\\n"
" \"aabbbbbbbbbbbb\"\n"
"#define D \\\n"
" \"FFFFFFFFFFFFF\" \\\n"
" \"LLLLLLLL\"\n",
Style);
-
- // Test across comments
- Style.MaxEmptyLinesToKeep = 10;
- Style.ReflowComments = false;
- Style.AlignConsecutiveMacros = FormatStyle::ACS_AcrossComments;
- EXPECT_EQ("#define a 3\n"
- "// line comment\n"
- "#define bbbb 4\n"
- "#define ccc (5)",
- format("#define a 3\n"
- "// line comment\n"
- "#define bbbb 4\n"
- "#define ccc (5)",
- Style));
-
- EXPECT_EQ("#define a 3\n"
- "/* block comment */\n"
- "#define bbbb 4\n"
- "#define ccc (5)",
- format("#define a 3\n"
- "/* block comment */\n"
- "#define bbbb 4\n"
- "#define ccc (5)",
- Style));
-
- EXPECT_EQ("#define a 3\n"
- "/* multi-line *\n"
- " * block comment */\n"
- "#define bbbb 4\n"
- "#define ccc (5)",
- format("#define a 3\n"
- "/* multi-line *\n"
- " * block comment */\n"
- "#define bbbb 4\n"
- "#define ccc (5)",
- Style));
-
- EXPECT_EQ("#define a 3\n"
- "// multi-line line comment\n"
- "//\n"
- "#define bbbb 4\n"
- "#define ccc (5)",
- format("#define a 3\n"
- "// multi-line line comment\n"
- "//\n"
- "#define bbbb 4\n"
- "#define ccc (5)",
- Style));
-
- EXPECT_EQ("#define a 3\n"
- "// empty lines still break.\n"
- "\n"
- "#define bbbb 4\n"
- "#define ccc (5)",
- format("#define a 3\n"
- "// empty lines still break.\n"
- "\n"
- "#define bbbb 4\n"
- "#define ccc (5)",
- Style));
-
- // Test across empty lines
- Style.AlignConsecutiveMacros = FormatStyle::ACS_AcrossEmptyLines;
- EXPECT_EQ("#define a 3\n"
- "\n"
- "#define bbbb 4\n"
- "#define ccc (5)",
- format("#define a 3\n"
- "\n"
- "#define bbbb 4\n"
- "#define ccc (5)",
- Style));
-
- EXPECT_EQ("#define a 3\n"
- "\n"
- "\n"
- "\n"
- "#define bbbb 4\n"
- "#define ccc (5)",
- format("#define a 3\n"
- "\n"
- "\n"
- "\n"
- "#define bbbb 4\n"
- "#define ccc (5)",
- Style));
-
- EXPECT_EQ("#define a 3\n"
- "// comments should break alignment\n"
- "//\n"
- "#define bbbb 4\n"
- "#define ccc (5)",
- format("#define a 3\n"
- "// comments should break alignment\n"
- "//\n"
- "#define bbbb 4\n"
- "#define ccc (5)",
- Style));
-
- // Test across empty lines and comments
- Style.AlignConsecutiveMacros = FormatStyle::ACS_AcrossEmptyLinesAndComments;
- verifyFormat("#define a 3\n"
- "\n"
- "// line comment\n"
- "#define bbbb 4\n"
- "#define ccc (5)",
- Style);
-
- EXPECT_EQ("#define a 3\n"
- "\n"
- "\n"
- "/* multi-line *\n"
- " * block comment */\n"
- "\n"
- "\n"
- "#define bbbb 4\n"
- "#define ccc (5)",
- format("#define a 3\n"
- "\n"
- "\n"
- "/* multi-line *\n"
- " * block comment */\n"
- "\n"
- "\n"
- "#define bbbb 4\n"
- "#define ccc (5)",
- Style));
-
- EXPECT_EQ("#define a 3\n"
- "\n"
- "\n"
- "/* multi-line *\n"
- " * block comment */\n"
- "\n"
- "\n"
- "#define bbbb 4\n"
- "#define ccc (5)",
- format("#define a 3\n"
- "\n"
- "\n"
- "/* multi-line *\n"
- " * block comment */\n"
- "\n"
- "\n"
- "#define bbbb 4\n"
- "#define ccc (5)",
- Style));
-}
-
-TEST_F(FormatTest, AlignConsecutiveAssignmentsAcrossEmptyLines) {
- FormatStyle Alignment = getLLVMStyle();
- Alignment.AlignConsecutiveMacros = FormatStyle::ACS_Consecutive;
- Alignment.AlignConsecutiveAssignments = FormatStyle::ACS_AcrossEmptyLines;
-
- Alignment.MaxEmptyLinesToKeep = 10;
- /* Test alignment across empty lines */
- EXPECT_EQ("int a = 5;\n"
- "\n"
- "int oneTwoThree = 123;",
- format("int a = 5;\n"
- "\n"
- "int oneTwoThree= 123;",
- Alignment));
- EXPECT_EQ("int a = 5;\n"
- "int one = 1;\n"
- "\n"
- "int oneTwoThree = 123;",
- format("int a = 5;\n"
- "int one = 1;\n"
- "\n"
- "int oneTwoThree = 123;",
- Alignment));
- EXPECT_EQ("int a = 5;\n"
- "int one = 1;\n"
- "\n"
- "int oneTwoThree = 123;\n"
- "int oneTwo = 12;",
- format("int a = 5;\n"
- "int one = 1;\n"
- "\n"
- "int oneTwoThree = 123;\n"
- "int oneTwo = 12;",
- Alignment));
-
- /* Test across comments */
- EXPECT_EQ("int a = 5;\n"
- "/* block comment */\n"
- "int oneTwoThree = 123;",
- format("int a = 5;\n"
- "/* block comment */\n"
- "int oneTwoThree=123;",
- Alignment));
-
- EXPECT_EQ("int a = 5;\n"
- "// line comment\n"
- "int oneTwoThree = 123;",
- format("int a = 5;\n"
- "// line comment\n"
- "int oneTwoThree=123;",
- Alignment));
-
- /* Test across comments and newlines */
- EXPECT_EQ("int a = 5;\n"
- "\n"
- "/* block comment */\n"
- "int oneTwoThree = 123;",
- format("int a = 5;\n"
- "\n"
- "/* block comment */\n"
- "int oneTwoThree=123;",
- Alignment));
-
- EXPECT_EQ("int a = 5;\n"
- "\n"
- "// line comment\n"
- "int oneTwoThree = 123;",
- format("int a = 5;\n"
- "\n"
- "// line comment\n"
- "int oneTwoThree=123;",
- Alignment));
-}
-
-TEST_F(FormatTest, AlignConsecutiveDeclarationsAcrossEmptyLinesAndComments) {
- FormatStyle Alignment = getLLVMStyle();
- Alignment.AlignConsecutiveDeclarations =
- FormatStyle::ACS_AcrossEmptyLinesAndComments;
- Alignment.AlignConsecutiveAssignments = FormatStyle::ACS_None;
-
- Alignment.MaxEmptyLinesToKeep = 10;
- /* Test alignment across empty lines */
- EXPECT_EQ("int a = 5;\n"
- "\n"
- "float const oneTwoThree = 123;",
- format("int a = 5;\n"
- "\n"
- "float const oneTwoThree = 123;",
- Alignment));
- EXPECT_EQ("int a = 5;\n"
- "float const one = 1;\n"
- "\n"
- "int oneTwoThree = 123;",
- format("int a = 5;\n"
- "float const one = 1;\n"
- "\n"
- "int oneTwoThree = 123;",
- Alignment));
-
- /* Test across comments */
- EXPECT_EQ("float const a = 5;\n"
- "/* block comment */\n"
- "int oneTwoThree = 123;",
- format("float const a = 5;\n"
- "/* block comment */\n"
- "int oneTwoThree=123;",
- Alignment));
-
- EXPECT_EQ("float const a = 5;\n"
- "// line comment\n"
- "int oneTwoThree = 123;",
- format("float const a = 5;\n"
- "// line comment\n"
- "int oneTwoThree=123;",
- Alignment));
-
- /* Test across comments and newlines */
- EXPECT_EQ("float const a = 5;\n"
- "\n"
- "/* block comment */\n"
- "int oneTwoThree = 123;",
- format("float const a = 5;\n"
- "\n"
- "/* block comment */\n"
- "int oneTwoThree=123;",
- Alignment));
-
- EXPECT_EQ("float const a = 5;\n"
- "\n"
- "// line comment\n"
- "int oneTwoThree = 123;",
- format("float const a = 5;\n"
- "\n"
- "// line comment\n"
- "int oneTwoThree=123;",
- Alignment));
-}
-
-TEST_F(FormatTest, AlignConsecutiveBitFieldsAcrossEmptyLinesAndComments) {
- FormatStyle Alignment = getLLVMStyle();
- Alignment.AlignConsecutiveBitFields =
- FormatStyle::ACS_AcrossEmptyLinesAndComments;
-
- Alignment.MaxEmptyLinesToKeep = 10;
- /* Test alignment across empty lines */
- EXPECT_EQ("int a : 5;\n"
- "\n"
- "int longbitfield : 6;",
- format("int a : 5;\n"
- "\n"
- "int longbitfield : 6;",
- Alignment));
- EXPECT_EQ("int a : 5;\n"
- "int one : 1;\n"
- "\n"
- "int longbitfield : 6;",
- format("int a : 5;\n"
- "int one : 1;\n"
- "\n"
- "int longbitfield : 6;",
- Alignment));
-
- /* Test across comments */
- EXPECT_EQ("int a : 5;\n"
- "/* block comment */\n"
- "int longbitfield : 6;",
- format("int a : 5;\n"
- "/* block comment */\n"
- "int longbitfield : 6;",
- Alignment));
- EXPECT_EQ("int a : 5;\n"
- "int one : 1;\n"
- "// line comment\n"
- "int longbitfield : 6;",
- format("int a : 5;\n"
- "int one : 1;\n"
- "// line comment\n"
- "int longbitfield : 6;",
- Alignment));
-
- /* Test across comments and newlines */
- EXPECT_EQ("int a : 5;\n"
- "/* block comment */\n"
- "\n"
- "int longbitfield : 6;",
- format("int a : 5;\n"
- "/* block comment */\n"
- "\n"
- "int longbitfield : 6;",
- Alignment));
- EXPECT_EQ("int a : 5;\n"
- "int one : 1;\n"
- "\n"
- "// line comment\n"
- "\n"
- "int longbitfield : 6;",
- format("int a : 5;\n"
- "int one : 1;\n"
- "\n"
- "// line comment \n"
- "\n"
- "int longbitfield : 6;",
- Alignment));
-}
-
-TEST_F(FormatTest, AlignConsecutiveAssignmentsAcrossComments) {
- FormatStyle Alignment = getLLVMStyle();
- Alignment.AlignConsecutiveMacros = FormatStyle::ACS_Consecutive;
- Alignment.AlignConsecutiveAssignments = FormatStyle::ACS_AcrossComments;
-
- Alignment.MaxEmptyLinesToKeep = 10;
- /* Test alignment across empty lines */
- EXPECT_EQ("int a = 5;\n"
- "\n"
- "int oneTwoThree = 123;",
- format("int a = 5;\n"
- "\n"
- "int oneTwoThree= 123;",
- Alignment));
- EXPECT_EQ("int a = 5;\n"
- "int one = 1;\n"
- "\n"
- "int oneTwoThree = 123;",
- format("int a = 5;\n"
- "int one = 1;\n"
- "\n"
- "int oneTwoThree = 123;",
- Alignment));
-
- /* Test across comments */
- EXPECT_EQ("int a = 5;\n"
- "/* block comment */\n"
- "int oneTwoThree = 123;",
- format("int a = 5;\n"
- "/* block comment */\n"
- "int oneTwoThree=123;",
- Alignment));
-
- EXPECT_EQ("int a = 5;\n"
- "// line comment\n"
- "int oneTwoThree = 123;",
- format("int a = 5;\n"
- "// line comment\n"
- "int oneTwoThree=123;",
- Alignment));
-
- EXPECT_EQ("int a = 5;\n"
- "/*\n"
- " * multi-line block comment\n"
- " */\n"
- "int oneTwoThree = 123;",
- format("int a = 5;\n"
- "/*\n"
- " * multi-line block comment\n"
- " */\n"
- "int oneTwoThree=123;",
- Alignment));
-
- EXPECT_EQ("int a = 5;\n"
- "//\n"
- "// multi-line line comment\n"
- "//\n"
- "int oneTwoThree = 123;",
- format("int a = 5;\n"
- "//\n"
- "// multi-line line comment\n"
- "//\n"
- "int oneTwoThree=123;",
- Alignment));
-
- /* Test across comments and newlines */
- EXPECT_EQ("int a = 5;\n"
- "\n"
- "/* block comment */\n"
- "int oneTwoThree = 123;",
- format("int a = 5;\n"
- "\n"
- "/* block comment */\n"
- "int oneTwoThree=123;",
- Alignment));
-
- EXPECT_EQ("int a = 5;\n"
- "\n"
- "// line comment\n"
- "int oneTwoThree = 123;",
- format("int a = 5;\n"
- "\n"
- "// line comment\n"
- "int oneTwoThree=123;",
- Alignment));
-}
-
-TEST_F(FormatTest, AlignConsecutiveAssignmentsAcrossEmptyLinesAndComments) {
- FormatStyle Alignment = getLLVMStyle();
- Alignment.AlignConsecutiveMacros = FormatStyle::ACS_Consecutive;
- Alignment.AlignConsecutiveAssignments =
- FormatStyle::ACS_AcrossEmptyLinesAndComments;
- verifyFormat("int a = 5;\n"
- "int oneTwoThree = 123;",
- Alignment);
- verifyFormat("int a = method();\n"
- "int oneTwoThree = 133;",
- Alignment);
- verifyFormat("a &= 5;\n"
- "bcd *= 5;\n"
- "ghtyf += 5;\n"
- "dvfvdb -= 5;\n"
- "a /= 5;\n"
- "vdsvsv %= 5;\n"
- "sfdbddfbdfbb ^= 5;\n"
- "dvsdsv |= 5;\n"
- "int dsvvdvsdvvv = 123;",
- Alignment);
- verifyFormat("int i = 1, j = 10;\n"
- "something = 2000;",
- Alignment);
- verifyFormat("something = 2000;\n"
- "int i = 1, j = 10;\n",
- Alignment);
- verifyFormat("something = 2000;\n"
- "another = 911;\n"
- "int i = 1, j = 10;\n"
- "oneMore = 1;\n"
- "i = 2;",
- Alignment);
- verifyFormat("int a = 5;\n"
- "int one = 1;\n"
- "method();\n"
- "int oneTwoThree = 123;\n"
- "int oneTwo = 12;",
- Alignment);
- verifyFormat("int oneTwoThree = 123;\n"
- "int oneTwo = 12;\n"
- "method();\n",
- Alignment);
- verifyFormat("int oneTwoThree = 123; // comment\n"
- "int oneTwo = 12; // comment",
- Alignment);
-
- // Bug 25167
- /* Uncomment when fixed
- verifyFormat("#if A\n"
- "#else\n"
- "int aaaaaaaa = 12;\n"
- "#endif\n"
- "#if B\n"
- "#else\n"
- "int a = 12;\n"
- "#endif\n",
- Alignment);
- verifyFormat("enum foo {\n"
- "#if A\n"
- "#else\n"
- " aaaaaaaa = 12;\n"
- "#endif\n"
- "#if B\n"
- "#else\n"
- " a = 12;\n"
- "#endif\n"
- "};\n",
- Alignment);
- */
-
- Alignment.MaxEmptyLinesToKeep = 10;
- /* Test alignment across empty lines */
- EXPECT_EQ("int a = 5;\n"
- "\n"
- "int oneTwoThree = 123;",
- format("int a = 5;\n"
- "\n"
- "int oneTwoThree= 123;",
- Alignment));
- EXPECT_EQ("int a = 5;\n"
- "int one = 1;\n"
- "\n"
- "int oneTwoThree = 123;",
- format("int a = 5;\n"
- "int one = 1;\n"
- "\n"
- "int oneTwoThree = 123;",
- Alignment));
- EXPECT_EQ("int a = 5;\n"
- "int one = 1;\n"
- "\n"
- "int oneTwoThree = 123;\n"
- "int oneTwo = 12;",
- format("int a = 5;\n"
- "int one = 1;\n"
- "\n"
- "int oneTwoThree = 123;\n"
- "int oneTwo = 12;",
- Alignment));
-
- /* Test across comments */
- EXPECT_EQ("int a = 5;\n"
- "/* block comment */\n"
- "int oneTwoThree = 123;",
- format("int a = 5;\n"
- "/* block comment */\n"
- "int oneTwoThree=123;",
- Alignment));
-
- EXPECT_EQ("int a = 5;\n"
- "// line comment\n"
- "int oneTwoThree = 123;",
- format("int a = 5;\n"
- "// line comment\n"
- "int oneTwoThree=123;",
- Alignment));
-
- /* Test across comments and newlines */
- EXPECT_EQ("int a = 5;\n"
- "\n"
- "/* block comment */\n"
- "int oneTwoThree = 123;",
- format("int a = 5;\n"
- "\n"
- "/* block comment */\n"
- "int oneTwoThree=123;",
- Alignment));
-
- EXPECT_EQ("int a = 5;\n"
- "\n"
- "// line comment\n"
- "int oneTwoThree = 123;",
- format("int a = 5;\n"
- "\n"
- "// line comment\n"
- "int oneTwoThree=123;",
- Alignment));
-
- EXPECT_EQ("int a = 5;\n"
- "//\n"
- "// multi-line line comment\n"
- "//\n"
- "int oneTwoThree = 123;",
- format("int a = 5;\n"
- "//\n"
- "// multi-line line comment\n"
- "//\n"
- "int oneTwoThree=123;",
- Alignment));
-
- EXPECT_EQ("int a = 5;\n"
- "/*\n"
- " * multi-line block comment\n"
- " */\n"
- "int oneTwoThree = 123;",
- format("int a = 5;\n"
- "/*\n"
- " * multi-line block comment\n"
- " */\n"
- "int oneTwoThree=123;",
- Alignment));
-
- EXPECT_EQ("int a = 5;\n"
- "\n"
- "/* block comment */\n"
- "\n"
- "\n"
- "\n"
- "int oneTwoThree = 123;",
- format("int a = 5;\n"
- "\n"
- "/* block comment */\n"
- "\n"
- "\n"
- "\n"
- "int oneTwoThree=123;",
- Alignment));
-
- EXPECT_EQ("int a = 5;\n"
- "\n"
- "// line comment\n"
- "\n"
- "\n"
- "\n"
- "int oneTwoThree = 123;",
- format("int a = 5;\n"
- "\n"
- "// line comment\n"
- "\n"
- "\n"
- "\n"
- "int oneTwoThree=123;",
- Alignment));
-
- Alignment.AlignEscapedNewlines = FormatStyle::ENAS_DontAlign;
- verifyFormat("#define A \\\n"
- " int aaaa = 12; \\\n"
- " int b = 23; \\\n"
- " int ccc = 234; \\\n"
- " int dddddddddd = 2345;",
- Alignment);
- Alignment.AlignEscapedNewlines = FormatStyle::ENAS_Left;
- verifyFormat("#define A \\\n"
- " int aaaa = 12; \\\n"
- " int b = 23; \\\n"
- " int ccc = 234; \\\n"
- " int dddddddddd = 2345;",
- Alignment);
- Alignment.AlignEscapedNewlines = FormatStyle::ENAS_Right;
- verifyFormat("#define A "
- " \\\n"
- " int aaaa = 12; "
- " \\\n"
- " int b = 23; "
- " \\\n"
- " int ccc = 234; "
- " \\\n"
- " int dddddddddd = 2345;",
- Alignment);
- verifyFormat("void SomeFunction(int parameter = 1, int i = 2, int j = 3, int "
- "k = 4, int l = 5,\n"
- " int m = 6) {\n"
- " int j = 10;\n"
- " otherThing = 1;\n"
- "}",
- Alignment);
- verifyFormat("void SomeFunction(int parameter = 0) {\n"
- " int i = 1;\n"
- " int j = 2;\n"
- " int big = 10000;\n"
- "}",
- Alignment);
- verifyFormat("class C {\n"
- "public:\n"
- " int i = 1;\n"
- " virtual void f() = 0;\n"
- "};",
- Alignment);
- verifyFormat("int i = 1;\n"
- "if (SomeType t = getSomething()) {\n"
- "}\n"
- "int j = 2;\n"
- "int big = 10000;",
- Alignment);
- verifyFormat("int j = 7;\n"
- "for (int k = 0; k < N; ++k) {\n"
- "}\n"
- "int j = 2;\n"
- "int big = 10000;\n"
- "}",
- Alignment);
- Alignment.BreakBeforeBinaryOperators = FormatStyle::BOS_All;
- verifyFormat("int i = 1;\n"
- "LooooooooooongType loooooooooooooooooooooongVariable\n"
- " = someLooooooooooooooooongFunction();\n"
- "int j = 2;",
- Alignment);
- Alignment.BreakBeforeBinaryOperators = FormatStyle::BOS_None;
- verifyFormat("int i = 1;\n"
- "LooooooooooongType loooooooooooooooooooooongVariable =\n"
- " someLooooooooooooooooongFunction();\n"
- "int j = 2;",
- Alignment);
-
- verifyFormat("auto lambda = []() {\n"
- " auto i = 0;\n"
- " return 0;\n"
- "};\n"
- "int i = 0;\n"
- "auto v = type{\n"
- " i = 1, //\n"
- " (i = 2), //\n"
- " i = 3 //\n"
- "};",
- Alignment);
-
- verifyFormat(
- "int i = 1;\n"
- "SomeType a = SomeFunction(looooooooooooooooooooooongParameterA,\n"
- " loooooooooooooooooooooongParameterB);\n"
- "int j = 2;",
- Alignment);
-
- verifyFormat("template <typename T, typename T_0 = very_long_type_name_0,\n"
- " typename B = very_long_type_name_1,\n"
- " typename T_2 = very_long_type_name_2>\n"
- "auto foo() {}\n",
- Alignment);
- verifyFormat("int a, b = 1;\n"
- "int c = 2;\n"
- "int dd = 3;\n",
- Alignment);
- verifyFormat("int aa = ((1 > 2) ? 3 : 4);\n"
- "float b[1][] = {{3.f}};\n",
- Alignment);
- verifyFormat("for (int i = 0; i < 1; i++)\n"
- " int x = 1;\n",
- Alignment);
- verifyFormat("for (i = 0; i < 1; i++)\n"
- " x = 1;\n"
- "y = 1;\n",
- Alignment);
-
- Alignment.ReflowComments = true;
- Alignment.ColumnLimit = 50;
- EXPECT_EQ("int x = 0;\n"
- "int yy = 1; /// specificlennospace\n"
- "int zzz = 2;\n",
- format("int x = 0;\n"
- "int yy = 1; ///specificlennospace\n"
- "int zzz = 2;\n",
- Alignment));
}
TEST_F(FormatTest, AlignConsecutiveAssignments) {
FormatStyle Alignment = getLLVMStyle();
- Alignment.AlignConsecutiveMacros = FormatStyle::ACS_Consecutive;
- Alignment.AlignConsecutiveAssignments = FormatStyle::ACS_None;
+ Alignment.AlignConsecutiveMacros = true;
+ Alignment.AlignConsecutiveAssignments = false;
verifyFormat("int a = 5;\n"
"int oneTwoThree = 123;",
Alignment);
"int oneTwoThree = 123;",
Alignment);
- Alignment.AlignConsecutiveAssignments = FormatStyle::ACS_Consecutive;
+ Alignment.AlignConsecutiveAssignments = true;
verifyFormat("int a = 5;\n"
"int oneTwoThree = 123;",
Alignment);
TEST_F(FormatTest, AlignConsecutiveBitFields) {
FormatStyle Alignment = getLLVMStyle();
- Alignment.AlignConsecutiveBitFields = FormatStyle::ACS_Consecutive;
+ Alignment.AlignConsecutiveBitFields = true;
verifyFormat("int const a : 5;\n"
"int oneTwoThree : 23;",
Alignment);
"int oneTwoThree : 23 = 0;",
Alignment);
- Alignment.AlignConsecutiveDeclarations = FormatStyle::ACS_Consecutive;
+ Alignment.AlignConsecutiveDeclarations = true;
verifyFormat("int const a : 5;\n"
"int oneTwoThree : 23;",
Alignment);
"int oneTwoThree : 23 = 0;",
Alignment);
- Alignment.AlignConsecutiveAssignments = FormatStyle::ACS_Consecutive;
+ Alignment.AlignConsecutiveAssignments = true;
verifyFormat("int const a : 5 = 1;\n"
"int oneTwoThree : 23 = 0;",
Alignment);
TEST_F(FormatTest, AlignConsecutiveDeclarations) {
FormatStyle Alignment = getLLVMStyle();
- Alignment.AlignConsecutiveMacros = FormatStyle::ACS_Consecutive;
- Alignment.AlignConsecutiveDeclarations = FormatStyle::ACS_None;
+ Alignment.AlignConsecutiveMacros = true;
+ Alignment.AlignConsecutiveDeclarations = false;
verifyFormat("float const a = 5;\n"
"int oneTwoThree = 123;",
Alignment);
"float const oneTwoThree = 123;",
Alignment);
- Alignment.AlignConsecutiveDeclarations = FormatStyle::ACS_Consecutive;
+ Alignment.AlignConsecutiveDeclarations = true;
verifyFormat("float const a = 5;\n"
"int oneTwoThree = 123;",
Alignment);
verifyFormat("int a(int x, void (*fp)(int y));\n"
"double b();",
Alignment);
- Alignment.AlignConsecutiveAssignments = FormatStyle::ACS_Consecutive;
+ Alignment.AlignConsecutiveAssignments = true;
// Ensure recursive alignment is broken by function braces, so that the
// "a = 1" does not align with subsequent assignments inside the function
// body.
"int ll=10000;\n"
"}",
Alignment));
- Alignment.AlignConsecutiveAssignments = FormatStyle::ACS_None;
+ Alignment.AlignConsecutiveAssignments = false;
Alignment.AlignEscapedNewlines = FormatStyle::ENAS_DontAlign;
verifyFormat("#define A \\\n"
" int aaaa = 12; \\\n"
"int j = 2;",
Alignment);
- Alignment.AlignConsecutiveAssignments = FormatStyle::ACS_Consecutive;
+ Alignment.AlignConsecutiveAssignments = true;
verifyFormat("auto lambda = []() {\n"
" auto ii = 0;\n"
" float j = 0;\n"
" i = 3 //\n"
"};",
Alignment);
- Alignment.AlignConsecutiveAssignments = FormatStyle::ACS_None;
+ Alignment.AlignConsecutiveAssignments = false;
verifyFormat(
"int i = 1;\n"
// We expect declarations and assignments to align, as long as it doesn't
// exceed the column limit, starting a new alignment sequence whenever it
// happens.
- Alignment.AlignConsecutiveAssignments = FormatStyle::ACS_Consecutive;
+ Alignment.AlignConsecutiveAssignments = true;
Alignment.ColumnLimit = 30;
verifyFormat("float ii = 1;\n"
"unsigned j = 2;\n"
"int myvar = 1;",
Alignment);
Alignment.ColumnLimit = 80;
- Alignment.AlignConsecutiveAssignments = FormatStyle::ACS_None;
+ Alignment.AlignConsecutiveAssignments = false;
verifyFormat(
"template <typename LongTemplate, typename VeryLongTemplateTypeName,\n"
verifyFormat("int aa = ((1 > 2) ? 3 : 4);\n"
"float b[1][] = {{3.f}};\n",
Alignment);
- Alignment.AlignConsecutiveAssignments = FormatStyle::ACS_Consecutive;
+ Alignment.AlignConsecutiveAssignments = true;
verifyFormat("float a, b = 1;\n"
"int c = 2;\n"
"int dd = 3;\n",
verifyFormat("int aa = ((1 > 2) ? 3 : 4);\n"
"float b[1][] = {{3.f}};\n",
Alignment);
- Alignment.AlignConsecutiveAssignments = FormatStyle::ACS_None;
+ Alignment.AlignConsecutiveAssignments = false;
Alignment.ColumnLimit = 30;
Alignment.BinPackParameters = false;
Alignment.PointerAlignment = FormatStyle::PAS_Right;
// See llvm.org/PR35641
- Alignment.AlignConsecutiveDeclarations = FormatStyle::ACS_Consecutive;
+ Alignment.AlignConsecutiveDeclarations = true;
verifyFormat("int func() { //\n"
" int b;\n"
" unsigned c;\n"
// See PR37175
FormatStyle Style = getMozillaStyle();
- Style.AlignConsecutiveDeclarations = FormatStyle::ACS_Consecutive;
+ Style.AlignConsecutiveDeclarations = true;
EXPECT_EQ("DECOR1 /**/ int8_t /**/ DECOR2 /**/\n"
"foo(int a);",
format("DECOR1 /**/ int8_t /**/ DECOR2 /**/ foo (int a);", Style));
FormatStyle Style = {};
Style.Language = FormatStyle::LK_Cpp;
CHECK_PARSE_BOOL(AlignTrailingComments);
+ CHECK_PARSE_BOOL(AlignConsecutiveAssignments);
+ CHECK_PARSE_BOOL(AlignConsecutiveBitFields);
+ CHECK_PARSE_BOOL(AlignConsecutiveDeclarations);
+ CHECK_PARSE_BOOL(AlignConsecutiveMacros);
CHECK_PARSE_BOOL(AllowAllArgumentsOnNextLine);
CHECK_PARSE_BOOL(AllowAllConstructorInitializersOnNextLine);
CHECK_PARSE_BOOL(AllowAllParametersOfDeclarationOnNextLine);
CHECK_PARSE("ContinuationIndentWidth: 11", ContinuationIndentWidth, 11u);
CHECK_PARSE("CommentPragmas: '// abc$'", CommentPragmas, "// abc$");
- Style.AlignConsecutiveAssignments = FormatStyle::ACS_Consecutive;
- CHECK_PARSE("AlignConsecutiveAssignments: None", AlignConsecutiveAssignments,
- FormatStyle::ACS_None);
- CHECK_PARSE("AlignConsecutiveAssignments: Consecutive",
- AlignConsecutiveAssignments, FormatStyle::ACS_Consecutive);
- CHECK_PARSE("AlignConsecutiveAssignments: AcrossEmptyLines",
- AlignConsecutiveAssignments, FormatStyle::ACS_AcrossEmptyLines);
- CHECK_PARSE("AlignConsecutiveAssignments: AcrossEmptyLinesAndComments",
- AlignConsecutiveAssignments,
- FormatStyle::ACS_AcrossEmptyLinesAndComments);
- // For backwards compability, false / true should still parse
- CHECK_PARSE("AlignConsecutiveAssignments: false", AlignConsecutiveAssignments,
- FormatStyle::ACS_None);
- CHECK_PARSE("AlignConsecutiveAssignments: true", AlignConsecutiveAssignments,
- FormatStyle::ACS_Consecutive);
-
- Style.AlignConsecutiveBitFields = FormatStyle::ACS_Consecutive;
- CHECK_PARSE("AlignConsecutiveBitFields: None", AlignConsecutiveBitFields,
- FormatStyle::ACS_None);
- CHECK_PARSE("AlignConsecutiveBitFields: Consecutive",
- AlignConsecutiveBitFields, FormatStyle::ACS_Consecutive);
- CHECK_PARSE("AlignConsecutiveBitFields: AcrossEmptyLines",
- AlignConsecutiveBitFields, FormatStyle::ACS_AcrossEmptyLines);
- CHECK_PARSE("AlignConsecutiveBitFields: AcrossEmptyLinesAndComments",
- AlignConsecutiveBitFields,
- FormatStyle::ACS_AcrossEmptyLinesAndComments);
- // For backwards compability, false / true should still parse
- CHECK_PARSE("AlignConsecutiveBitFields: false", AlignConsecutiveBitFields,
- FormatStyle::ACS_None);
- CHECK_PARSE("AlignConsecutiveBitFields: true", AlignConsecutiveBitFields,
- FormatStyle::ACS_Consecutive);
-
- Style.AlignConsecutiveMacros = FormatStyle::ACS_Consecutive;
- CHECK_PARSE("AlignConsecutiveMacros: None", AlignConsecutiveMacros,
- FormatStyle::ACS_None);
- CHECK_PARSE("AlignConsecutiveMacros: Consecutive", AlignConsecutiveMacros,
- FormatStyle::ACS_Consecutive);
- CHECK_PARSE("AlignConsecutiveMacros: AcrossEmptyLines",
- AlignConsecutiveMacros, FormatStyle::ACS_AcrossEmptyLines);
- CHECK_PARSE("AlignConsecutiveMacros: AcrossEmptyLinesAndComments",
- AlignConsecutiveMacros,
- FormatStyle::ACS_AcrossEmptyLinesAndComments);
- // For backwards compability, false / true should still parse
- CHECK_PARSE("AlignConsecutiveMacros: false", AlignConsecutiveMacros,
- FormatStyle::ACS_None);
- CHECK_PARSE("AlignConsecutiveMacros: true", AlignConsecutiveMacros,
- FormatStyle::ACS_Consecutive);
-
- Style.AlignConsecutiveDeclarations = FormatStyle::ACS_Consecutive;
- CHECK_PARSE("AlignConsecutiveDeclarations: None",
- AlignConsecutiveDeclarations, FormatStyle::ACS_None);
- CHECK_PARSE("AlignConsecutiveDeclarations: Consecutive",
- AlignConsecutiveDeclarations, FormatStyle::ACS_Consecutive);
- CHECK_PARSE("AlignConsecutiveDeclarations: AcrossEmptyLines",
- AlignConsecutiveDeclarations, FormatStyle::ACS_AcrossEmptyLines);
- CHECK_PARSE("AlignConsecutiveDeclarations: AcrossEmptyLinesAndComments",
- AlignConsecutiveDeclarations,
- FormatStyle::ACS_AcrossEmptyLinesAndComments);
- // For backwards compability, false / true should still parse
- CHECK_PARSE("AlignConsecutiveDeclarations: false",
- AlignConsecutiveDeclarations, FormatStyle::ACS_None);
- CHECK_PARSE("AlignConsecutiveDeclarations: true",
- AlignConsecutiveDeclarations, FormatStyle::ACS_Consecutive);
-
Style.PointerAlignment = FormatStyle::PAS_Middle;
CHECK_PARSE("PointerAlignment: Left", PointerAlignment,
FormatStyle::PAS_Left);
format("FOO(String-ized&Messy+But,: :\n"
" Still=Intentional);",
Style));
- Style.AlignConsecutiveAssignments = FormatStyle::ACS_Consecutive;
+ Style.AlignConsecutiveAssignments = true;
EXPECT_EQ("FOO(String-ized=&Messy+But,: :\n"
" Still=Intentional);",
format("FOO(String-ized=&Messy+But,: :\n"
EXPECT_EQ(Source, format(Source, Style));
- Style.AlignConsecutiveDeclarations = FormatStyle::ACS_Consecutive;
+ Style.AlignConsecutiveDeclarations = true;
EXPECT_EQ("void Foo::slot() {\n"
" unsigned char MyChar = 'x';\n"
" emit signal(MyChar);\n"