diff options
author | Chih-Hung Hsieh <chh@google.com> | 2017-09-27 00:58:45 +0000 |
---|---|---|
committer | Chih-Hung Hsieh <chh@google.com> | 2017-09-27 00:58:45 +0000 |
commit | e3721258151fc526606cbbe649845e989e7c8443 (patch) | |
tree | 695f2a0fe66d0933a9bcdb3a27d72b7a2be1649c /unittests | |
parent | 2dab9ecc4a8eba7b83700673007d3ce340e015d7 (diff) |
[clang-format] Adjust space around &/&& of structured bindings
Keep space before or after the &/&& tokens, but not both. For example,
auto [x,y] = a;
auto &[xr, yr] = a; // LLVM style
auto& [xr, yr] = a; // google style
Differential Revision:https://reviews.llvm.org/D35743
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@314264 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'unittests')
-rw-r--r-- | unittests/Format/FormatTest.cpp | 53 |
1 files changed, 44 insertions, 9 deletions
diff --git a/unittests/Format/FormatTest.cpp b/unittests/Format/FormatTest.cpp index a1b0e5fee7..2b3d571da7 100644 --- a/unittests/Format/FormatTest.cpp +++ b/unittests/Format/FormatTest.cpp @@ -11579,24 +11579,59 @@ TEST_F(FormatTest, StructuredBindings) { EXPECT_EQ("auto const volatile [a, b] = f();", format("auto const volatile[a, b] = f();")); EXPECT_EQ("auto [a, b, c] = f();", format("auto [ a , b,c ] = f();")); - EXPECT_EQ("auto & [a, b, c] = f();", + EXPECT_EQ("auto &[a, b, c] = f();", format("auto &[ a , b,c ] = f();")); - EXPECT_EQ("auto && [a, b, c] = f();", + EXPECT_EQ("auto &&[a, b, c] = f();", format("auto &&[ a , b,c ] = f();")); - EXPECT_EQ("auto const & [a, b] = f();", format("auto const&[a, b] = f();")); - EXPECT_EQ("auto const volatile && [a, b] = f();", + EXPECT_EQ("auto const &[a, b] = f();", format("auto const&[a, b] = f();")); + EXPECT_EQ("auto const volatile &&[a, b] = f();", format("auto const volatile &&[a, b] = f();")); - EXPECT_EQ("auto && [a, b] = f();", format("auto &&[a, b] = f();")); + EXPECT_EQ("auto const &&[a, b] = f();", format("auto const && [a, b] = f();")); + EXPECT_EQ("const auto &[a, b] = f();", format("const auto & [a, b] = f();")); + EXPECT_EQ("const auto volatile &&[a, b] = f();", + format("const auto volatile &&[a, b] = f();")); + EXPECT_EQ("volatile const auto &&[a, b] = f();", + format("volatile const auto &&[a, b] = f();")); + EXPECT_EQ("const auto &&[a, b] = f();", format("const auto && [a, b] = f();")); // Make sure we don't mistake structured bindings for lambdas. - verifyFormat("auto [a, b]{A * i};"); - verifyFormat("auto const [a, b]{A * i};"); - verifyFormat("auto const && [a, b]{A * i};"); + FormatStyle PointerMiddle = getLLVMStyle(); + PointerMiddle.PointerAlignment = FormatStyle::PAS_Middle; + verifyFormat("auto [a1, b]{A * i};", getGoogleStyle()); + verifyFormat("auto [a2, b]{A * i};", getLLVMStyle()); + verifyFormat("auto [a3, b]{A * i};", PointerMiddle); + verifyFormat("auto const [a1, b]{A * i};", getGoogleStyle()); + verifyFormat("auto const [a2, b]{A * i};", getLLVMStyle()); + verifyFormat("auto const [a3, b]{A * i};", PointerMiddle); + verifyFormat("auto const& [a1, b]{A * i};", getGoogleStyle()); + verifyFormat("auto const &[a2, b]{A * i};", getLLVMStyle()); + verifyFormat("auto const & [a3, b]{A * i};", PointerMiddle); + verifyFormat("auto const&& [a1, b]{A * i};", getGoogleStyle()); + verifyFormat("auto const &&[a2, b]{A * i};", getLLVMStyle()); + verifyFormat("auto const && [a3, b]{A * i};", PointerMiddle); + + EXPECT_EQ("for (const auto &&[a, b] : some_range) {\n}", + format("for (const auto && [a, b] : some_range) {\n}")); + EXPECT_EQ("for (const auto &[a, b] : some_range) {\n}", + format("for (const auto & [a, b] : some_range) {\n}")); + EXPECT_EQ("for (const auto [a, b] : some_range) {\n}", + format("for (const auto[a, b] : some_range) {\n}")); + EXPECT_EQ("auto [x, y](expr);", format("auto[x,y] (expr);")); + EXPECT_EQ("auto &[x, y](expr);", format("auto & [x,y] (expr);")); + EXPECT_EQ("auto &&[x, y](expr);", format("auto && [x,y] (expr);")); + EXPECT_EQ("auto const &[x, y](expr);", format("auto const & [x,y] (expr);")); + EXPECT_EQ("auto const &&[x, y](expr);", format("auto const && [x,y] (expr);")); + EXPECT_EQ("auto [x, y]{expr};", format("auto[x,y] {expr};")); + EXPECT_EQ("auto const &[x, y]{expr};", format("auto const & [x,y] {expr};")); + EXPECT_EQ("auto const &&[x, y]{expr};", format("auto const && [x,y] {expr};")); format::FormatStyle Spaces = format::getLLVMStyle(); Spaces.SpacesInSquareBrackets = true; verifyFormat("auto [ a, b ] = f();", Spaces); - verifyFormat("auto && [ a, b ] = f();", Spaces); + verifyFormat("auto &&[ a, b ] = f();", Spaces); + verifyFormat("auto &[ a, b ] = f();", Spaces); + verifyFormat("auto const &&[ a, b ] = f();", Spaces); + verifyFormat("auto const &[ a, b ] = f();", Spaces); } } // end namespace |