summaryrefslogtreecommitdiffstats
path: root/clang/unittests/Format/FormatTestCSharp.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'clang/unittests/Format/FormatTestCSharp.cpp')
-rw-r--r--clang/unittests/Format/FormatTestCSharp.cpp57
1 files changed, 55 insertions, 2 deletions
diff --git a/clang/unittests/Format/FormatTestCSharp.cpp b/clang/unittests/Format/FormatTestCSharp.cpp
index 031de143389..a2f381078d4 100644
--- a/clang/unittests/Format/FormatTestCSharp.cpp
+++ b/clang/unittests/Format/FormatTestCSharp.cpp
@@ -147,15 +147,27 @@ TEST_F(FormatTestCSharp, CSharpFatArrows) {
}
TEST_F(FormatTestCSharp, CSharpNullConditional) {
+ FormatStyle Style = getGoogleStyle(FormatStyle::LK_CSharp);
+ Style.SpaceBeforeParens = FormatStyle::SBPO_Always;
+
verifyFormat(
"public Person(string firstName, string lastName, int? age=null)");
- verifyFormat("switch(args?.Length)");
+ verifyFormat("foo () {\n"
+ " switch (args?.Length) {}\n"
+ "}",
+ Style);
+
+ verifyFormat("switch (args?.Length) {}", Style);
verifyFormat("public static void Main(string[] args)\n"
"{\n"
" string dirPath = args?[0];\n"
"}");
+
+ Style.SpaceBeforeParens = FormatStyle::SBPO_Never;
+
+ verifyFormat("switch(args?.Length) {}", Style);
}
TEST_F(FormatTestCSharp, Attributes) {
@@ -221,16 +233,22 @@ TEST_F(FormatTestCSharp, Attributes) {
TEST_F(FormatTestCSharp, CSharpUsing) {
FormatStyle Style = getGoogleStyle(FormatStyle::LK_CSharp);
Style.SpaceBeforeParens = FormatStyle::SBPO_Always;
- verifyFormat("public void foo() {\n"
+ verifyFormat("public void foo () {\n"
" using (StreamWriter sw = new StreamWriter (filenameA)) {}\n"
"}",
Style);
+ verifyFormat("using (StreamWriter sw = new StreamWriter (filenameB)) {}",
+ Style);
+
Style.SpaceBeforeParens = FormatStyle::SBPO_Never;
verifyFormat("public void foo() {\n"
" using(StreamWriter sw = new StreamWriter(filenameB)) {}\n"
"}",
Style);
+
+ verifyFormat("using(StreamWriter sw = new StreamWriter(filenameB)) {}",
+ Style);
}
TEST_F(FormatTestCSharp, CSharpRegions) {
@@ -300,5 +318,40 @@ TEST_F(FormatTestCSharp, AttributesIndentation) {
Style);
}
+TEST_F(FormatTestCSharp, CSharpSpaceBefore) {
+ FormatStyle Style = getGoogleStyle(FormatStyle::LK_CSharp);
+ Style.SpaceBeforeParens = FormatStyle::SBPO_Always;
+
+ verifyFormat("List<string> list;", Style);
+ verifyFormat("Dictionary<string, string> dict;", Style);
+
+ verifyFormat("for (int i = 0; i < size (); i++) {\n"
+ "}",
+ Style);
+ verifyFormat("foreach (var x in y) {\n"
+ "}",
+ Style);
+ verifyFormat("switch (x) {}", Style);
+ verifyFormat("do {\n"
+ "} while (x);",
+ Style);
+
+ Style.SpaceBeforeParens = FormatStyle::SBPO_Never;
+
+ verifyFormat("List<string> list;", Style);
+ verifyFormat("Dictionary<string, string> dict;", Style);
+
+ verifyFormat("for(int i = 0; i < size(); i++) {\n"
+ "}",
+ Style);
+ verifyFormat("foreach(var x in y) {\n"
+ "}",
+ Style);
+ verifyFormat("switch(x) {}", Style);
+ verifyFormat("do {\n"
+ "} while(x);",
+ Style);
+}
+
} // namespace format
} // end namespace clang
OpenPOWER on IntegriCloud