@@ -7,6 +7,7 @@ namespace StyleCop.Analyzers.Test.DocumentationRules
77 using System . Threading . Tasks ;
88 using Microsoft . CodeAnalysis . CodeFixes ;
99 using StyleCop . Analyzers . DocumentationRules ;
10+ using TestHelper ;
1011 using Xunit ;
1112
1213 /// <summary>
@@ -344,6 +345,43 @@ public async Task TestValidFileHeaderWithLeadingBlankLinesAsync(string prefix)
344345 await this . VerifyCSharpDiagnosticAsync ( testCode , EmptyDiagnosticResults , CancellationToken . None ) . ConfigureAwait ( false ) ;
345346 }
346347
348+ /// <summary>
349+ /// Verifies that incomplete multiline comment at the start of the file is handled correctly.
350+ /// </summary>
351+ /// <returns>A <see cref="Task"/> representing the asynchronous unit test.</returns>
352+ [ Fact ]
353+ [ WorkItem ( 2649 , "https://github.com/DotNetAnalyzers/StyleCopAnalyzers/issues/2649" ) ]
354+ public async Task TestIncompleteMultilineCommentAsync ( )
355+ {
356+ this . useNoXmlSettings = true ;
357+
358+ var testCode = @"/*
359+ * copyright (c) FooCorp. All rights reserved.
360+ " ;
361+
362+ var fixedCode = @"// copyright (c) FooCorp. All rights reserved.
363+
364+ /*
365+ * copyright (c) FooCorp. All rights reserved.
366+ " ;
367+
368+ DiagnosticResult [ ] expectedDiagnostics =
369+ {
370+ this . CSharpCompilerError ( "CS1035" ) . WithMessage ( "End-of-file found, '*/' expected" ) . WithLocation ( 1 , 1 ) ,
371+ this . CSharpDiagnostic ( FileHeaderAnalyzers . SA1633DescriptorMissing ) . WithLocation ( 1 , 1 ) ,
372+ } ;
373+
374+ // The fixed code will still have the incomplete comment, as there is no certainty that the incomplete comment was intended as file header.
375+ DiagnosticResult [ ] expectedFixedDiagnostics =
376+ {
377+ this . CSharpCompilerError ( "CS1035" ) . WithMessage ( "End-of-file found, '*/' expected" ) . WithLocation ( 3 , 1 ) ,
378+ } ;
379+
380+ await this . VerifyCSharpDiagnosticAsync ( testCode , expectedDiagnostics , CancellationToken . None ) . ConfigureAwait ( false ) ;
381+ await this . VerifyCSharpDiagnosticAsync ( fixedCode , expectedFixedDiagnostics , CancellationToken . None ) . ConfigureAwait ( false ) ;
382+ await this . VerifyCSharpFixAsync ( testCode , fixedCode , numberOfFixAllIterations : 2 ) . ConfigureAwait ( false ) ;
383+ }
384+
347385 /// <inheritdoc/>
348386 protected override string GetSettings ( )
349387 {
0 commit comments