Skip to content

Commit dddf185

Browse files
committed
Add tests for 'private protected' accessibility
1 parent 5712cf8 commit dddf185

4 files changed

Lines changed: 250 additions & 20 deletions

File tree

StyleCop.Analyzers/StyleCop.Analyzers.Test.CSharp7/DocumentationRules/SA1600CSharp7UnitTests.cs

Lines changed: 205 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,9 +3,214 @@
33

44
namespace StyleCop.Analyzers.Test.CSharp7.DocumentationRules
55
{
6+
using System.Threading.Tasks;
7+
using Microsoft.CodeAnalysis;
8+
using Microsoft.CodeAnalysis.CSharp;
69
using StyleCop.Analyzers.Test.DocumentationRules;
10+
using Xunit;
711

812
public class SA1600CSharp7UnitTests : SA1600UnitTests
913
{
14+
private string currentTestSettings;
15+
16+
[Fact]
17+
public async Task TestPrivateProtectedDelegateWithoutDocumentationAsync()
18+
{
19+
await this.TestNestedDelegateDeclarationDocumentationAsync("private protected", true, false).ConfigureAwait(false);
20+
}
21+
22+
[Fact]
23+
public async Task TestPrivateProtectedDelegateWithDocumentationAsync()
24+
{
25+
await this.TestNestedDelegateDeclarationDocumentationAsync("private protected", false, true).ConfigureAwait(false);
26+
}
27+
28+
[Fact]
29+
public async Task TestPrivateProtectedMethodWithoutDocumentationAsync()
30+
{
31+
await this.TestMethodDeclarationDocumentationAsync("private protected", false, true, false).ConfigureAwait(false);
32+
}
33+
34+
[Fact]
35+
public async Task TestPrivateProtectedMethodWithDocumentationAsync()
36+
{
37+
await this.TestMethodDeclarationDocumentationAsync("private protected", false, false, true).ConfigureAwait(false);
38+
}
39+
40+
[Fact]
41+
public async Task TestPrivateProtectedConstructorWithoutDocumentationAsync()
42+
{
43+
await this.TestConstructorDeclarationDocumentationAsync("private protected", true, false).ConfigureAwait(false);
44+
}
45+
46+
[Fact]
47+
public async Task TestPrivateProtectedConstructorWithDocumentationAsync()
48+
{
49+
await this.TestConstructorDeclarationDocumentationAsync("private protected", false, true).ConfigureAwait(false);
50+
}
51+
52+
[Fact]
53+
public async Task TestPrivateProtectedFieldWithoutDocumentationAsync()
54+
{
55+
await this.TestFieldDeclarationDocumentationAsync("private protected", true, false).ConfigureAwait(false);
56+
57+
// Re-test with the 'documentPrivateElements' setting enabled (doesn't impact fields)
58+
this.currentTestSettings = @"
59+
{
60+
""settings"": {
61+
""documentationRules"": {
62+
""documentPrivateElements"": true
63+
}
64+
}
65+
}
66+
";
67+
68+
await this.TestFieldDeclarationDocumentationAsync("private protected", true, false).ConfigureAwait(false);
69+
70+
// Re-test with the 'documentInternalElements' setting disabled (does impact fields)
71+
this.currentTestSettings = @"
72+
{
73+
""settings"": {
74+
""documentationRules"": {
75+
""documentInternalElements"": false
76+
}
77+
}
78+
}
79+
";
80+
81+
await this.TestFieldDeclarationDocumentationAsync("private protected", false, false).ConfigureAwait(false);
82+
83+
// Re-test with the 'documentPrivateFields' setting enabled (does impact fields)
84+
this.currentTestSettings = @"
85+
{
86+
""settings"": {
87+
""documentationRules"": {
88+
""documentPrivateFields"": true
89+
}
90+
}
91+
}
92+
";
93+
94+
await this.TestFieldDeclarationDocumentationAsync("private protected", true, false).ConfigureAwait(false);
95+
}
96+
97+
[Fact]
98+
public async Task TestPrivateProtectedFieldWithDocumentationAsync()
99+
{
100+
await this.TestFieldDeclarationDocumentationAsync("private protected", false, true).ConfigureAwait(false);
101+
102+
// Re-test with the 'documentPrivateElements' setting enabled (doesn't impact fields)
103+
this.currentTestSettings = @"
104+
{
105+
""settings"": {
106+
""documentationRules"": {
107+
""documentPrivateElements"": true
108+
}
109+
}
110+
}
111+
";
112+
113+
await this.TestFieldDeclarationDocumentationAsync("private protected", false, true).ConfigureAwait(false);
114+
115+
// Re-test with the 'documentInternalElements' setting disabled (does impact fields)
116+
this.currentTestSettings = @"
117+
{
118+
""settings"": {
119+
""documentationRules"": {
120+
""documentInternalElements"": false
121+
}
122+
}
123+
}
124+
";
125+
126+
await this.TestFieldDeclarationDocumentationAsync("private protected", false, true).ConfigureAwait(false);
127+
128+
// Re-test with the 'documentPrivateFields' setting enabled (does impact fields)
129+
this.currentTestSettings = @"
130+
{
131+
""settings"": {
132+
""documentationRules"": {
133+
""documentPrivateFields"": true
134+
}
135+
}
136+
}
137+
";
138+
139+
await this.TestFieldDeclarationDocumentationAsync("private protected", false, true).ConfigureAwait(false);
140+
}
141+
142+
[Fact]
143+
public async Task TestPrivateProtectedPropertyWithoutDocumentationAsync()
144+
{
145+
await this.TestPropertyDeclarationDocumentationAsync("private protected", false, true, false).ConfigureAwait(false);
146+
}
147+
148+
[Fact]
149+
public async Task TestPrivateProtectedPropertyWithDocumentationAsync()
150+
{
151+
await this.TestPropertyDeclarationDocumentationAsync("private protected", false, false, true).ConfigureAwait(false);
152+
}
153+
154+
[Fact]
155+
public async Task TestPrivateProtectedIndexerWithoutDocumentationAsync()
156+
{
157+
await this.TestIndexerDeclarationDocumentationAsync("private protected", false, true, false).ConfigureAwait(false);
158+
}
159+
160+
[Fact]
161+
public async Task TestPrivateProtectedIndexerWithDocumentationAsync()
162+
{
163+
await this.TestIndexerDeclarationDocumentationAsync("private protected", false, false, true).ConfigureAwait(false);
164+
}
165+
166+
[Fact]
167+
public async Task TestPrivateProtectedEventWithoutDocumentationAsync()
168+
{
169+
await this.TestEventDeclarationDocumentationAsync("private protected", false, true, false).ConfigureAwait(false);
170+
}
171+
172+
[Fact]
173+
public async Task TestPrivateProtectedEventWithDocumentationAsync()
174+
{
175+
await this.TestEventDeclarationDocumentationAsync("private protected", false, false, true).ConfigureAwait(false);
176+
}
177+
178+
[Fact]
179+
public async Task TestPrivateProtectedEventFieldWithoutDocumentationAsync()
180+
{
181+
await this.TestEventFieldDeclarationDocumentationAsync("private protected", true, false).ConfigureAwait(false);
182+
}
183+
184+
[Fact]
185+
public async Task TestPrivateProtectedEventFieldWithDocumentationAsync()
186+
{
187+
await this.TestEventFieldDeclarationDocumentationAsync("private protected", false, true).ConfigureAwait(false);
188+
}
189+
190+
protected override string GetSettings()
191+
{
192+
return this.currentTestSettings ?? base.GetSettings();
193+
}
194+
195+
protected override Project CreateProjectImpl(string[] sources, string language, string[] filenames)
196+
{
197+
var project = base.CreateProjectImpl(sources, language, filenames);
198+
var parseOptions = (CSharpParseOptions)project.ParseOptions;
199+
return project.WithParseOptions(parseOptions.WithLanguageVersion(LanguageVersion.CSharp7_2));
200+
}
201+
202+
protected override async Task TestTypeWithoutDocumentationAsync(string type, bool isInterface)
203+
{
204+
await base.TestTypeWithoutDocumentationAsync(type, isInterface).ConfigureAwait(false);
205+
206+
await this.TestNestedTypeDeclarationDocumentationAsync(type, "private protected", true, false).ConfigureAwait(false);
207+
}
208+
209+
protected override async Task TestTypeWithDocumentationAsync(string type)
210+
{
211+
await base.TestTypeWithDocumentationAsync(type).ConfigureAwait(false);
212+
213+
await this.TestNestedTypeDeclarationDocumentationAsync(type, "private protected", false, true).ConfigureAwait(false);
214+
}
10215
}
11216
}

