This revision was landed with ongoing or failed builds. This revision was automatically updated to reflect the committed changes. Closed by commit rGebed0ca71561: [clang-format] C# switch expression formatting differs from normal switch… (authored by MyDeveloperDay).
Repository: rG LLVM Github Monorepo CHANGES SINCE LAST ACTION https://reviews.llvm.org/D115673/new/ https://reviews.llvm.org/D115673 Files: clang/lib/Format/TokenAnnotator.cpp clang/unittests/Format/FormatTestCSharp.cpp Index: clang/unittests/Format/FormatTestCSharp.cpp =================================================================== --- clang/unittests/Format/FormatTestCSharp.cpp +++ clang/unittests/Format/FormatTestCSharp.cpp @@ -1369,5 +1369,15 @@ Style); } +TEST_F(FormatTestCSharp, SwitchExpression) { + FormatStyle Style = getMicrosoftStyle(FormatStyle::LK_CSharp); + verifyFormat("int x = a switch {\n" + " 1 => (0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0),\n" + " 2 => 1,\n" + " _ => 2\n" + "};\n", + Style); +} + } // namespace format } // end namespace clang Index: clang/lib/Format/TokenAnnotator.cpp =================================================================== --- clang/lib/Format/TokenAnnotator.cpp +++ clang/lib/Format/TokenAnnotator.cpp @@ -3716,6 +3716,10 @@ return false; if (Right.is(TT_CSharpGenericTypeConstraint)) return true; + if (Right.Next && Right.Next->is(TT_FatArrow) && + (Right.is(tok::numeric_constant) || + (Right.is(tok::identifier) && Right.TokenText == "_"))) + return true; // Break after C# [...] and before public/protected/private/internal. if (Left.is(TT_AttributeSquare) && Left.is(tok::r_square) &&
Index: clang/unittests/Format/FormatTestCSharp.cpp =================================================================== --- clang/unittests/Format/FormatTestCSharp.cpp +++ clang/unittests/Format/FormatTestCSharp.cpp @@ -1369,5 +1369,15 @@ Style); } +TEST_F(FormatTestCSharp, SwitchExpression) { + FormatStyle Style = getMicrosoftStyle(FormatStyle::LK_CSharp); + verifyFormat("int x = a switch {\n" + " 1 => (0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0),\n" + " 2 => 1,\n" + " _ => 2\n" + "};\n", + Style); +} + } // namespace format } // end namespace clang Index: clang/lib/Format/TokenAnnotator.cpp =================================================================== --- clang/lib/Format/TokenAnnotator.cpp +++ clang/lib/Format/TokenAnnotator.cpp @@ -3716,6 +3716,10 @@ return false; if (Right.is(TT_CSharpGenericTypeConstraint)) return true; + if (Right.Next && Right.Next->is(TT_FatArrow) && + (Right.is(tok::numeric_constant) || + (Right.is(tok::identifier) && Right.TokenText == "_"))) + return true; // Break after C# [...] and before public/protected/private/internal. if (Left.is(TT_AttributeSquare) && Left.is(tok::r_square) &&
_______________________________________________ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits