diff options
author | mydeveloperday <mydeveloperday@gmail.com> | 2021-08-27 19:10:45 +0100 |
---|---|---|
committer | mydeveloperday <mydeveloperday@gmail.com> | 2021-08-27 19:13:53 +0100 |
commit | ed367b9dff10ee1df9ac1984eb2ad7544da7ab06 (patch) | |
tree | 987b27b179dccd9773d6b5f5ab54edd026e8710f /clang/unittests/Format/FormatTestCSharp.cpp | |
parent | 2930c839a5877356db6966409f4f9f2cdbcf3a07 (diff) | |
download | llvm-ed367b9dff10ee1df9ac1984eb2ad7544da7ab06.zip llvm-ed367b9dff10ee1df9ac1984eb2ad7544da7ab06.tar.gz llvm-ed367b9dff10ee1df9ac1984eb2ad7544da7ab06.tar.bz2 |
[clang-format] [PR51640] - New AfterEnum brace wrapping changes have cause C# behaviour to change
LLVM 13.0.0-rc2 shows change of behaviour in enum and interface BraceWrapping (likely before we simply didn't wrap) but may be related to {D99840}
Logged as https://bugs.llvm.org/show_bug.cgi?id=51640
This change ensure AfterEnum works for
`internal|public|protected|private enum A {` in the same way as it works for `enum A {` in C++
A similar issue was also observed with `interface` in C#
Reviewed By: krasimir, owenpan
Differential Revision: https://reviews.llvm.org/D108810
Diffstat (limited to 'clang/unittests/Format/FormatTestCSharp.cpp')
-rw-r--r-- | clang/unittests/Format/FormatTestCSharp.cpp | 217 |
1 files changed, 216 insertions, 1 deletions
diff --git a/clang/unittests/Format/FormatTestCSharp.cpp b/clang/unittests/Format/FormatTestCSharp.cpp index 8cd29e5..b7ea8d3 100644 --- a/clang/unittests/Format/FormatTestCSharp.cpp +++ b/clang/unittests/Format/FormatTestCSharp.cpp @@ -402,7 +402,9 @@ TEST_F(FormatTestCSharp, CSharpRegions) { } TEST_F(FormatTestCSharp, CSharpKeyWordEscaping) { - verifyFormat("public enum var {\n" + // AfterEnum is true by default. + verifyFormat("public enum var\n" + "{\n" " none,\n" " @string,\n" " bool,\n" @@ -1099,5 +1101,218 @@ class A { getGoogleStyle(FormatStyle::LK_Cpp)); } +TEST_F(FormatTestCSharp, CSharpAfterEnum) { + FormatStyle Style = getGoogleStyle(FormatStyle::LK_CSharp); + Style.BreakBeforeBraces = FormatStyle::BS_Custom; + Style.BraceWrapping.AfterEnum = false; + Style.AllowShortEnumsOnASingleLine = false; + + verifyFormat("enum MyEnum {\n" + " Foo,\n" + " Bar,\n" + "}", + Style); + verifyFormat("internal enum MyEnum {\n" + " Foo,\n" + " Bar,\n" + "}", + Style); + verifyFormat("public enum MyEnum {\n" + " Foo,\n" + " Bar,\n" + "}", + Style); + verifyFormat("protected enum MyEnum {\n" + " Foo,\n" + " Bar,\n" + "}", + Style); + verifyFormat("private enum MyEnum {\n" + " Foo,\n" + " Bar,\n" + "}", + Style); + + Style.BraceWrapping.AfterEnum = true; + Style.AllowShortEnumsOnASingleLine = false; + + verifyFormat("enum MyEnum\n" + "{\n" + " Foo,\n" + " Bar,\n" + "}", + Style); + verifyFormat("internal enum MyEnum\n" + "{\n" + " Foo,\n" + " Bar,\n" + "}", + Style); + verifyFormat("public enum MyEnum\n" + "{\n" + " Foo,\n" + " Bar,\n" + "}", + Style); + verifyFormat("protected enum MyEnum\n" + "{\n" + " Foo,\n" + " Bar,\n" + "}", + Style); + verifyFormat("private enum MyEnum\n" + "{\n" + " Foo,\n" + " Bar,\n" + "}", + Style); + verifyFormat("/* Foo */ private enum MyEnum\n" + "{\n" + " Foo,\n" + " Bar,\n" + "}", + Style); + verifyFormat("/* Foo */ /* Bar */ private enum MyEnum\n" + "{\n" + " Foo,\n" + " Bar,\n" + "}", + Style); +} + +TEST_F(FormatTestCSharp, CSharpAfterClass) { + FormatStyle Style = getGoogleStyle(FormatStyle::LK_CSharp); + Style.BreakBeforeBraces = FormatStyle::BS_Custom; + Style.BraceWrapping.AfterClass = false; + + verifyFormat("class MyClass {\n" + " int a;\n" + " int b;\n" + "}", + Style); + verifyFormat("internal class MyClass {\n" + " int a;\n" + " int b;\n" + "}", + Style); + verifyFormat("public class MyClass {\n" + " int a;\n" + " int b;\n" + "}", + Style); + verifyFormat("protected class MyClass {\n" + " int a;\n" + " int b;\n" + "}", + Style); + verifyFormat("private class MyClass {\n" + " int a;\n" + " int b;\n" + "}", + Style); + + verifyFormat("interface Interface {\n" + " int a;\n" + " int b;\n" + "}", + Style); + verifyFormat("internal interface Interface {\n" + " int a;\n" + " int b;\n" + "}", + Style); + verifyFormat("public interface Interface {\n" + " int a;\n" + " int b;\n" + "}", + Style); + verifyFormat("protected interface Interface {\n" + " int a;\n" + " int b;\n" + "}", + Style); + verifyFormat("private interface Interface {\n" + " int a;\n" + " int b;\n" + "}", + Style); + + Style.BraceWrapping.AfterClass = true; + + verifyFormat("class MyClass\n" + "{\n" + " int a;\n" + " int b;\n" + "}", + Style); + verifyFormat("internal class MyClass\n" + "{\n" + " int a;\n" + " int b;\n" + "}", + Style); + verifyFormat("public class MyClass\n" + "{\n" + " int a;\n" + " int b;\n" + "}", + Style); + verifyFormat("protected class MyClass\n" + "{\n" + " int a;\n" + " int b;\n" + "}", + Style); + verifyFormat("private class MyClass\n" + "{\n" + " int a;\n" + " int b;\n" + "}", + Style); + + verifyFormat("interface MyInterface\n" + "{\n" + " int a;\n" + " int b;\n" + "}", + Style); + verifyFormat("internal interface MyInterface\n" + "{\n" + " int a;\n" + " int b;\n" + "}", + Style); + verifyFormat("public interface MyInterface\n" + "{\n" + " int a;\n" + " int b;\n" + "}", + Style); + verifyFormat("protected interface MyInterface\n" + "{\n" + " int a;\n" + " int b;\n" + "}", + Style); + verifyFormat("private interface MyInterface\n" + "{\n" + " int a;\n" + " int b;\n" + "}", + Style); + verifyFormat("/* Foo */ private interface MyInterface\n" + "{\n" + " int a;\n" + " int b;\n" + "}", + Style); + verifyFormat("/* Foo */ /* Bar */ private interface MyInterface\n" + "{\n" + " int a;\n" + " int b;\n" + "}", + Style); +} + } // namespace format } // end namespace clang |