Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
lwm1986
roslyn
提交
6495e6fe
R
roslyn
项目概览
lwm1986
/
roslyn
与 Fork 源项目一致
从无法访问的项目Fork
通知
1
Star
0
Fork
0
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
0
列表
看板
标记
里程碑
合并请求
0
DevOps
流水线
流水线任务
计划
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
R
roslyn
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
0
Issue
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
Pages
DevOps
DevOps
流水线
流水线任务
计划
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
流水线任务
提交
Issue看板
体验新版 GitCode,发现更多精彩内容 >>
提交
6495e6fe
编写于
2月 14, 2020
作者:
S
Sam Harwell
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
Convert AddAccessibilityModifiersTests to the new test library
上级
4a7d283e
变更
1
隐藏空白更改
内联
并排
Showing
1 changed file
with
257 addition
and
54 deletion
+257
-54
src/EditorFeatures/CSharpTest/AddAccessibilityModifiers/AddAccessibilityModifiersTests.cs
...dAccessibilityModifiers/AddAccessibilityModifiersTests.cs
+257
-54
未找到文件。
src/EditorFeatures/CSharpTest/AddAccessibilityModifiers/AddAccessibilityModifiersTests.cs
浏览文件 @
6495e6fe
...
...
@@ -2,16 +2,18 @@
// The .NET Foundation licenses this file to you under the MIT license.
// See the LICENSE file in the project root for more information.
using
System.Collections.Generic
;
using
System.Threading.Tasks
;
using
Microsoft.CodeAnalysis.CodeFixes
;
using
Microsoft.CodeAnalysis.CodeStyle
;
using
Microsoft.CodeAnalysis.CSharp.AddAccessibilityModifiers
;
using
Microsoft.CodeAnalysis.Diagnostics
;
using
Microsoft.CodeAnalysis.Editor.CSharp.UnitTests.Diagnostics
;
using
Microsoft.CodeAnalysis.Options
;
using
Microsoft.CodeAnalysis.Test.Utilities
;
using
Microsoft.CodeAnalysis.Testing
;
using
Xunit
;
using
VerifyCS
=
Microsoft
.
CodeAnalysis
.
Editor
.
UnitTests
.
CodeActions
.
CSharpCodeFixVerifier
<
Microsoft
.
CodeAnalysis
.
CSharp
.
AddAccessibilityModifiers
.
CSharpAddAccessibilityModifiersDiagnosticAnalyzer
,
Microsoft
.
CodeAnalysis
.
CSharp
.
AddAccessibilityModifiers
.
CSharpAddAccessibilityModifiersCodeFixProvider
>;
namespace
Microsoft.CodeAnalysis.Editor.CSharp.UnitTests.AddAccessibilityModifiers
{
...
...
@@ -20,56 +22,58 @@ public partial class AddAccessibilityModifiersTests : AbstractCSharpDiagnosticPr
internal
override
(
DiagnosticAnalyzer
,
CodeFixProvider
)
CreateDiagnosticProviderAndFixer
(
Workspace
workspace
)
=>
(
new
CSharpAddAccessibilityModifiersDiagnosticAnalyzer
(),
new
CSharpAddAccessibilityModifiersCodeFixProvider
());
private
IDictionary
<
OptionKey
,
object
>
OmitDefaultModifiers
=>
OptionsSet
(
SingleOption
(
CodeStyleOptions
.
RequireAccessibilityModifiers
,
AccessibilityModifiersRequired
.
OmitIfDefault
,
NotificationOption
.
Suggestion
));
[
Fact
,
Trait
(
Traits
.
Feature
,
Traits
.
Features
.
CodeActionsAddAccessibilityModifiers
)]
public
async
Task
TestAllConstructs
()
{
await
TestInRegularAndScriptAsync
(
@"
await
new
VerifyCS
.
Test
{
TestState
=
{
Sources
=
{
@"
namespace Outer
{
namespace Inner1.Inner2
{
class
{|FixAllInDocument:C|}
class
[|C|]
{
class
NestedClass
{ }
class
[|NestedClass|]
{ }
struct
NestedStruct
{ }
struct
[|NestedStruct|]
{ }
int
f1
;
int
f2
, f3;
int
[|f1|]
;
int
[|f2|]
, f3;
public int f4;
event Action
e1
, e2;
event Action
[|e1|]
, e2;
public event Action e3;
event Action
e4
{ add { } remove { } }
event Action
[|e4|]
{ add { } remove { } }
public event Action e5 { add { } remove { } }
event Action I.e6 { add { } remote { } }
static C() { }
C
() { }
[|C|]
() { }
public C(int i) { }
~C() { }
void
M1
() { }
void
[|M1|]
() { }
public void M2() { }
void I.M3() { }
partial void M4() { }
int
P1
{ get; }
int
[|P1|]
{ get; }
public int P2 { get; }
int I.P3 { get; }
int
this
[int i] { get; }
int
[|this|]
[int i] { get; }
public int this[string s] { get; }
int I.this[bool b] { get; }
}
interface
I
interface
[|I|]
{
event Action e6;
void M3();
...
...
@@ -77,20 +81,63 @@ interface I
int this[bool b] { get; }
}
delegate void
D
();
delegate void
[|D|]
();
enum
E
enum
[|E|]
{
EMember
}
}
}"
,
@"
},
ExpectedDiagnostics
=
{
// Test0.cs(16,19): error CS0246: The type or namespace name 'Action' could not be found (are you missing a using directive or an assembly reference?)
DiagnosticResult
.
CompilerError
(
"CS0246"
).
WithSpan
(
16
,
19
,
16
,
25
).
WithArguments
(
"Action"
),
// Test0.cs(17,26): error CS0246: The type or namespace name 'Action' could not be found (are you missing a using directive or an assembly reference?)
DiagnosticResult
.
CompilerError
(
"CS0246"
).
WithSpan
(
17
,
26
,
17
,
32
).
WithArguments
(
"Action"
),
// Test0.cs(19,19): error CS0246: The type or namespace name 'Action' could not be found (are you missing a using directive or an assembly reference?)
DiagnosticResult
.
CompilerError
(
"CS0246"
).
WithSpan
(
19
,
19
,
19
,
25
).
WithArguments
(
"Action"
),
// Test0.cs(20,26): error CS0246: The type or namespace name 'Action' could not be found (are you missing a using directive or an assembly reference?)
DiagnosticResult
.
CompilerError
(
"CS0246"
).
WithSpan
(
20
,
26
,
20
,
32
).
WithArguments
(
"Action"
),
// Test0.cs(21,19): error CS0246: The type or namespace name 'Action' could not be found (are you missing a using directive or an assembly reference?)
DiagnosticResult
.
CompilerError
(
"CS0246"
).
WithSpan
(
21
,
19
,
21
,
25
).
WithArguments
(
"Action"
),
// Test0.cs(21,26): error CS0540: 'C.I.e6': containing type does not implement interface 'I'
DiagnosticResult
.
CompilerError
(
"CS0540"
).
WithSpan
(
21
,
26
,
21
,
27
).
WithArguments
(
"Outer.Inner1.Inner2.C.Outer.Inner1.Inner2.I.e6"
,
"Outer.Inner1.Inner2.I"
),
// Test0.cs(21,28): error CS0065: 'C.I.e6': event property must have both add and remove accessors
DiagnosticResult
.
CompilerError
(
"CS0065"
).
WithSpan
(
21
,
28
,
21
,
30
).
WithArguments
(
"Outer.Inner1.Inner2.C.Outer.Inner1.Inner2.I.e6"
),
// Test0.cs(21,41): error CS1055: An add or remove accessor expected
DiagnosticResult
.
CompilerError
(
"CS1055"
).
WithSpan
(
21
,
41
,
21
,
47
),
// Test0.cs(31,18): error CS0540: 'C.I.M3()': containing type does not implement interface 'I'
DiagnosticResult
.
CompilerError
(
"CS0540"
).
WithSpan
(
31
,
18
,
31
,
19
).
WithArguments
(
"Outer.Inner1.Inner2.C.Outer.Inner1.Inner2.I.M3()"
,
"Outer.Inner1.Inner2.I"
),
// Test0.cs(32,26): error CS0751: A partial method must be declared within a partial class, partial struct, or partial interface
DiagnosticResult
.
CompilerError
(
"CS0751"
).
WithSpan
(
32
,
26
,
32
,
28
),
// Test0.cs(32,26): error CS0759: No defining declaration found for implementing declaration of partial method 'C.M4()'
DiagnosticResult
.
CompilerError
(
"CS0759"
).
WithSpan
(
32
,
26
,
32
,
28
).
WithArguments
(
"Outer.Inner1.Inner2.C.M4()"
),
// Test0.cs(36,17): error CS0540: 'C.I.P3': containing type does not implement interface 'I'
DiagnosticResult
.
CompilerError
(
"CS0540"
).
WithSpan
(
36
,
17
,
36
,
18
).
WithArguments
(
"Outer.Inner1.Inner2.C.Outer.Inner1.Inner2.I.P3"
,
"Outer.Inner1.Inner2.I"
),
// Test0.cs(38,31): error CS0501: 'C.this[int].get' must declare a body because it is not marked abstract, extern, or partial
DiagnosticResult
.
CompilerError
(
"CS0501"
).
WithSpan
(
38
,
31
,
38
,
34
).
WithArguments
(
"Outer.Inner1.Inner2.C.this[int].get"
),
// Test0.cs(39,41): error CS0501: 'C.this[string].get' must declare a body because it is not marked abstract, extern, or partial
DiagnosticResult
.
CompilerError
(
"CS0501"
).
WithSpan
(
39
,
41
,
39
,
44
).
WithArguments
(
"Outer.Inner1.Inner2.C.this[string].get"
),
// Test0.cs(40,17): error CS0540: 'C.I.this[bool]': containing type does not implement interface 'I'
DiagnosticResult
.
CompilerError
(
"CS0540"
).
WithSpan
(
40
,
17
,
40
,
18
).
WithArguments
(
"Outer.Inner1.Inner2.C.Outer.Inner1.Inner2.I.this[bool]"
,
"Outer.Inner1.Inner2.I"
),
// Test0.cs(40,34): error CS0501: 'C.I.this[bool].get' must declare a body because it is not marked abstract, extern, or partial
DiagnosticResult
.
CompilerError
(
"CS0501"
).
WithSpan
(
40
,
34
,
40
,
37
).
WithArguments
(
"Outer.Inner1.Inner2.C.Outer.Inner1.Inner2.I.this[bool].get"
),
// Test0.cs(45,19): error CS0246: The type or namespace name 'Action' could not be found (are you missing a using directive or an assembly reference?)
DiagnosticResult
.
CompilerError
(
"CS0246"
).
WithSpan
(
45
,
19
,
45
,
25
).
WithArguments
(
"Action"
),
},
},
FixedState
=
{
Sources
=
{
@"
namespace Outer
{
namespace Inner1.Inner2
{
internal class
{|FixAllInDocument:C|}
internal class
C
{
private class NestedClass { }
...
...
@@ -143,13 +190,53 @@ internal enum E
EMember
}
}
}"
);
}"
,
},
ExpectedDiagnostics
=
{
// Test0.cs(16,27): error CS0246: The type or namespace name 'Action' could not be found (are you missing a using directive or an assembly reference?)
DiagnosticResult
.
CompilerError
(
"CS0246"
).
WithSpan
(
16
,
27
,
16
,
33
).
WithArguments
(
"Action"
),
// Test0.cs(17,26): error CS0246: The type or namespace name 'Action' could not be found (are you missing a using directive or an assembly reference?)
DiagnosticResult
.
CompilerError
(
"CS0246"
).
WithSpan
(
17
,
26
,
17
,
32
).
WithArguments
(
"Action"
),
// Test0.cs(19,27): error CS0246: The type or namespace name 'Action' could not be found (are you missing a using directive or an assembly reference?)
DiagnosticResult
.
CompilerError
(
"CS0246"
).
WithSpan
(
19
,
27
,
19
,
33
).
WithArguments
(
"Action"
),
// Test0.cs(20,26): error CS0246: The type or namespace name 'Action' could not be found (are you missing a using directive or an assembly reference?)
DiagnosticResult
.
CompilerError
(
"CS0246"
).
WithSpan
(
20
,
26
,
20
,
32
).
WithArguments
(
"Action"
),
// Test0.cs(21,19): error CS0246: The type or namespace name 'Action' could not be found (are you missing a using directive or an assembly reference?)
DiagnosticResult
.
CompilerError
(
"CS0246"
).
WithSpan
(
21
,
19
,
21
,
25
).
WithArguments
(
"Action"
),
// Test0.cs(21,26): error CS0540: 'C.I.e6': containing type does not implement interface 'I'
DiagnosticResult
.
CompilerError
(
"CS0540"
).
WithSpan
(
21
,
26
,
21
,
27
).
WithArguments
(
"Outer.Inner1.Inner2.C.Outer.Inner1.Inner2.I.e6"
,
"Outer.Inner1.Inner2.I"
),
// Test0.cs(21,28): error CS0065: 'C.I.e6': event property must have both add and remove accessors
DiagnosticResult
.
CompilerError
(
"CS0065"
).
WithSpan
(
21
,
28
,
21
,
30
).
WithArguments
(
"Outer.Inner1.Inner2.C.Outer.Inner1.Inner2.I.e6"
),
// Test0.cs(21,41): error CS1055: An add or remove accessor expected
DiagnosticResult
.
CompilerError
(
"CS1055"
).
WithSpan
(
21
,
41
,
21
,
47
),
// Test0.cs(32,18): error CS0540: 'C.I.M3()': containing type does not implement interface 'I'
DiagnosticResult
.
CompilerError
(
"CS0540"
).
WithSpan
(
32
,
18
,
32
,
19
).
WithArguments
(
"Outer.Inner1.Inner2.C.Outer.Inner1.Inner2.I.M3()"
,
"Outer.Inner1.Inner2.I"
),
// Test0.cs(33,26): error CS0751: A partial method must be declared within a partial class, partial struct, or partial interface
DiagnosticResult
.
CompilerError
(
"CS0751"
).
WithSpan
(
33
,
26
,
33
,
28
),
// Test0.cs(33,26): error CS0759: No defining declaration found for implementing declaration of partial method 'C.M4()'
DiagnosticResult
.
CompilerError
(
"CS0759"
).
WithSpan
(
33
,
26
,
33
,
28
).
WithArguments
(
"Outer.Inner1.Inner2.C.M4()"
),
// Test0.cs(37,17): error CS0540: 'C.I.P3': containing type does not implement interface 'I'
DiagnosticResult
.
CompilerError
(
"CS0540"
).
WithSpan
(
37
,
17
,
37
,
18
).
WithArguments
(
"Outer.Inner1.Inner2.C.Outer.Inner1.Inner2.I.P3"
,
"Outer.Inner1.Inner2.I"
),
// Test0.cs(39,39): error CS0501: 'C.this[int].get' must declare a body because it is not marked abstract, extern, or partial
DiagnosticResult
.
CompilerError
(
"CS0501"
).
WithSpan
(
39
,
39
,
39
,
42
).
WithArguments
(
"Outer.Inner1.Inner2.C.this[int].get"
),
// Test0.cs(40,41): error CS0501: 'C.this[string].get' must declare a body because it is not marked abstract, extern, or partial
DiagnosticResult
.
CompilerError
(
"CS0501"
).
WithSpan
(
40
,
41
,
40
,
44
).
WithArguments
(
"Outer.Inner1.Inner2.C.this[string].get"
),
// Test0.cs(41,17): error CS0540: 'C.I.this[bool]': containing type does not implement interface 'I'
DiagnosticResult
.
CompilerError
(
"CS0540"
).
WithSpan
(
41
,
17
,
41
,
18
).
WithArguments
(
"Outer.Inner1.Inner2.C.Outer.Inner1.Inner2.I.this[bool]"
,
"Outer.Inner1.Inner2.I"
),
// Test0.cs(41,34): error CS0501: 'C.I.this[bool].get' must declare a body because it is not marked abstract, extern, or partial
DiagnosticResult
.
CompilerError
(
"CS0501"
).
WithSpan
(
41
,
34
,
41
,
37
).
WithArguments
(
"Outer.Inner1.Inner2.C.Outer.Inner1.Inner2.I.this[bool].get"
),
// Test0.cs(46,19): error CS0246: The type or namespace name 'Action' could not be found (are you missing a using directive or an assembly reference?)
DiagnosticResult
.
CompilerError
(
"CS0246"
).
WithSpan
(
46
,
19
,
46
,
25
).
WithArguments
(
"Action"
),
},
},
}.
RunAsync
();
}
[
Fact
,
Trait
(
Traits
.
Feature
,
Traits
.
Features
.
CodeActionsAddAccessibilityModifiers
)]
public
async
Task
TestRefStructs
()
{
await
TestInRegularAndScript
Async
(
@"
await
VerifyCS
.
VerifyCodeFix
Async
(
@"
namespace Test
{
ref struct [|S1|] { }
...
...
@@ -163,7 +250,7 @@ namespace Test
[
Fact
,
Trait
(
Traits
.
Feature
,
Traits
.
Features
.
CodeActionsAddAccessibilityModifiers
)]
public
async
Task
TestReadOnlyStructs
()
{
await
TestInRegularAndScript
Async
(
@"
await
VerifyCS
.
VerifyCodeFix
Async
(
@"
namespace Test
{
readonly struct [|S1|] { }
...
...
@@ -177,51 +264,56 @@ namespace Test
[
Fact
,
Trait
(
Traits
.
Feature
,
Traits
.
Features
.
CodeActionsAddAccessibilityModifiers
)]
public
async
Task
TestAllConstructsWithOmit
()
{
await
TestInRegularAndScriptAsync
(
@"
await
new
VerifyCS
.
Test
{
TestState
=
{
Sources
=
{
@"
namespace Outer
{
namespace Inner1.Inner2
{
internal class
{|FixAllInDocument:C|}
internal class
[|C|]
{
private class
NestedClass
{ }
private class
[|NestedClass|]
{ }
private struct
NestedStruct
{ }
private struct
[|NestedStruct|]
{ }
private int
f1
;
private int
f2
, f3;
private int
[|f1|]
;
private int
[|f2|]
, f3;
public int f4;
private event Action
e1
, e2;
private event Action
[|e1|]
, e2;
public event Action e3;
private event Action
e4
{ add { } remove { } }
private event Action
[|e4|]
{ add { } remove { } }
public event Action e5 { add { } remove { } }
event Action I.e6 { add { } remote { } }
static C() { }
private
C
() { }
private
[|C|]
() { }
public C(int i) { }
~C() { }
private void
M1
() { }
private void
[|M1|]
() { }
public void M2() { }
void I.M3() { }
partial void M4() { }
private int
P1
{ get; }
private int
[|P1|]
{ get; }
public int P2 { get; }
int I.P3 { get; }
private int
this
[int i] { get; }
private int
[|this|]
[int i] { get; }
public int this[string s] { get; }
int I.this[bool b] { get; }
}
internal interface
I
internal interface
[|I|]
{
event Action e6;
void M3();
...
...
@@ -229,20 +321,63 @@ internal interface I
int this[bool b] { get; }
}
internal delegate void
D
();
internal delegate void
[|D|]
();
internal enum
E
internal enum
[|E|]
{
EMember
}
}
}"
,
@"
},
ExpectedDiagnostics
=
{
// Test0.cs(16,27): error CS0246: The type or namespace name 'Action' could not be found (are you missing a using directive or an assembly reference?)
DiagnosticResult
.
CompilerError
(
"CS0246"
).
WithSpan
(
16
,
27
,
16
,
33
).
WithArguments
(
"Action"
),
// Test0.cs(17,26): error CS0246: The type or namespace name 'Action' could not be found (are you missing a using directive or an assembly reference?)
DiagnosticResult
.
CompilerError
(
"CS0246"
).
WithSpan
(
17
,
26
,
17
,
32
).
WithArguments
(
"Action"
),
// Test0.cs(19,27): error CS0246: The type or namespace name 'Action' could not be found (are you missing a using directive or an assembly reference?)
DiagnosticResult
.
CompilerError
(
"CS0246"
).
WithSpan
(
19
,
27
,
19
,
33
).
WithArguments
(
"Action"
),
// Test0.cs(20,26): error CS0246: The type or namespace name 'Action' could not be found (are you missing a using directive or an assembly reference?)
DiagnosticResult
.
CompilerError
(
"CS0246"
).
WithSpan
(
20
,
26
,
20
,
32
).
WithArguments
(
"Action"
),
// Test0.cs(21,19): error CS0246: The type or namespace name 'Action' could not be found (are you missing a using directive or an assembly reference?)
DiagnosticResult
.
CompilerError
(
"CS0246"
).
WithSpan
(
21
,
19
,
21
,
25
).
WithArguments
(
"Action"
),
// Test0.cs(21,26): error CS0540: 'C.I.e6': containing type does not implement interface 'I'
DiagnosticResult
.
CompilerError
(
"CS0540"
).
WithSpan
(
21
,
26
,
21
,
27
).
WithArguments
(
"Outer.Inner1.Inner2.C.Outer.Inner1.Inner2.I.e6"
,
"Outer.Inner1.Inner2.I"
),
// Test0.cs(21,28): error CS0065: 'C.I.e6': event property must have both add and remove accessors
DiagnosticResult
.
CompilerError
(
"CS0065"
).
WithSpan
(
21
,
28
,
21
,
30
).
WithArguments
(
"Outer.Inner1.Inner2.C.Outer.Inner1.Inner2.I.e6"
),
// Test0.cs(21,41): error CS1055: An add or remove accessor expected
DiagnosticResult
.
CompilerError
(
"CS1055"
).
WithSpan
(
21
,
41
,
21
,
47
),
// Test0.cs(32,18): error CS0540: 'C.I.M3()': containing type does not implement interface 'I'
DiagnosticResult
.
CompilerError
(
"CS0540"
).
WithSpan
(
32
,
18
,
32
,
19
).
WithArguments
(
"Outer.Inner1.Inner2.C.Outer.Inner1.Inner2.I.M3()"
,
"Outer.Inner1.Inner2.I"
),
// Test0.cs(33,26): error CS0751: A partial method must be declared within a partial class, partial struct, or partial interface
DiagnosticResult
.
CompilerError
(
"CS0751"
).
WithSpan
(
33
,
26
,
33
,
28
),
// Test0.cs(33,26): error CS0759: No defining declaration found for implementing declaration of partial method 'C.M4()'
DiagnosticResult
.
CompilerError
(
"CS0759"
).
WithSpan
(
33
,
26
,
33
,
28
).
WithArguments
(
"Outer.Inner1.Inner2.C.M4()"
),
// Test0.cs(37,17): error CS0540: 'C.I.P3': containing type does not implement interface 'I'
DiagnosticResult
.
CompilerError
(
"CS0540"
).
WithSpan
(
37
,
17
,
37
,
18
).
WithArguments
(
"Outer.Inner1.Inner2.C.Outer.Inner1.Inner2.I.P3"
,
"Outer.Inner1.Inner2.I"
),
// Test0.cs(39,39): error CS0501: 'C.this[int].get' must declare a body because it is not marked abstract, extern, or partial
DiagnosticResult
.
CompilerError
(
"CS0501"
).
WithSpan
(
39
,
39
,
39
,
42
).
WithArguments
(
"Outer.Inner1.Inner2.C.this[int].get"
),
// Test0.cs(40,41): error CS0501: 'C.this[string].get' must declare a body because it is not marked abstract, extern, or partial
DiagnosticResult
.
CompilerError
(
"CS0501"
).
WithSpan
(
40
,
41
,
40
,
44
).
WithArguments
(
"Outer.Inner1.Inner2.C.this[string].get"
),
// Test0.cs(41,17): error CS0540: 'C.I.this[bool]': containing type does not implement interface 'I'
DiagnosticResult
.
CompilerError
(
"CS0540"
).
WithSpan
(
41
,
17
,
41
,
18
).
WithArguments
(
"Outer.Inner1.Inner2.C.Outer.Inner1.Inner2.I.this[bool]"
,
"Outer.Inner1.Inner2.I"
),
// Test0.cs(41,34): error CS0501: 'C.I.this[bool].get' must declare a body because it is not marked abstract, extern, or partial
DiagnosticResult
.
CompilerError
(
"CS0501"
).
WithSpan
(
41
,
34
,
41
,
37
).
WithArguments
(
"Outer.Inner1.Inner2.C.Outer.Inner1.Inner2.I.this[bool].get"
),
// Test0.cs(46,19): error CS0246: The type or namespace name 'Action' could not be found (are you missing a using directive or an assembly reference?)
DiagnosticResult
.
CompilerError
(
"CS0246"
).
WithSpan
(
46
,
19
,
46
,
25
).
WithArguments
(
"Action"
),
},
},
FixedState
=
{
Sources
=
{
@"
namespace Outer
{
namespace Inner1.Inner2
{
class
{|FixAllInDocument:C|}
class
C
{
class NestedClass { }
...
...
@@ -295,43 +430,111 @@ enum E
EMember
}
}
}"
,
options
:
OmitDefaultModifiers
);
}"
,
},
ExpectedDiagnostics
=
{
// Test0.cs(16,19): error CS0246: The type or namespace name 'Action' could not be found (are you missing a using directive or an assembly reference?)
DiagnosticResult
.
CompilerError
(
"CS0246"
).
WithSpan
(
16
,
19
,
16
,
25
).
WithArguments
(
"Action"
),
// Test0.cs(17,26): error CS0246: The type or namespace name 'Action' could not be found (are you missing a using directive or an assembly reference?)
DiagnosticResult
.
CompilerError
(
"CS0246"
).
WithSpan
(
17
,
26
,
17
,
32
).
WithArguments
(
"Action"
),
// Test0.cs(19,19): error CS0246: The type or namespace name 'Action' could not be found (are you missing a using directive or an assembly reference?)
DiagnosticResult
.
CompilerError
(
"CS0246"
).
WithSpan
(
19
,
19
,
19
,
25
).
WithArguments
(
"Action"
),
// Test0.cs(20,26): error CS0246: The type or namespace name 'Action' could not be found (are you missing a using directive or an assembly reference?)
DiagnosticResult
.
CompilerError
(
"CS0246"
).
WithSpan
(
20
,
26
,
20
,
32
).
WithArguments
(
"Action"
),
// Test0.cs(21,19): error CS0246: The type or namespace name 'Action' could not be found (are you missing a using directive or an assembly reference?)
DiagnosticResult
.
CompilerError
(
"CS0246"
).
WithSpan
(
21
,
19
,
21
,
25
).
WithArguments
(
"Action"
),
// Test0.cs(21,26): error CS0540: 'C.I.e6': containing type does not implement interface 'I'
DiagnosticResult
.
CompilerError
(
"CS0540"
).
WithSpan
(
21
,
26
,
21
,
27
).
WithArguments
(
"Outer.Inner1.Inner2.C.Outer.Inner1.Inner2.I.e6"
,
"Outer.Inner1.Inner2.I"
),
// Test0.cs(21,28): error CS0065: 'C.I.e6': event property must have both add and remove accessors
DiagnosticResult
.
CompilerError
(
"CS0065"
).
WithSpan
(
21
,
28
,
21
,
30
).
WithArguments
(
"Outer.Inner1.Inner2.C.Outer.Inner1.Inner2.I.e6"
),
// Test0.cs(21,41): error CS1055: An add or remove accessor expected
DiagnosticResult
.
CompilerError
(
"CS1055"
).
WithSpan
(
21
,
41
,
21
,
47
),
// Test0.cs(32,18): error CS0540: 'C.I.M3()': containing type does not implement interface 'I'
DiagnosticResult
.
CompilerError
(
"CS0540"
).
WithSpan
(
32
,
18
,
32
,
19
).
WithArguments
(
"Outer.Inner1.Inner2.C.Outer.Inner1.Inner2.I.M3()"
,
"Outer.Inner1.Inner2.I"
),
// Test0.cs(33,26): error CS0751: A partial method must be declared within a partial class, partial struct, or partial interface
DiagnosticResult
.
CompilerError
(
"CS0751"
).
WithSpan
(
33
,
26
,
33
,
28
),
// Test0.cs(33,26): error CS0759: No defining declaration found for implementing declaration of partial method 'C.M4()'
DiagnosticResult
.
CompilerError
(
"CS0759"
).
WithSpan
(
33
,
26
,
33
,
28
).
WithArguments
(
"Outer.Inner1.Inner2.C.M4()"
),
// Test0.cs(37,17): error CS0540: 'C.I.P3': containing type does not implement interface 'I'
DiagnosticResult
.
CompilerError
(
"CS0540"
).
WithSpan
(
37
,
17
,
37
,
18
).
WithArguments
(
"Outer.Inner1.Inner2.C.Outer.Inner1.Inner2.I.P3"
,
"Outer.Inner1.Inner2.I"
),
// Test0.cs(39,31): error CS0501: 'C.this[int].get' must declare a body because it is not marked abstract, extern, or partial
DiagnosticResult
.
CompilerError
(
"CS0501"
).
WithSpan
(
39
,
31
,
39
,
34
).
WithArguments
(
"Outer.Inner1.Inner2.C.this[int].get"
),
// Test0.cs(40,41): error CS0501: 'C.this[string].get' must declare a body because it is not marked abstract, extern, or partial
DiagnosticResult
.
CompilerError
(
"CS0501"
).
WithSpan
(
40
,
41
,
40
,
44
).
WithArguments
(
"Outer.Inner1.Inner2.C.this[string].get"
),
// Test0.cs(41,17): error CS0540: 'C.I.this[bool]': containing type does not implement interface 'I'
DiagnosticResult
.
CompilerError
(
"CS0540"
).
WithSpan
(
41
,
17
,
41
,
18
).
WithArguments
(
"Outer.Inner1.Inner2.C.Outer.Inner1.Inner2.I.this[bool]"
,
"Outer.Inner1.Inner2.I"
),
// Test0.cs(41,34): error CS0501: 'C.I.this[bool].get' must declare a body because it is not marked abstract, extern, or partial
DiagnosticResult
.
CompilerError
(
"CS0501"
).
WithSpan
(
41
,
34
,
41
,
37
).
WithArguments
(
"Outer.Inner1.Inner2.C.Outer.Inner1.Inner2.I.this[bool].get"
),
// Test0.cs(46,19): error CS0246: The type or namespace name 'Action' could not be found (are you missing a using directive or an assembly reference?)
DiagnosticResult
.
CompilerError
(
"CS0246"
).
WithSpan
(
46
,
19
,
46
,
25
).
WithArguments
(
"Action"
),
},
},
Options
=
{
{
CodeStyleOptions
.
RequireAccessibilityModifiers
,
AccessibilityModifiersRequired
.
OmitIfDefault
},
},
}.
RunAsync
();
}
[
Fact
,
Trait
(
Traits
.
Feature
,
Traits
.
Features
.
CodeActionsAddAccessibilityModifiers
)]
public
async
Task
TestRefStructsWithOmit
()
{
await
TestInRegularAndScriptAsync
(
@"
await
new
VerifyCS
.
Test
{
TestCode
=
@"
namespace Test
{
internal ref struct [|S1|] { }
}"
,
@"
}"
,
FixedCode
=
@"
namespace Test
{
ref struct S1 { }
}"
,
options
:
OmitDefaultModifiers
);
}"
,
Options
=
{
{
CodeStyleOptions
.
RequireAccessibilityModifiers
,
AccessibilityModifiersRequired
.
OmitIfDefault
},
},
}.
RunAsync
();
}
[
Fact
,
Trait
(
Traits
.
Feature
,
Traits
.
Features
.
CodeActionsAddAccessibilityModifiers
)]
public
async
Task
TestReadOnlyStructsWithOmit
()
{
await
TestInRegularAndScriptAsync
(
@"
await
new
VerifyCS
.
Test
{
TestCode
=
@"
namespace Test
{
internal readonly struct [|S1|] { }
}"
,
@"
}"
,
FixedCode
=
@"
namespace Test
{
readonly struct S1 { }
}"
,
options
:
OmitDefaultModifiers
);
}"
,
Options
=
{
{
CodeStyleOptions
.
RequireAccessibilityModifiers
,
AccessibilityModifiersRequired
.
OmitIfDefault
},
},
}.
RunAsync
();
}
[
Fact
,
Trait
(
Traits
.
Feature
,
Traits
.
Features
.
CodeActionsAddAccessibilityModifiers
)]
public
async
Task
TestClassOutsideNamespace
()
{
await
TestInRegularAndScriptAsync
(
@"
internal class [|C1|] { }"
,
@"
class C1 { }"
,
options
:
OmitDefaultModifiers
);
await
new
VerifyCS
.
Test
{
TestCode
=
@"
internal class [|C1|] { }"
,
FixedCode
=
@"
class C1 { }"
,
Options
=
{
{
CodeStyleOptions
.
RequireAccessibilityModifiers
,
AccessibilityModifiersRequired
.
OmitIfDefault
},
},
}.
RunAsync
();
}
}
}
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录