StyleCop.Analyzers/StyleCop.Analyzers.Test/DocumentationRules/SA1600UnitTests.cs

Lines changed: 18 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -855,7 +855,7 @@ protected override CodeFixProvider GetCSharpCodeFixProvider()
855855
return new SA1600CodeFixProvider();
856856
}
857857

858-
private async Task TestTypeDeclarationDocumentationAsync(string type, string modifiers, bool requiresDiagnostic, bool hasDocumentation)
858+
protected async Task TestTypeDeclarationDocumentationAsync(string type, string modifiers, bool requiresDiagnostic, bool hasDocumentation)
859859
{
860860
var testCodeWithoutDocumentation = @"
861861
{0} {1}
@@ -876,7 +876,7 @@ private async Task TestTypeDeclarationDocumentationAsync(string type, string mod
876876
await this.VerifyCSharpDiagnosticAsync(string.Format(hasDocumentation ? testCodeWithDocumentation : testCodeWithoutDocumentation, modifiers, type), requiresDiagnostic ? expected : EmptyDiagnosticResults, CancellationToken.None).ConfigureAwait(false);
877877
}
878878

879-
private async Task TestNestedTypeDeclarationDocumentationAsync(string type, string modifiers, bool requiresDiagnostic, bool hasDocumentation)
879+
protected async Task TestNestedTypeDeclarationDocumentationAsync(string type, string modifiers, bool requiresDiagnostic, bool hasDocumentation)
880880
{
881881
var testCodeWithoutDocumentation = @" /// <summary>
882882
/// A summary
@@ -909,7 +909,7 @@ public class OuterClass
909909
await this.VerifyCSharpDiagnosticAsync(string.Format(hasDocumentation ? testCodeWithDocumentation : testCodeWithoutDocumentation, modifiers, type), requiresDiagnostic ? expected : EmptyDiagnosticResults, CancellationToken.None).ConfigureAwait(false);
910910
}
911911

912-
private async Task TestDelegateDeclarationDocumentationAsync(string modifiers, bool requiresDiagnostic, bool hasDocumentation)
912+
protected async Task TestDelegateDeclarationDocumentationAsync(string modifiers, bool requiresDiagnostic, bool hasDocumentation)
913913
{
914914
var testCodeWithoutDocumentation = @"
915915
{0} delegate void
@@ -926,7 +926,7 @@ private async Task TestDelegateDeclarationDocumentationAsync(string modifiers, b
926926
await this.VerifyCSharpDiagnosticAsync(string.Format(hasDocumentation ? testCodeWithDocumentation : testCodeWithoutDocumentation, modifiers), requiresDiagnostic ? expected : EmptyDiagnosticResults, CancellationToken.None).ConfigureAwait(false);
927927
}
928928

929-
private async Task TestNestedDelegateDeclarationDocumentationAsync(string modifiers, bool requiresDiagnostic, bool hasDocumentation)
929+
protected async Task TestNestedDelegateDeclarationDocumentationAsync(string modifiers, bool requiresDiagnostic, bool hasDocumentation)
930930
{
931931
var testCodeWithoutDocumentation = @" /// <summary>
932932
/// A summary
@@ -955,7 +955,7 @@ public class OuterClass
955955
await this.VerifyCSharpDiagnosticAsync(string.Format(hasDocumentation ? testCodeWithDocumentation : testCodeWithoutDocumentation, modifiers), requiresDiagnostic ? expected : EmptyDiagnosticResults, CancellationToken.None).ConfigureAwait(false);
956956
}
957957

958-
private async Task TestMethodDeclarationDocumentationAsync(string modifiers, bool isExplicitInterfaceMethod, bool requiresDiagnostic, bool hasDocumentation)
958+
protected async Task TestMethodDeclarationDocumentationAsync(string modifiers, bool isExplicitInterfaceMethod, bool requiresDiagnostic, bool hasDocumentation)
959959
{
960960
var testCodeWithoutDocumentation = @" /// <summary>
961961
/// A summary
@@ -997,7 +997,7 @@ public interface IInterface {{ void MemberName(); }}
997997
await this.VerifyCSharpDiagnosticAsync(string.Format(hasDocumentation ? testCodeWithDocumentation : testCodeWithoutDocumentation, modifiers, explicitInterfaceText), requiresDiagnostic ? expected : EmptyDiagnosticResults, CancellationToken.None).ConfigureAwait(false);
998998
}
999999

1000-
private async Task TestInterfaceMethodDeclarationDocumentationAsync(bool hasDocumentation)
1000+
protected async Task TestInterfaceMethodDeclarationDocumentationAsync(bool hasDocumentation)
10011001
{
10021002
var testCodeWithoutDocumentation = @" /// <summary>
10031003
/// A summary
@@ -1026,7 +1026,7 @@ public interface InterfaceName
10261026
await this.VerifyCSharpDiagnosticAsync(hasDocumentation ? testCodeWithDocumentation : testCodeWithoutDocumentation, !hasDocumentation ? expected : EmptyDiagnosticResults, CancellationToken.None).ConfigureAwait(false);
10271027
}
10281028

1029-
private async Task TestInterfacePropertyDeclarationDocumentationAsync(bool hasDocumentation)
1029+
protected async Task TestInterfacePropertyDeclarationDocumentationAsync(bool hasDocumentation)
10301030
{
10311031
var testCodeWithoutDocumentation = @" /// <summary>
10321032
/// A summary
@@ -1061,7 +1061,7 @@ string MemberName
10611061
await this.VerifyCSharpDiagnosticAsync(hasDocumentation ? testCodeWithDocumentation : testCodeWithoutDocumentation, !hasDocumentation ? expected : EmptyDiagnosticResults, CancellationToken.None).ConfigureAwait(false);
10621062
}
10631063

1064-
private async Task TestInterfaceEventDeclarationDocumentationAsync(bool hasDocumentation)
1064+
protected async Task TestInterfaceEventDeclarationDocumentationAsync(bool hasDocumentation)
10651065
{
10661066
var testCodeWithoutDocumentation = @" /// <summary>
10671067
/// A summary
@@ -1090,7 +1090,7 @@ public interface InterfaceName
10901090
await this.VerifyCSharpDiagnosticAsync(hasDocumentation ? testCodeWithDocumentation : testCodeWithoutDocumentation, !hasDocumentation ? expected : EmptyDiagnosticResults, CancellationToken.None).ConfigureAwait(false);
10911091
}
10921092

1093-
private async Task TestInterfaceIndexerDeclarationDocumentationAsync(bool hasDocumentation)
1093+
protected async Task TestInterfaceIndexerDeclarationDocumentationAsync(bool hasDocumentation)
10941094
{
10951095
var testCodeWithoutDocumentation = @" /// <summary>
10961096
/// A summary
@@ -1119,7 +1119,7 @@ public interface InterfaceName
11191119
await this.VerifyCSharpDiagnosticAsync(hasDocumentation ? testCodeWithDocumentation : testCodeWithoutDocumentation, !hasDocumentation ? expected : EmptyDiagnosticResults, CancellationToken.None).ConfigureAwait(false);
11201120
}
11211121

1122-
private async Task TestConstructorDeclarationDocumentationAsync(string modifiers, bool requiresDiagnostic, bool hasDocumentation)
1122+
protected async Task TestConstructorDeclarationDocumentationAsync(string modifiers, bool requiresDiagnostic, bool hasDocumentation)
11231123
{
11241124
var testCodeWithoutDocumentation = @" /// <summary>
11251125
/// A summary
@@ -1152,7 +1152,7 @@ public class OuterClass
11521152
await this.VerifyCSharpDiagnosticAsync(string.Format(hasDocumentation ? testCodeWithDocumentation : testCodeWithoutDocumentation, modifiers), requiresDiagnostic ? expected : EmptyDiagnosticResults, CancellationToken.None).ConfigureAwait(false);
11531153
}
11541154

1155-
private async Task TestDestructorDeclarationDocumentationAsync(bool requiresDiagnostic, bool hasDocumentation)
1155+
protected async Task TestDestructorDeclarationDocumentationAsync(bool requiresDiagnostic, bool hasDocumentation)
11561156
{
11571157
var testCodeWithoutDocumentation = @" /// <summary>
11581158
/// A summary
@@ -1183,7 +1183,7 @@ public class OuterClass
11831183
await this.VerifyCSharpDiagnosticAsync(string.Format(hasDocumentation ? testCodeWithDocumentation : testCodeWithoutDocumentation), requiresDiagnostic ? expected : EmptyDiagnosticResults, CancellationToken.None).ConfigureAwait(false);
11841184
}
11851185

1186-
private async Task TestPropertyDeclarationDocumentationAsync(string modifiers, bool isExplicitInterfaceProperty, bool requiresDiagnostic, bool hasDocumentation)
1186+
protected async Task TestPropertyDeclarationDocumentationAsync(string modifiers, bool isExplicitInterfaceProperty, bool requiresDiagnostic, bool hasDocumentation)
11871187
{
11881188
var testCodeWithoutDocumentation = @" /// <summary>
11891189
/// A summary
@@ -1223,7 +1223,7 @@ public interface IInterface {{ string MemberName {{ get; set; }} }}
12231223
await this.VerifyCSharpDiagnosticAsync(string.Format(hasDocumentation ? testCodeWithDocumentation : testCodeWithoutDocumentation, modifiers, explicitInterfaceText), requiresDiagnostic ? expected : EmptyDiagnosticResults, CancellationToken.None).ConfigureAwait(false);
12241224
}
12251225

1226-
private async Task TestIndexerDeclarationDocumentationAsync(string modifiers, bool isExplicitInterfaceIndexer, bool requiresDiagnostic, bool hasDocumentation)
1226+
protected async Task TestIndexerDeclarationDocumentationAsync(string modifiers, bool isExplicitInterfaceIndexer, bool requiresDiagnostic, bool hasDocumentation)
12271227
{
12281228
var testCodeWithoutDocumentation = @" /// <summary>
12291229
/// A summary
@@ -1263,7 +1263,7 @@ public interface IInterface {{ string this[string key] {{ get; set; }} }}
12631263
await this.VerifyCSharpDiagnosticAsync(string.Format(hasDocumentation ? testCodeWithDocumentation : testCodeWithoutDocumentation, modifiers, explicitInterfaceText), requiresDiagnostic ? expected : EmptyDiagnosticResults, CancellationToken.None).ConfigureAwait(false);
12641264
}
12651265

1266-
private async Task TestEventDeclarationDocumentationAsync(string modifiers, bool isExplicitInterfaceEvent, bool requiresDiagnostic, bool hasDocumentation)
1266+
protected async Task TestEventDeclarationDocumentationAsync(string modifiers, bool isExplicitInterfaceEvent, bool requiresDiagnostic, bool hasDocumentation)
12671267
{
12681268
var testCodeWithoutDocumentation = @" /// <summary>
12691269
/// A summary
@@ -1325,7 +1325,7 @@ public interface IInterface {{ event System.Action MyEvent; }}
13251325
await this.VerifyCSharpDiagnosticAsync(string.Format(hasDocumentation ? testCodeWithDocumentation : testCodeWithoutDocumentation, modifiers, explicitInterfaceText), requiresDiagnostic ? expected : EmptyDiagnosticResults, CancellationToken.None).ConfigureAwait(false);
13261326
}
13271327

1328-
private async Task TestFieldDeclarationDocumentationAsync(string modifiers, bool requiresDiagnostic, bool hasDocumentation)
1328+
protected async Task TestFieldDeclarationDocumentationAsync(string modifiers, bool requiresDiagnostic, bool hasDocumentation)
13291329
{
13301330
var testCodeWithoutDocumentation = @" /// <summary>
13311331
/// A summary
@@ -1354,7 +1354,7 @@ public class OuterClass
13541354
await this.VerifyCSharpDiagnosticAsync(string.Format(hasDocumentation ? testCodeWithDocumentation : testCodeWithoutDocumentation, modifiers), requiresDiagnostic ? expected : EmptyDiagnosticResults, CancellationToken.None).ConfigureAwait(false);
13551355
}
13561356

1357-
private async Task TestEventFieldDeclarationDocumentationAsync(string modifiers, bool requiresDiagnostic, bool hasDocumentation)
1357+
protected async Task TestEventFieldDeclarationDocumentationAsync(string modifiers, bool requiresDiagnostic, bool hasDocumentation)
13581358
{
13591359
var testCodeWithoutDocumentation = @" /// <summary>
13601360
/// A summary
@@ -1383,7 +1383,7 @@ public class OuterClass
13831383
await this.VerifyCSharpDiagnosticAsync(string.Format(hasDocumentation ? testCodeWithDocumentation : testCodeWithoutDocumentation, modifiers), requiresDiagnostic ? expected : EmptyDiagnosticResults, CancellationToken.None).ConfigureAwait(false);
13841384
}
13851385

1386-
private async Task TestTypeWithoutDocumentationAsync(string type, bool isInterface)
1386+
protected virtual async Task TestTypeWithoutDocumentationAsync(string type, bool isInterface)
13871387
{
13881388
await this.TestTypeDeclarationDocumentationAsync(type, string.Empty, true, false).ConfigureAwait(false);
13891389
await this.TestTypeDeclarationDocumentationAsync(type, "internal", true, false).ConfigureAwait(false);
@@ -1397,7 +1397,7 @@ private async Task TestTypeWithoutDocumentationAsync(string type, bool isInterfa
13971397
await this.TestNestedTypeDeclarationDocumentationAsync(type, "public", true, false).ConfigureAwait(false);
13981398
}
13991399

1400-
private async Task TestTypeWithDocumentationAsync(string type)
1400+
protected virtual async Task TestTypeWithDocumentationAsync(string type)
14011401
{
14021402
await this.TestTypeDeclarationDocumentationAsync(type, string.Empty, false, true).ConfigureAwait(false);
14031403
await this.TestTypeDeclarationDocumentationAsync(type, "internal", false, true).ConfigureAwait(false);

0 commit comments

Comments
 (0)