Skip to content

Commit 9ac894c

Browse files
committed
Add a test for documentation comment behavior
1 parent 0eef077 commit 9ac894c

1 file changed

Lines changed: 116 additions & 0 deletions

File tree

StyleCop.Analyzers/StyleCop.Analyzers.Test/ReadabilityRules/SA1137UnitTests.cs

Lines changed: 116 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -223,6 +223,122 @@ public async Task TestTypeDeclarationConstraintClausesAsync(string typeKind)
223223
await this.VerifyCSharpFixAsync(testCode, fixedCode, cancellationToken: CancellationToken.None).ConfigureAwait(false);
224224
}
225225

226+
/// <summary>
227+
/// This test demonstrates the behavior of SA1137 and its code fix with respect to documentation comments.
228+
/// Currently both operations ignore documentation comments, but in the future the implementation may be updated
229+
/// to examine and correct them similarly to attribute lists.
230+
/// </summary>
231+
/// <returns>A <see cref="Task"/> representing the asynchronous unit test.</returns>
232+
[Fact]
233+
public async Task TestDocumentationCommentBehaviorAsync()
234+
{
235+
string testCode = @"
236+
using System;
237+
enum Enum1
238+
{
239+
/// <summary>
240+
/// Summary.
241+
/// </summary>
242+
[My]
243+
Element1,
244+
245+
/// <summary>
246+
/// Summary.
247+
/// </summary>
248+
Element2,
249+
}
250+
251+
enum Enum2
252+
{
253+
/// <summary>
254+
/// Summary.
255+
/// </summary>
256+
[My]
257+
Element1,
258+
259+
/// <summary>
260+
/// Summary.
261+
/// </summary>
262+
Element2,
263+
}
264+
265+
enum Enum3
266+
{
267+
/// <summary>
268+
/// Summary.
269+
/// </summary>
270+
[My] Element1,
271+
272+
/// <summary>
273+
/// Summary.
274+
/// </summary>
275+
Element2,
276+
}
277+
278+
[AttributeUsage(AttributeTargets.All, AllowMultiple = true)]
279+
class MyAttribute : Attribute { }
280+
";
281+
string fixedCode = @"
282+
using System;
283+
enum Enum1
284+
{
285+
/// <summary>
286+
/// Summary.
287+
/// </summary>
288+
[My]
289+
Element1,
290+
291+
/// <summary>
292+
/// Summary.
293+
/// </summary>
294+
Element2,
295+
}
296+
297+
enum Enum2
298+
{
299+
/// <summary>
300+
/// Summary.
301+
/// </summary>
302+
[My]
303+
Element1,
304+
305+
/// <summary>
306+
/// Summary.
307+
/// </summary>
308+
Element2,
309+
}
310+
311+
enum Enum3
312+
{
313+
/// <summary>
314+
/// Summary.
315+
/// </summary>
316+
[My] Element1,
317+
318+
/// <summary>
319+
/// Summary.
320+
/// </summary>
321+
Element2,
322+
}
323+
324+
[AttributeUsage(AttributeTargets.All, AllowMultiple = true)]
325+
class MyAttribute : Attribute { }
326+
";
327+
328+
DiagnosticResult[] expected =
329+
{
330+
this.CSharpDiagnostic().WithLocation(8, 1),
331+
this.CSharpDiagnostic().WithLocation(14, 1),
332+
this.CSharpDiagnostic().WithLocation(22, 1),
333+
this.CSharpDiagnostic().WithLocation(28, 1),
334+
this.CSharpDiagnostic().WithLocation(36, 1),
335+
};
336+
337+
await this.VerifyCSharpDiagnosticAsync(testCode, expected, CancellationToken.None).ConfigureAwait(false);
338+
await this.VerifyCSharpDiagnosticAsync(fixedCode, EmptyDiagnosticResults, CancellationToken.None).ConfigureAwait(false);
339+
await this.VerifyCSharpFixAsync(testCode, fixedCode, cancellationToken: CancellationToken.None).ConfigureAwait(false);
340+
}
341+
226342
[Fact]
227343
public async Task TestEnumDeclarationAsync()
228344
{

0 commit comments

Comments
 (0)