[clang-format] Add basic support for formatting C# files
Summary:
This revision adds basic support for formatting C# files with clang-format, I know the barrier to entry is high here so I'm sending this revision in to test the water as to whether this might be something we'd consider landing.
Tracking in Bugzilla as:
https://bugs.llvm.org/show_bug.cgi?id=40850
Justification:
C# code just looks ugly in comparison to the C++ code in our source tree which is clang-formatted.
I've struggled with Visual Studio reformatting to get a clean and consistent style, I want to format our C# code on saving like I do now for C++ and i want it to have the same style as defined in our .clang-format file, so it consistent as it can be with C++. (Braces/Breaking/Spaces/Indent etc..)
Using clang format without this patch leaves the code in a bad state, sometimes when the BreakStringLiterals is set, it fails to compile.
Mostly the C# is similar to Java, except instead of JavaAnnotations I try to reuse the TT_AttributeSquare.
Almost the most valuable portion is to have a new Language in order to partition the configuration for C# within a common .clang-format file, with the auto detection on the .cs extension. But there are other C# specific styles that could be added later if this is accepted. in particular how `{ set;get }` is formatted.
Reviewers: djasper, klimek, krasimir, benhamilton, JonasToth
Reviewed By: klimek
Subscribers: llvm-commits, mgorny, jdoerfert, cfe-commits
Tags: #clang, #clang-tools-extra
Differential Revision: https://reviews.llvm.org/D58404
llvm-svn: 356662
2019-03-21 21:09:22 +08:00
|
|
|
//===- unittest/Format/FormatTestCSharp.cpp - Formatting tests for CSharp -===//
|
|
|
|
//
|
|
|
|
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
|
|
|
|
// See https://llvm.org/LICENSE.txt for license information.
|
|
|
|
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
|
|
|
|
//
|
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
|
|
|
|
#include "FormatTestUtils.h"
|
|
|
|
#include "clang/Format/Format.h"
|
|
|
|
#include "llvm/Support/Debug.h"
|
|
|
|
#include "gtest/gtest.h"
|
|
|
|
|
|
|
|
#define DEBUG_TYPE "format-test"
|
|
|
|
|
|
|
|
namespace clang {
|
|
|
|
namespace format {
|
|
|
|
|
|
|
|
class FormatTestCSharp : public ::testing::Test {
|
|
|
|
protected:
|
|
|
|
static std::string format(llvm::StringRef Code, unsigned Offset,
|
|
|
|
unsigned Length, const FormatStyle &Style) {
|
|
|
|
LLVM_DEBUG(llvm::errs() << "---\n");
|
|
|
|
LLVM_DEBUG(llvm::errs() << Code << "\n\n");
|
|
|
|
std::vector<tooling::Range> Ranges(1, tooling::Range(Offset, Length));
|
|
|
|
tooling::Replacements Replaces = reformat(Style, Code, Ranges);
|
|
|
|
auto Result = applyAllReplacements(Code, Replaces);
|
|
|
|
EXPECT_TRUE(static_cast<bool>(Result));
|
|
|
|
LLVM_DEBUG(llvm::errs() << "\n" << *Result << "\n\n");
|
|
|
|
return *Result;
|
|
|
|
}
|
|
|
|
|
|
|
|
static std::string
|
|
|
|
format(llvm::StringRef Code,
|
2019-10-04 15:56:49 +08:00
|
|
|
const FormatStyle &Style = getMicrosoftStyle(FormatStyle::LK_CSharp)) {
|
[clang-format] Add basic support for formatting C# files
Summary:
This revision adds basic support for formatting C# files with clang-format, I know the barrier to entry is high here so I'm sending this revision in to test the water as to whether this might be something we'd consider landing.
Tracking in Bugzilla as:
https://bugs.llvm.org/show_bug.cgi?id=40850
Justification:
C# code just looks ugly in comparison to the C++ code in our source tree which is clang-formatted.
I've struggled with Visual Studio reformatting to get a clean and consistent style, I want to format our C# code on saving like I do now for C++ and i want it to have the same style as defined in our .clang-format file, so it consistent as it can be with C++. (Braces/Breaking/Spaces/Indent etc..)
Using clang format without this patch leaves the code in a bad state, sometimes when the BreakStringLiterals is set, it fails to compile.
Mostly the C# is similar to Java, except instead of JavaAnnotations I try to reuse the TT_AttributeSquare.
Almost the most valuable portion is to have a new Language in order to partition the configuration for C# within a common .clang-format file, with the auto detection on the .cs extension. But there are other C# specific styles that could be added later if this is accepted. in particular how `{ set;get }` is formatted.
Reviewers: djasper, klimek, krasimir, benhamilton, JonasToth
Reviewed By: klimek
Subscribers: llvm-commits, mgorny, jdoerfert, cfe-commits
Tags: #clang, #clang-tools-extra
Differential Revision: https://reviews.llvm.org/D58404
llvm-svn: 356662
2019-03-21 21:09:22 +08:00
|
|
|
return format(Code, 0, Code.size(), Style);
|
|
|
|
}
|
|
|
|
|
|
|
|
static FormatStyle getStyleWithColumns(unsigned ColumnLimit) {
|
2019-10-04 15:56:49 +08:00
|
|
|
FormatStyle Style = getMicrosoftStyle(FormatStyle::LK_CSharp);
|
[clang-format] Add basic support for formatting C# files
Summary:
This revision adds basic support for formatting C# files with clang-format, I know the barrier to entry is high here so I'm sending this revision in to test the water as to whether this might be something we'd consider landing.
Tracking in Bugzilla as:
https://bugs.llvm.org/show_bug.cgi?id=40850
Justification:
C# code just looks ugly in comparison to the C++ code in our source tree which is clang-formatted.
I've struggled with Visual Studio reformatting to get a clean and consistent style, I want to format our C# code on saving like I do now for C++ and i want it to have the same style as defined in our .clang-format file, so it consistent as it can be with C++. (Braces/Breaking/Spaces/Indent etc..)
Using clang format without this patch leaves the code in a bad state, sometimes when the BreakStringLiterals is set, it fails to compile.
Mostly the C# is similar to Java, except instead of JavaAnnotations I try to reuse the TT_AttributeSquare.
Almost the most valuable portion is to have a new Language in order to partition the configuration for C# within a common .clang-format file, with the auto detection on the .cs extension. But there are other C# specific styles that could be added later if this is accepted. in particular how `{ set;get }` is formatted.
Reviewers: djasper, klimek, krasimir, benhamilton, JonasToth
Reviewed By: klimek
Subscribers: llvm-commits, mgorny, jdoerfert, cfe-commits
Tags: #clang, #clang-tools-extra
Differential Revision: https://reviews.llvm.org/D58404
llvm-svn: 356662
2019-03-21 21:09:22 +08:00
|
|
|
Style.ColumnLimit = ColumnLimit;
|
|
|
|
return Style;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void verifyFormat(
|
|
|
|
llvm::StringRef Code,
|
2019-10-04 15:56:49 +08:00
|
|
|
const FormatStyle &Style = getMicrosoftStyle(FormatStyle::LK_CSharp)) {
|
[clang-format] Add basic support for formatting C# files
Summary:
This revision adds basic support for formatting C# files with clang-format, I know the barrier to entry is high here so I'm sending this revision in to test the water as to whether this might be something we'd consider landing.
Tracking in Bugzilla as:
https://bugs.llvm.org/show_bug.cgi?id=40850
Justification:
C# code just looks ugly in comparison to the C++ code in our source tree which is clang-formatted.
I've struggled with Visual Studio reformatting to get a clean and consistent style, I want to format our C# code on saving like I do now for C++ and i want it to have the same style as defined in our .clang-format file, so it consistent as it can be with C++. (Braces/Breaking/Spaces/Indent etc..)
Using clang format without this patch leaves the code in a bad state, sometimes when the BreakStringLiterals is set, it fails to compile.
Mostly the C# is similar to Java, except instead of JavaAnnotations I try to reuse the TT_AttributeSquare.
Almost the most valuable portion is to have a new Language in order to partition the configuration for C# within a common .clang-format file, with the auto detection on the .cs extension. But there are other C# specific styles that could be added later if this is accepted. in particular how `{ set;get }` is formatted.
Reviewers: djasper, klimek, krasimir, benhamilton, JonasToth
Reviewed By: klimek
Subscribers: llvm-commits, mgorny, jdoerfert, cfe-commits
Tags: #clang, #clang-tools-extra
Differential Revision: https://reviews.llvm.org/D58404
llvm-svn: 356662
2019-03-21 21:09:22 +08:00
|
|
|
EXPECT_EQ(Code.str(), format(Code, Style)) << "Expected code is not stable";
|
|
|
|
EXPECT_EQ(Code.str(), format(test::messUp(Code), Style));
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
TEST_F(FormatTestCSharp, CSharpClass) {
|
2019-10-04 15:56:49 +08:00
|
|
|
verifyFormat("public class SomeClass\n"
|
|
|
|
"{\n"
|
|
|
|
" void f()\n"
|
|
|
|
" {\n"
|
|
|
|
" }\n"
|
|
|
|
" int g()\n"
|
|
|
|
" {\n"
|
|
|
|
" return 0;\n"
|
|
|
|
" }\n"
|
|
|
|
" void h()\n"
|
|
|
|
" {\n"
|
|
|
|
" while (true)\n"
|
|
|
|
" f();\n"
|
|
|
|
" for (;;)\n"
|
|
|
|
" f();\n"
|
|
|
|
" if (true)\n"
|
|
|
|
" f();\n"
|
|
|
|
" }\n"
|
[clang-format] Add basic support for formatting C# files
Summary:
This revision adds basic support for formatting C# files with clang-format, I know the barrier to entry is high here so I'm sending this revision in to test the water as to whether this might be something we'd consider landing.
Tracking in Bugzilla as:
https://bugs.llvm.org/show_bug.cgi?id=40850
Justification:
C# code just looks ugly in comparison to the C++ code in our source tree which is clang-formatted.
I've struggled with Visual Studio reformatting to get a clean and consistent style, I want to format our C# code on saving like I do now for C++ and i want it to have the same style as defined in our .clang-format file, so it consistent as it can be with C++. (Braces/Breaking/Spaces/Indent etc..)
Using clang format without this patch leaves the code in a bad state, sometimes when the BreakStringLiterals is set, it fails to compile.
Mostly the C# is similar to Java, except instead of JavaAnnotations I try to reuse the TT_AttributeSquare.
Almost the most valuable portion is to have a new Language in order to partition the configuration for C# within a common .clang-format file, with the auto detection on the .cs extension. But there are other C# specific styles that could be added later if this is accepted. in particular how `{ set;get }` is formatted.
Reviewers: djasper, klimek, krasimir, benhamilton, JonasToth
Reviewed By: klimek
Subscribers: llvm-commits, mgorny, jdoerfert, cfe-commits
Tags: #clang, #clang-tools-extra
Differential Revision: https://reviews.llvm.org/D58404
llvm-svn: 356662
2019-03-21 21:09:22 +08:00
|
|
|
"}");
|
|
|
|
}
|
|
|
|
|
|
|
|
TEST_F(FormatTestCSharp, AccessModifiers) {
|
2019-10-04 15:56:49 +08:00
|
|
|
verifyFormat("public String toString()\n"
|
|
|
|
"{\n"
|
|
|
|
"}");
|
|
|
|
verifyFormat("private String toString()\n"
|
|
|
|
"{\n"
|
|
|
|
"}");
|
|
|
|
verifyFormat("protected String toString()\n"
|
|
|
|
"{\n"
|
|
|
|
"}");
|
|
|
|
verifyFormat("internal String toString()\n"
|
|
|
|
"{\n"
|
|
|
|
"}");
|
[clang-format] Add basic support for formatting C# files
Summary:
This revision adds basic support for formatting C# files with clang-format, I know the barrier to entry is high here so I'm sending this revision in to test the water as to whether this might be something we'd consider landing.
Tracking in Bugzilla as:
https://bugs.llvm.org/show_bug.cgi?id=40850
Justification:
C# code just looks ugly in comparison to the C++ code in our source tree which is clang-formatted.
I've struggled with Visual Studio reformatting to get a clean and consistent style, I want to format our C# code on saving like I do now for C++ and i want it to have the same style as defined in our .clang-format file, so it consistent as it can be with C++. (Braces/Breaking/Spaces/Indent etc..)
Using clang format without this patch leaves the code in a bad state, sometimes when the BreakStringLiterals is set, it fails to compile.
Mostly the C# is similar to Java, except instead of JavaAnnotations I try to reuse the TT_AttributeSquare.
Almost the most valuable portion is to have a new Language in order to partition the configuration for C# within a common .clang-format file, with the auto detection on the .cs extension. But there are other C# specific styles that could be added later if this is accepted. in particular how `{ set;get }` is formatted.
Reviewers: djasper, klimek, krasimir, benhamilton, JonasToth
Reviewed By: klimek
Subscribers: llvm-commits, mgorny, jdoerfert, cfe-commits
Tags: #clang, #clang-tools-extra
Differential Revision: https://reviews.llvm.org/D58404
llvm-svn: 356662
2019-03-21 21:09:22 +08:00
|
|
|
|
2019-10-04 15:56:49 +08:00
|
|
|
verifyFormat("public override String toString()\n"
|
|
|
|
"{\n"
|
|
|
|
"}");
|
|
|
|
verifyFormat("private override String toString()\n"
|
|
|
|
"{\n"
|
|
|
|
"}");
|
|
|
|
verifyFormat("protected override String toString()\n"
|
|
|
|
"{\n"
|
|
|
|
"}");
|
|
|
|
verifyFormat("internal override String toString()\n"
|
|
|
|
"{\n"
|
|
|
|
"}");
|
[clang-format] Add basic support for formatting C# files
Summary:
This revision adds basic support for formatting C# files with clang-format, I know the barrier to entry is high here so I'm sending this revision in to test the water as to whether this might be something we'd consider landing.
Tracking in Bugzilla as:
https://bugs.llvm.org/show_bug.cgi?id=40850
Justification:
C# code just looks ugly in comparison to the C++ code in our source tree which is clang-formatted.
I've struggled with Visual Studio reformatting to get a clean and consistent style, I want to format our C# code on saving like I do now for C++ and i want it to have the same style as defined in our .clang-format file, so it consistent as it can be with C++. (Braces/Breaking/Spaces/Indent etc..)
Using clang format without this patch leaves the code in a bad state, sometimes when the BreakStringLiterals is set, it fails to compile.
Mostly the C# is similar to Java, except instead of JavaAnnotations I try to reuse the TT_AttributeSquare.
Almost the most valuable portion is to have a new Language in order to partition the configuration for C# within a common .clang-format file, with the auto detection on the .cs extension. But there are other C# specific styles that could be added later if this is accepted. in particular how `{ set;get }` is formatted.
Reviewers: djasper, klimek, krasimir, benhamilton, JonasToth
Reviewed By: klimek
Subscribers: llvm-commits, mgorny, jdoerfert, cfe-commits
Tags: #clang, #clang-tools-extra
Differential Revision: https://reviews.llvm.org/D58404
llvm-svn: 356662
2019-03-21 21:09:22 +08:00
|
|
|
|
2019-10-04 15:56:49 +08:00
|
|
|
verifyFormat("internal static String toString()\n"
|
|
|
|
"{\n"
|
|
|
|
"}");
|
[clang-format] Add basic support for formatting C# files
Summary:
This revision adds basic support for formatting C# files with clang-format, I know the barrier to entry is high here so I'm sending this revision in to test the water as to whether this might be something we'd consider landing.
Tracking in Bugzilla as:
https://bugs.llvm.org/show_bug.cgi?id=40850
Justification:
C# code just looks ugly in comparison to the C++ code in our source tree which is clang-formatted.
I've struggled with Visual Studio reformatting to get a clean and consistent style, I want to format our C# code on saving like I do now for C++ and i want it to have the same style as defined in our .clang-format file, so it consistent as it can be with C++. (Braces/Breaking/Spaces/Indent etc..)
Using clang format without this patch leaves the code in a bad state, sometimes when the BreakStringLiterals is set, it fails to compile.
Mostly the C# is similar to Java, except instead of JavaAnnotations I try to reuse the TT_AttributeSquare.
Almost the most valuable portion is to have a new Language in order to partition the configuration for C# within a common .clang-format file, with the auto detection on the .cs extension. But there are other C# specific styles that could be added later if this is accepted. in particular how `{ set;get }` is formatted.
Reviewers: djasper, klimek, krasimir, benhamilton, JonasToth
Reviewed By: klimek
Subscribers: llvm-commits, mgorny, jdoerfert, cfe-commits
Tags: #clang, #clang-tools-extra
Differential Revision: https://reviews.llvm.org/D58404
llvm-svn: 356662
2019-03-21 21:09:22 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
TEST_F(FormatTestCSharp, NoStringLiteralBreaks) {
|
|
|
|
verifyFormat("foo("
|
|
|
|
"\"aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa"
|
|
|
|
"aaaaaa\");");
|
|
|
|
}
|
|
|
|
|
|
|
|
TEST_F(FormatTestCSharp, CSharpVerbatiumStringLiterals) {
|
|
|
|
verifyFormat("foo(@\"aaaaaaaa\\abc\\aaaa\");");
|
|
|
|
// @"ABC\" + ToString("B") - handle embedded \ in literal string at
|
|
|
|
// the end
|
|
|
|
//
|
|
|
|
/*
|
|
|
|
* After removal of Lexer change we are currently not able
|
|
|
|
* To handle these cases
|
|
|
|
verifyFormat("string s = @\"ABC\\\" + ToString(\"B\");");
|
|
|
|
verifyFormat("string s = @\"ABC\"\"DEF\"\"GHI\"");
|
|
|
|
verifyFormat("string s = @\"ABC\"\"DEF\"\"\"");
|
|
|
|
verifyFormat("string s = @\"ABC\"\"DEF\"\"\" + abc");
|
|
|
|
*/
|
|
|
|
}
|
|
|
|
|
|
|
|
TEST_F(FormatTestCSharp, CSharpInterpolatedStringLiterals) {
|
|
|
|
verifyFormat("foo($\"aaaaaaaa{aaa}aaaa\");");
|
|
|
|
verifyFormat("foo($\"aaaa{A}\");");
|
|
|
|
verifyFormat(
|
|
|
|
"foo($\"aaaa{A}"
|
|
|
|
"aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa\");");
|
|
|
|
verifyFormat("Name = $\"{firstName} {lastName}\";");
|
|
|
|
|
|
|
|
// $"ABC\" + ToString("B") - handle embedded \ in literal string at
|
|
|
|
// the end
|
|
|
|
verifyFormat("string s = $\"A{abc}BC\" + ToString(\"B\");");
|
|
|
|
verifyFormat("$\"{domain}\\\\{user}\"");
|
|
|
|
verifyFormat(
|
|
|
|
"var verbatimInterpolated = $@\"C:\\Users\\{userName}\\Documents\\\";");
|
|
|
|
}
|
|
|
|
|
|
|
|
TEST_F(FormatTestCSharp, CSharpFatArrows) {
|
|
|
|
verifyFormat("Task serverTask = Task.Run(async() => {");
|
|
|
|
verifyFormat("public override string ToString() => \"{Name}\\{Age}\";");
|
|
|
|
}
|
|
|
|
|
|
|
|
TEST_F(FormatTestCSharp, CSharpNullConditional) {
|
2019-10-04 16:10:22 +08:00
|
|
|
FormatStyle Style = getGoogleStyle(FormatStyle::LK_CSharp);
|
|
|
|
Style.SpaceBeforeParens = FormatStyle::SBPO_Always;
|
|
|
|
|
[clang-format] Add basic support for formatting C# files
Summary:
This revision adds basic support for formatting C# files with clang-format, I know the barrier to entry is high here so I'm sending this revision in to test the water as to whether this might be something we'd consider landing.
Tracking in Bugzilla as:
https://bugs.llvm.org/show_bug.cgi?id=40850
Justification:
C# code just looks ugly in comparison to the C++ code in our source tree which is clang-formatted.
I've struggled with Visual Studio reformatting to get a clean and consistent style, I want to format our C# code on saving like I do now for C++ and i want it to have the same style as defined in our .clang-format file, so it consistent as it can be with C++. (Braces/Breaking/Spaces/Indent etc..)
Using clang format without this patch leaves the code in a bad state, sometimes when the BreakStringLiterals is set, it fails to compile.
Mostly the C# is similar to Java, except instead of JavaAnnotations I try to reuse the TT_AttributeSquare.
Almost the most valuable portion is to have a new Language in order to partition the configuration for C# within a common .clang-format file, with the auto detection on the .cs extension. But there are other C# specific styles that could be added later if this is accepted. in particular how `{ set;get }` is formatted.
Reviewers: djasper, klimek, krasimir, benhamilton, JonasToth
Reviewed By: klimek
Subscribers: llvm-commits, mgorny, jdoerfert, cfe-commits
Tags: #clang, #clang-tools-extra
Differential Revision: https://reviews.llvm.org/D58404
llvm-svn: 356662
2019-03-21 21:09:22 +08:00
|
|
|
verifyFormat(
|
|
|
|
"public Person(string firstName, string lastName, int? age=null)");
|
|
|
|
|
2019-10-04 16:10:22 +08:00
|
|
|
verifyFormat("foo () {\n"
|
|
|
|
" switch (args?.Length) {}\n"
|
|
|
|
"}",
|
|
|
|
Style);
|
|
|
|
|
|
|
|
verifyFormat("switch (args?.Length) {}", Style);
|
[clang-format] Add basic support for formatting C# files
Summary:
This revision adds basic support for formatting C# files with clang-format, I know the barrier to entry is high here so I'm sending this revision in to test the water as to whether this might be something we'd consider landing.
Tracking in Bugzilla as:
https://bugs.llvm.org/show_bug.cgi?id=40850
Justification:
C# code just looks ugly in comparison to the C++ code in our source tree which is clang-formatted.
I've struggled with Visual Studio reformatting to get a clean and consistent style, I want to format our C# code on saving like I do now for C++ and i want it to have the same style as defined in our .clang-format file, so it consistent as it can be with C++. (Braces/Breaking/Spaces/Indent etc..)
Using clang format without this patch leaves the code in a bad state, sometimes when the BreakStringLiterals is set, it fails to compile.
Mostly the C# is similar to Java, except instead of JavaAnnotations I try to reuse the TT_AttributeSquare.
Almost the most valuable portion is to have a new Language in order to partition the configuration for C# within a common .clang-format file, with the auto detection on the .cs extension. But there are other C# specific styles that could be added later if this is accepted. in particular how `{ set;get }` is formatted.
Reviewers: djasper, klimek, krasimir, benhamilton, JonasToth
Reviewed By: klimek
Subscribers: llvm-commits, mgorny, jdoerfert, cfe-commits
Tags: #clang, #clang-tools-extra
Differential Revision: https://reviews.llvm.org/D58404
llvm-svn: 356662
2019-03-21 21:09:22 +08:00
|
|
|
|
2019-10-04 15:56:49 +08:00
|
|
|
verifyFormat("public static void Main(string[] args)\n"
|
|
|
|
"{\n"
|
|
|
|
" string dirPath = args?[0];\n"
|
|
|
|
"}");
|
2019-10-04 16:10:22 +08:00
|
|
|
|
|
|
|
Style.SpaceBeforeParens = FormatStyle::SBPO_Never;
|
|
|
|
|
|
|
|
verifyFormat("switch(args?.Length) {}", Style);
|
[clang-format] Add basic support for formatting C# files
Summary:
This revision adds basic support for formatting C# files with clang-format, I know the barrier to entry is high here so I'm sending this revision in to test the water as to whether this might be something we'd consider landing.
Tracking in Bugzilla as:
https://bugs.llvm.org/show_bug.cgi?id=40850
Justification:
C# code just looks ugly in comparison to the C++ code in our source tree which is clang-formatted.
I've struggled with Visual Studio reformatting to get a clean and consistent style, I want to format our C# code on saving like I do now for C++ and i want it to have the same style as defined in our .clang-format file, so it consistent as it can be with C++. (Braces/Breaking/Spaces/Indent etc..)
Using clang format without this patch leaves the code in a bad state, sometimes when the BreakStringLiterals is set, it fails to compile.
Mostly the C# is similar to Java, except instead of JavaAnnotations I try to reuse the TT_AttributeSquare.
Almost the most valuable portion is to have a new Language in order to partition the configuration for C# within a common .clang-format file, with the auto detection on the .cs extension. But there are other C# specific styles that could be added later if this is accepted. in particular how `{ set;get }` is formatted.
Reviewers: djasper, klimek, krasimir, benhamilton, JonasToth
Reviewed By: klimek
Subscribers: llvm-commits, mgorny, jdoerfert, cfe-commits
Tags: #clang, #clang-tools-extra
Differential Revision: https://reviews.llvm.org/D58404
llvm-svn: 356662
2019-03-21 21:09:22 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
TEST_F(FormatTestCSharp, Attributes) {
|
|
|
|
verifyFormat("[STAThread]\n"
|
2019-10-04 15:56:49 +08:00
|
|
|
"static void Main(string[] args)\n"
|
|
|
|
"{\n"
|
|
|
|
"}");
|
[clang-format] Add basic support for formatting C# files
Summary:
This revision adds basic support for formatting C# files with clang-format, I know the barrier to entry is high here so I'm sending this revision in to test the water as to whether this might be something we'd consider landing.
Tracking in Bugzilla as:
https://bugs.llvm.org/show_bug.cgi?id=40850
Justification:
C# code just looks ugly in comparison to the C++ code in our source tree which is clang-formatted.
I've struggled with Visual Studio reformatting to get a clean and consistent style, I want to format our C# code on saving like I do now for C++ and i want it to have the same style as defined in our .clang-format file, so it consistent as it can be with C++. (Braces/Breaking/Spaces/Indent etc..)
Using clang format without this patch leaves the code in a bad state, sometimes when the BreakStringLiterals is set, it fails to compile.
Mostly the C# is similar to Java, except instead of JavaAnnotations I try to reuse the TT_AttributeSquare.
Almost the most valuable portion is to have a new Language in order to partition the configuration for C# within a common .clang-format file, with the auto detection on the .cs extension. But there are other C# specific styles that could be added later if this is accepted. in particular how `{ set;get }` is formatted.
Reviewers: djasper, klimek, krasimir, benhamilton, JonasToth
Reviewed By: klimek
Subscribers: llvm-commits, mgorny, jdoerfert, cfe-commits
Tags: #clang, #clang-tools-extra
Differential Revision: https://reviews.llvm.org/D58404
llvm-svn: 356662
2019-03-21 21:09:22 +08:00
|
|
|
|
|
|
|
verifyFormat("[TestMethod]\n"
|
2019-10-04 15:56:49 +08:00
|
|
|
"private class Test\n"
|
|
|
|
"{\n"
|
|
|
|
"}");
|
[clang-format] Add basic support for formatting C# files
Summary:
This revision adds basic support for formatting C# files with clang-format, I know the barrier to entry is high here so I'm sending this revision in to test the water as to whether this might be something we'd consider landing.
Tracking in Bugzilla as:
https://bugs.llvm.org/show_bug.cgi?id=40850
Justification:
C# code just looks ugly in comparison to the C++ code in our source tree which is clang-formatted.
I've struggled with Visual Studio reformatting to get a clean and consistent style, I want to format our C# code on saving like I do now for C++ and i want it to have the same style as defined in our .clang-format file, so it consistent as it can be with C++. (Braces/Breaking/Spaces/Indent etc..)
Using clang format without this patch leaves the code in a bad state, sometimes when the BreakStringLiterals is set, it fails to compile.
Mostly the C# is similar to Java, except instead of JavaAnnotations I try to reuse the TT_AttributeSquare.
Almost the most valuable portion is to have a new Language in order to partition the configuration for C# within a common .clang-format file, with the auto detection on the .cs extension. But there are other C# specific styles that could be added later if this is accepted. in particular how `{ set;get }` is formatted.
Reviewers: djasper, klimek, krasimir, benhamilton, JonasToth
Reviewed By: klimek
Subscribers: llvm-commits, mgorny, jdoerfert, cfe-commits
Tags: #clang, #clang-tools-extra
Differential Revision: https://reviews.llvm.org/D58404
llvm-svn: 356662
2019-03-21 21:09:22 +08:00
|
|
|
|
|
|
|
verifyFormat("[TestMethod]\n"
|
2019-10-04 15:56:49 +08:00
|
|
|
"protected class Test\n"
|
|
|
|
"{\n"
|
|
|
|
"}");
|
[clang-format] Add basic support for formatting C# files
Summary:
This revision adds basic support for formatting C# files with clang-format, I know the barrier to entry is high here so I'm sending this revision in to test the water as to whether this might be something we'd consider landing.
Tracking in Bugzilla as:
https://bugs.llvm.org/show_bug.cgi?id=40850
Justification:
C# code just looks ugly in comparison to the C++ code in our source tree which is clang-formatted.
I've struggled with Visual Studio reformatting to get a clean and consistent style, I want to format our C# code on saving like I do now for C++ and i want it to have the same style as defined in our .clang-format file, so it consistent as it can be with C++. (Braces/Breaking/Spaces/Indent etc..)
Using clang format without this patch leaves the code in a bad state, sometimes when the BreakStringLiterals is set, it fails to compile.
Mostly the C# is similar to Java, except instead of JavaAnnotations I try to reuse the TT_AttributeSquare.
Almost the most valuable portion is to have a new Language in order to partition the configuration for C# within a common .clang-format file, with the auto detection on the .cs extension. But there are other C# specific styles that could be added later if this is accepted. in particular how `{ set;get }` is formatted.
Reviewers: djasper, klimek, krasimir, benhamilton, JonasToth
Reviewed By: klimek
Subscribers: llvm-commits, mgorny, jdoerfert, cfe-commits
Tags: #clang, #clang-tools-extra
Differential Revision: https://reviews.llvm.org/D58404
llvm-svn: 356662
2019-03-21 21:09:22 +08:00
|
|
|
|
|
|
|
verifyFormat("[TestMethod]\n"
|
2019-10-04 15:56:49 +08:00
|
|
|
"internal class Test\n"
|
|
|
|
"{\n"
|
|
|
|
"}");
|
[clang-format] Add basic support for formatting C# files
Summary:
This revision adds basic support for formatting C# files with clang-format, I know the barrier to entry is high here so I'm sending this revision in to test the water as to whether this might be something we'd consider landing.
Tracking in Bugzilla as:
https://bugs.llvm.org/show_bug.cgi?id=40850
Justification:
C# code just looks ugly in comparison to the C++ code in our source tree which is clang-formatted.
I've struggled with Visual Studio reformatting to get a clean and consistent style, I want to format our C# code on saving like I do now for C++ and i want it to have the same style as defined in our .clang-format file, so it consistent as it can be with C++. (Braces/Breaking/Spaces/Indent etc..)
Using clang format without this patch leaves the code in a bad state, sometimes when the BreakStringLiterals is set, it fails to compile.
Mostly the C# is similar to Java, except instead of JavaAnnotations I try to reuse the TT_AttributeSquare.
Almost the most valuable portion is to have a new Language in order to partition the configuration for C# within a common .clang-format file, with the auto detection on the .cs extension. But there are other C# specific styles that could be added later if this is accepted. in particular how `{ set;get }` is formatted.
Reviewers: djasper, klimek, krasimir, benhamilton, JonasToth
Reviewed By: klimek
Subscribers: llvm-commits, mgorny, jdoerfert, cfe-commits
Tags: #clang, #clang-tools-extra
Differential Revision: https://reviews.llvm.org/D58404
llvm-svn: 356662
2019-03-21 21:09:22 +08:00
|
|
|
|
|
|
|
verifyFormat("[TestMethod]\n"
|
2019-10-04 15:56:49 +08:00
|
|
|
"class Test\n"
|
|
|
|
"{\n"
|
|
|
|
"}");
|
[clang-format] Add basic support for formatting C# files
Summary:
This revision adds basic support for formatting C# files with clang-format, I know the barrier to entry is high here so I'm sending this revision in to test the water as to whether this might be something we'd consider landing.
Tracking in Bugzilla as:
https://bugs.llvm.org/show_bug.cgi?id=40850
Justification:
C# code just looks ugly in comparison to the C++ code in our source tree which is clang-formatted.
I've struggled with Visual Studio reformatting to get a clean and consistent style, I want to format our C# code on saving like I do now for C++ and i want it to have the same style as defined in our .clang-format file, so it consistent as it can be with C++. (Braces/Breaking/Spaces/Indent etc..)
Using clang format without this patch leaves the code in a bad state, sometimes when the BreakStringLiterals is set, it fails to compile.
Mostly the C# is similar to Java, except instead of JavaAnnotations I try to reuse the TT_AttributeSquare.
Almost the most valuable portion is to have a new Language in order to partition the configuration for C# within a common .clang-format file, with the auto detection on the .cs extension. But there are other C# specific styles that could be added later if this is accepted. in particular how `{ set;get }` is formatted.
Reviewers: djasper, klimek, krasimir, benhamilton, JonasToth
Reviewed By: klimek
Subscribers: llvm-commits, mgorny, jdoerfert, cfe-commits
Tags: #clang, #clang-tools-extra
Differential Revision: https://reviews.llvm.org/D58404
llvm-svn: 356662
2019-03-21 21:09:22 +08:00
|
|
|
|
|
|
|
verifyFormat("[TestMethod]\n"
|
|
|
|
"[DeploymentItem(\"Test.txt\")]\n"
|
2019-10-04 15:56:49 +08:00
|
|
|
"public class Test\n"
|
|
|
|
"{\n"
|
|
|
|
"}");
|
[clang-format] Add basic support for formatting C# files
Summary:
This revision adds basic support for formatting C# files with clang-format, I know the barrier to entry is high here so I'm sending this revision in to test the water as to whether this might be something we'd consider landing.
Tracking in Bugzilla as:
https://bugs.llvm.org/show_bug.cgi?id=40850
Justification:
C# code just looks ugly in comparison to the C++ code in our source tree which is clang-formatted.
I've struggled with Visual Studio reformatting to get a clean and consistent style, I want to format our C# code on saving like I do now for C++ and i want it to have the same style as defined in our .clang-format file, so it consistent as it can be with C++. (Braces/Breaking/Spaces/Indent etc..)
Using clang format without this patch leaves the code in a bad state, sometimes when the BreakStringLiterals is set, it fails to compile.
Mostly the C# is similar to Java, except instead of JavaAnnotations I try to reuse the TT_AttributeSquare.
Almost the most valuable portion is to have a new Language in order to partition the configuration for C# within a common .clang-format file, with the auto detection on the .cs extension. But there are other C# specific styles that could be added later if this is accepted. in particular how `{ set;get }` is formatted.
Reviewers: djasper, klimek, krasimir, benhamilton, JonasToth
Reviewed By: klimek
Subscribers: llvm-commits, mgorny, jdoerfert, cfe-commits
Tags: #clang, #clang-tools-extra
Differential Revision: https://reviews.llvm.org/D58404
llvm-svn: 356662
2019-03-21 21:09:22 +08:00
|
|
|
|
|
|
|
verifyFormat("[System.AttributeUsage(System.AttributeTargets.Method)]\n"
|
|
|
|
"[System.Runtime.InteropServices.ComVisible(true)]\n"
|
2019-10-04 15:56:49 +08:00
|
|
|
"public sealed class STAThreadAttribute : Attribute\n"
|
|
|
|
"{\n"
|
|
|
|
"}");
|
[clang-format] Add basic support for formatting C# files
Summary:
This revision adds basic support for formatting C# files with clang-format, I know the barrier to entry is high here so I'm sending this revision in to test the water as to whether this might be something we'd consider landing.
Tracking in Bugzilla as:
https://bugs.llvm.org/show_bug.cgi?id=40850
Justification:
C# code just looks ugly in comparison to the C++ code in our source tree which is clang-formatted.
I've struggled with Visual Studio reformatting to get a clean and consistent style, I want to format our C# code on saving like I do now for C++ and i want it to have the same style as defined in our .clang-format file, so it consistent as it can be with C++. (Braces/Breaking/Spaces/Indent etc..)
Using clang format without this patch leaves the code in a bad state, sometimes when the BreakStringLiterals is set, it fails to compile.
Mostly the C# is similar to Java, except instead of JavaAnnotations I try to reuse the TT_AttributeSquare.
Almost the most valuable portion is to have a new Language in order to partition the configuration for C# within a common .clang-format file, with the auto detection on the .cs extension. But there are other C# specific styles that could be added later if this is accepted. in particular how `{ set;get }` is formatted.
Reviewers: djasper, klimek, krasimir, benhamilton, JonasToth
Reviewed By: klimek
Subscribers: llvm-commits, mgorny, jdoerfert, cfe-commits
Tags: #clang, #clang-tools-extra
Differential Revision: https://reviews.llvm.org/D58404
llvm-svn: 356662
2019-03-21 21:09:22 +08:00
|
|
|
|
|
|
|
verifyFormat("[Verb(\"start\", HelpText = \"Starts the server listening on "
|
|
|
|
"provided port\")]\n"
|
2019-10-04 15:56:49 +08:00
|
|
|
"class Test\n"
|
|
|
|
"{\n"
|
|
|
|
"}");
|
[clang-format] Add basic support for formatting C# files
Summary:
This revision adds basic support for formatting C# files with clang-format, I know the barrier to entry is high here so I'm sending this revision in to test the water as to whether this might be something we'd consider landing.
Tracking in Bugzilla as:
https://bugs.llvm.org/show_bug.cgi?id=40850
Justification:
C# code just looks ugly in comparison to the C++ code in our source tree which is clang-formatted.
I've struggled with Visual Studio reformatting to get a clean and consistent style, I want to format our C# code on saving like I do now for C++ and i want it to have the same style as defined in our .clang-format file, so it consistent as it can be with C++. (Braces/Breaking/Spaces/Indent etc..)
Using clang format without this patch leaves the code in a bad state, sometimes when the BreakStringLiterals is set, it fails to compile.
Mostly the C# is similar to Java, except instead of JavaAnnotations I try to reuse the TT_AttributeSquare.
Almost the most valuable portion is to have a new Language in order to partition the configuration for C# within a common .clang-format file, with the auto detection on the .cs extension. But there are other C# specific styles that could be added later if this is accepted. in particular how `{ set;get }` is formatted.
Reviewers: djasper, klimek, krasimir, benhamilton, JonasToth
Reviewed By: klimek
Subscribers: llvm-commits, mgorny, jdoerfert, cfe-commits
Tags: #clang, #clang-tools-extra
Differential Revision: https://reviews.llvm.org/D58404
llvm-svn: 356662
2019-03-21 21:09:22 +08:00
|
|
|
|
|
|
|
verifyFormat("[TestMethod]\n"
|
2019-10-04 15:56:49 +08:00
|
|
|
"public string Host\n"
|
|
|
|
"{\n"
|
|
|
|
" set;\n"
|
|
|
|
" get;\n"
|
|
|
|
"}");
|
[clang-format] Add basic support for formatting C# files
Summary:
This revision adds basic support for formatting C# files with clang-format, I know the barrier to entry is high here so I'm sending this revision in to test the water as to whether this might be something we'd consider landing.
Tracking in Bugzilla as:
https://bugs.llvm.org/show_bug.cgi?id=40850
Justification:
C# code just looks ugly in comparison to the C++ code in our source tree which is clang-formatted.
I've struggled with Visual Studio reformatting to get a clean and consistent style, I want to format our C# code on saving like I do now for C++ and i want it to have the same style as defined in our .clang-format file, so it consistent as it can be with C++. (Braces/Breaking/Spaces/Indent etc..)
Using clang format without this patch leaves the code in a bad state, sometimes when the BreakStringLiterals is set, it fails to compile.
Mostly the C# is similar to Java, except instead of JavaAnnotations I try to reuse the TT_AttributeSquare.
Almost the most valuable portion is to have a new Language in order to partition the configuration for C# within a common .clang-format file, with the auto detection on the .cs extension. But there are other C# specific styles that could be added later if this is accepted. in particular how `{ set;get }` is formatted.
Reviewers: djasper, klimek, krasimir, benhamilton, JonasToth
Reviewed By: klimek
Subscribers: llvm-commits, mgorny, jdoerfert, cfe-commits
Tags: #clang, #clang-tools-extra
Differential Revision: https://reviews.llvm.org/D58404
llvm-svn: 356662
2019-03-21 21:09:22 +08:00
|
|
|
|
|
|
|
verifyFormat("[TestMethod(\"start\", HelpText = \"Starts the server "
|
|
|
|
"listening on provided host\")]\n"
|
2019-10-04 15:56:49 +08:00
|
|
|
"public string Host\n"
|
|
|
|
"{\n"
|
|
|
|
" set;\n"
|
|
|
|
" get;\n"
|
|
|
|
"}");
|
[clang-format] Add basic support for formatting C# files
Summary:
This revision adds basic support for formatting C# files with clang-format, I know the barrier to entry is high here so I'm sending this revision in to test the water as to whether this might be something we'd consider landing.
Tracking in Bugzilla as:
https://bugs.llvm.org/show_bug.cgi?id=40850
Justification:
C# code just looks ugly in comparison to the C++ code in our source tree which is clang-formatted.
I've struggled with Visual Studio reformatting to get a clean and consistent style, I want to format our C# code on saving like I do now for C++ and i want it to have the same style as defined in our .clang-format file, so it consistent as it can be with C++. (Braces/Breaking/Spaces/Indent etc..)
Using clang format without this patch leaves the code in a bad state, sometimes when the BreakStringLiterals is set, it fails to compile.
Mostly the C# is similar to Java, except instead of JavaAnnotations I try to reuse the TT_AttributeSquare.
Almost the most valuable portion is to have a new Language in order to partition the configuration for C# within a common .clang-format file, with the auto detection on the .cs extension. But there are other C# specific styles that could be added later if this is accepted. in particular how `{ set;get }` is formatted.
Reviewers: djasper, klimek, krasimir, benhamilton, JonasToth
Reviewed By: klimek
Subscribers: llvm-commits, mgorny, jdoerfert, cfe-commits
Tags: #clang, #clang-tools-extra
Differential Revision: https://reviews.llvm.org/D58404
llvm-svn: 356662
2019-03-21 21:09:22 +08:00
|
|
|
}
|
|
|
|
|
[clang-format] [PR43100] clang-format C# support does not add a space between "using" and paren
Summary:
Addresses https://bugs.llvm.org/show_bug.cgi?id=43100
Formatting using statement in C# with clang-format removes the space between using and paren even when SpaceBeforeParens is !
```
using(FileStream fs = new FileStream(path, FileMode.Open, FileAccess.Read, FileShare.Read, bufferSize : 1))
```
this change simply overcomes this for when using C# settings in the .clang-format file
```
using (FileStream fs = new FileStream(path, FileMode.Open, FileAccess.Read, FileShare.Read, bufferSize : 1))
```
All FormatTests pass..
```
[==========] 688 tests from 21 test cases ran. (88508 ms total)
[ PASSED ] 688 tests.
```
Reviewers: djasper, klimek, owenpan
Reviewed By: owenpan
Subscribers: llvm-commits, cfe-commits
Tags: #clang
Differential Revision: https://reviews.llvm.org/D66662
llvm-svn: 371720
2019-09-12 18:18:53 +08:00
|
|
|
TEST_F(FormatTestCSharp, CSharpUsing) {
|
|
|
|
FormatStyle Style = getGoogleStyle(FormatStyle::LK_CSharp);
|
|
|
|
Style.SpaceBeforeParens = FormatStyle::SBPO_Always;
|
2019-10-04 16:10:22 +08:00
|
|
|
verifyFormat("public void foo () {\n"
|
[clang-format] [PR43100] clang-format C# support does not add a space between "using" and paren
Summary:
Addresses https://bugs.llvm.org/show_bug.cgi?id=43100
Formatting using statement in C# with clang-format removes the space between using and paren even when SpaceBeforeParens is !
```
using(FileStream fs = new FileStream(path, FileMode.Open, FileAccess.Read, FileShare.Read, bufferSize : 1))
```
this change simply overcomes this for when using C# settings in the .clang-format file
```
using (FileStream fs = new FileStream(path, FileMode.Open, FileAccess.Read, FileShare.Read, bufferSize : 1))
```
All FormatTests pass..
```
[==========] 688 tests from 21 test cases ran. (88508 ms total)
[ PASSED ] 688 tests.
```
Reviewers: djasper, klimek, owenpan
Reviewed By: owenpan
Subscribers: llvm-commits, cfe-commits
Tags: #clang
Differential Revision: https://reviews.llvm.org/D66662
llvm-svn: 371720
2019-09-12 18:18:53 +08:00
|
|
|
" using (StreamWriter sw = new StreamWriter (filenameA)) {}\n"
|
|
|
|
"}",
|
|
|
|
Style);
|
|
|
|
|
2019-10-04 16:10:22 +08:00
|
|
|
verifyFormat("using (StreamWriter sw = new StreamWriter (filenameB)) {}",
|
|
|
|
Style);
|
|
|
|
|
[clang-format] [PR43100] clang-format C# support does not add a space between "using" and paren
Summary:
Addresses https://bugs.llvm.org/show_bug.cgi?id=43100
Formatting using statement in C# with clang-format removes the space between using and paren even when SpaceBeforeParens is !
```
using(FileStream fs = new FileStream(path, FileMode.Open, FileAccess.Read, FileShare.Read, bufferSize : 1))
```
this change simply overcomes this for when using C# settings in the .clang-format file
```
using (FileStream fs = new FileStream(path, FileMode.Open, FileAccess.Read, FileShare.Read, bufferSize : 1))
```
All FormatTests pass..
```
[==========] 688 tests from 21 test cases ran. (88508 ms total)
[ PASSED ] 688 tests.
```
Reviewers: djasper, klimek, owenpan
Reviewed By: owenpan
Subscribers: llvm-commits, cfe-commits
Tags: #clang
Differential Revision: https://reviews.llvm.org/D66662
llvm-svn: 371720
2019-09-12 18:18:53 +08:00
|
|
|
Style.SpaceBeforeParens = FormatStyle::SBPO_Never;
|
|
|
|
verifyFormat("public void foo() {\n"
|
|
|
|
" using(StreamWriter sw = new StreamWriter(filenameB)) {}\n"
|
|
|
|
"}",
|
|
|
|
Style);
|
2019-10-04 16:10:22 +08:00
|
|
|
|
|
|
|
verifyFormat("using(StreamWriter sw = new StreamWriter(filenameB)) {}",
|
|
|
|
Style);
|
[clang-format] [PR43100] clang-format C# support does not add a space between "using" and paren
Summary:
Addresses https://bugs.llvm.org/show_bug.cgi?id=43100
Formatting using statement in C# with clang-format removes the space between using and paren even when SpaceBeforeParens is !
```
using(FileStream fs = new FileStream(path, FileMode.Open, FileAccess.Read, FileShare.Read, bufferSize : 1))
```
this change simply overcomes this for when using C# settings in the .clang-format file
```
using (FileStream fs = new FileStream(path, FileMode.Open, FileAccess.Read, FileShare.Read, bufferSize : 1))
```
All FormatTests pass..
```
[==========] 688 tests from 21 test cases ran. (88508 ms total)
[ PASSED ] 688 tests.
```
Reviewers: djasper, klimek, owenpan
Reviewed By: owenpan
Subscribers: llvm-commits, cfe-commits
Tags: #clang
Differential Revision: https://reviews.llvm.org/D66662
llvm-svn: 371720
2019-09-12 18:18:53 +08:00
|
|
|
}
|
|
|
|
|
[clang-format] Add basic support for formatting C# files
Summary:
This revision adds basic support for formatting C# files with clang-format, I know the barrier to entry is high here so I'm sending this revision in to test the water as to whether this might be something we'd consider landing.
Tracking in Bugzilla as:
https://bugs.llvm.org/show_bug.cgi?id=40850
Justification:
C# code just looks ugly in comparison to the C++ code in our source tree which is clang-formatted.
I've struggled with Visual Studio reformatting to get a clean and consistent style, I want to format our C# code on saving like I do now for C++ and i want it to have the same style as defined in our .clang-format file, so it consistent as it can be with C++. (Braces/Breaking/Spaces/Indent etc..)
Using clang format without this patch leaves the code in a bad state, sometimes when the BreakStringLiterals is set, it fails to compile.
Mostly the C# is similar to Java, except instead of JavaAnnotations I try to reuse the TT_AttributeSquare.
Almost the most valuable portion is to have a new Language in order to partition the configuration for C# within a common .clang-format file, with the auto detection on the .cs extension. But there are other C# specific styles that could be added later if this is accepted. in particular how `{ set;get }` is formatted.
Reviewers: djasper, klimek, krasimir, benhamilton, JonasToth
Reviewed By: klimek
Subscribers: llvm-commits, mgorny, jdoerfert, cfe-commits
Tags: #clang, #clang-tools-extra
Differential Revision: https://reviews.llvm.org/D58404
llvm-svn: 356662
2019-03-21 21:09:22 +08:00
|
|
|
TEST_F(FormatTestCSharp, CSharpRegions) {
|
|
|
|
verifyFormat("#region aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa aaaaaaaaaaaaaaaaa "
|
|
|
|
"aaaaaaaaaaaaaaa long region");
|
|
|
|
}
|
|
|
|
|
|
|
|
TEST_F(FormatTestCSharp, CSharpKeyWordEscaping) {
|
|
|
|
verifyFormat("public enum var { none, @string, bool, @enum }");
|
|
|
|
}
|
|
|
|
|
|
|
|
TEST_F(FormatTestCSharp, CSharpNullCoalescing) {
|
|
|
|
verifyFormat("var test = ABC ?? DEF");
|
|
|
|
verifyFormat("string myname = name ?? \"ABC\";");
|
|
|
|
verifyFormat("return _name ?? \"DEF\";");
|
|
|
|
}
|
|
|
|
|
2019-10-04 15:56:49 +08:00
|
|
|
TEST_F(FormatTestCSharp, AttributesIndentation) {
|
|
|
|
FormatStyle Style = getMicrosoftStyle(FormatStyle::LK_CSharp);
|
|
|
|
Style.AlwaysBreakAfterReturnType = FormatStyle::RTBS_None;
|
|
|
|
|
|
|
|
verifyFormat("[STAThread]\n"
|
|
|
|
"static void Main(string[] args)\n"
|
|
|
|
"{\n"
|
|
|
|
"}",
|
|
|
|
Style);
|
|
|
|
|
|
|
|
verifyFormat("[STAThread]\n"
|
|
|
|
"void "
|
|
|
|
"veryLooooooooooooooongFunctionName(string[] args)\n"
|
|
|
|
"{\n"
|
|
|
|
"}",
|
|
|
|
Style);
|
|
|
|
|
|
|
|
verifyFormat("[STAThread]\n"
|
|
|
|
"veryLoooooooooooooooooooongReturnType "
|
|
|
|
"veryLooooooooooooooongFunctionName(string[] args)\n"
|
|
|
|
"{\n"
|
|
|
|
"}",
|
|
|
|
Style);
|
|
|
|
|
|
|
|
verifyFormat("[SuppressMessage(\"A\", \"B\", Justification = \"C\")]\n"
|
|
|
|
"public override X Y()\n"
|
|
|
|
"{\n"
|
|
|
|
"}\n",
|
|
|
|
Style);
|
|
|
|
|
|
|
|
verifyFormat("[SuppressMessage]\n"
|
|
|
|
"public X Y()\n"
|
|
|
|
"{\n"
|
|
|
|
"}\n",
|
|
|
|
Style);
|
|
|
|
|
|
|
|
verifyFormat("[SuppressMessage]\n"
|
|
|
|
"public override X Y()\n"
|
|
|
|
"{\n"
|
|
|
|
"}\n",
|
|
|
|
Style);
|
|
|
|
|
|
|
|
verifyFormat("public A(B b) : base(b)\n"
|
|
|
|
"{\n"
|
|
|
|
" [SuppressMessage]\n"
|
|
|
|
" public override X Y()\n"
|
|
|
|
" {\n"
|
|
|
|
" }\n"
|
|
|
|
"}\n",
|
|
|
|
Style);
|
2019-12-21 01:04:49 +08:00
|
|
|
|
|
|
|
verifyFormat("public A : Base\n"
|
|
|
|
"{\n"
|
|
|
|
"}\n"
|
|
|
|
"[Test]\n"
|
|
|
|
"public Foo()\n"
|
|
|
|
"{\n"
|
|
|
|
"}\n",
|
|
|
|
Style);
|
|
|
|
|
|
|
|
verifyFormat("namespace\n"
|
|
|
|
"{\n"
|
|
|
|
"public A : Base\n"
|
|
|
|
"{\n"
|
|
|
|
"}\n"
|
|
|
|
"[Test]\n"
|
|
|
|
"public Foo()\n"
|
|
|
|
"{\n"
|
|
|
|
"}\n"
|
|
|
|
"}\n",
|
|
|
|
Style);
|
2019-10-04 15:56:49 +08:00
|
|
|
}
|
|
|
|
|
2019-10-04 16:10:22 +08:00
|
|
|
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);
|
|
|
|
}
|
|
|
|
|
[clang-format] Add basic support for formatting C# files
Summary:
This revision adds basic support for formatting C# files with clang-format, I know the barrier to entry is high here so I'm sending this revision in to test the water as to whether this might be something we'd consider landing.
Tracking in Bugzilla as:
https://bugs.llvm.org/show_bug.cgi?id=40850
Justification:
C# code just looks ugly in comparison to the C++ code in our source tree which is clang-formatted.
I've struggled with Visual Studio reformatting to get a clean and consistent style, I want to format our C# code on saving like I do now for C++ and i want it to have the same style as defined in our .clang-format file, so it consistent as it can be with C++. (Braces/Breaking/Spaces/Indent etc..)
Using clang format without this patch leaves the code in a bad state, sometimes when the BreakStringLiterals is set, it fails to compile.
Mostly the C# is similar to Java, except instead of JavaAnnotations I try to reuse the TT_AttributeSquare.
Almost the most valuable portion is to have a new Language in order to partition the configuration for C# within a common .clang-format file, with the auto detection on the .cs extension. But there are other C# specific styles that could be added later if this is accepted. in particular how `{ set;get }` is formatted.
Reviewers: djasper, klimek, krasimir, benhamilton, JonasToth
Reviewed By: klimek
Subscribers: llvm-commits, mgorny, jdoerfert, cfe-commits
Tags: #clang, #clang-tools-extra
Differential Revision: https://reviews.llvm.org/D58404
llvm-svn: 356662
2019-03-21 21:09:22 +08:00
|
|
|
} // namespace format
|
|
|
|
} // end namespace clang
|