@@ -14,6 +14,32 @@ namespace StyleCop.Analyzers.Test.DocumentationRules
1414 /// </summary>
1515 public class SA1636UnitTests : FileHeaderTestBase
1616 {
17+ private const string MultiLineHeaderTestSettings = @"
18+ {
19+ ""settings"": {
20+ ""documentationRules"": {
21+ ""companyName"": ""FooCorp"",
22+ ""copyrightText"": ""copyright (c) {companyName}. All rights reserved.\n\nLine #3""
23+ }
24+ }
25+ }
26+ " ;
27+
28+ private const string NoXmlMultiLineHeaderTestSettings = @"
29+ {
30+ ""settings"": {
31+ ""documentationRules"": {
32+ ""companyName"": ""FooCorp"",
33+ ""copyrightText"": ""copyright (c) {companyName}. All rights reserved.\n\nLine #3"",
34+ ""xmlHeader"": false
35+ }
36+ }
37+ }
38+ " ;
39+
40+ private bool useMultiLineHeaderTestSettings ;
41+ private bool useNoXmlMultiLineHeaderTestSettings ;
42+
1743 /// <summary>
1844 /// Verifies that a file header with a copyright message that is different than in the settings will produce the expected diagnostic message.
1945 /// </summary>
@@ -74,6 +100,99 @@ namespace Bar
74100 await this . VerifyCSharpFixAsync ( testCode , fixedCode , cancellationToken : CancellationToken . None ) . ConfigureAwait ( false ) ;
75101 }
76102
103+ /// <summary>
104+ /// Verifies that a file header will ignore spurious leading / trailing whitespaces (for multiple line comments)
105+ /// This is a regression for #1356
106+ /// </summary>
107+ /// <returns>A <see cref="Task"/> representing the asynchronous unit test.</returns>
108+ [ Fact ]
109+ public async Task TestFileHeaderWillIgnoreLeadingAndTrailingWhitespaceAroundCopyrightMessageAsync ( )
110+ {
111+ this . useMultiLineHeaderTestSettings = true ;
112+
113+ var testCode1 = @"// <copyright file=""Test0.cs"" company=""FooCorp"">
114+ // copyright (c) FooCorp. All rights reserved.
115+ //
116+ // Line #3
117+ // </copyright>
118+
119+ namespace Bar
120+ {
121+ }
122+ " ;
123+
124+ var testCode2 = @"/* <copyright file=""Test1.cs"" company=""FooCorp"">
125+ copyright (c) FooCorp. All rights reserved.
126+
127+ Line #3
128+ </copyright> */
129+
130+ namespace Bar
131+ {
132+ }
133+ " ;
134+
135+ var testCode3 = @"/*
136+ * <copyright file=""Test2.cs"" company=""FooCorp"">
137+ * copyright (c) FooCorp. All rights reserved.
138+ *
139+ * Line #3
140+ * </copyright>
141+ */
142+
143+ namespace Bar
144+ {
145+ }
146+ " ;
147+
148+ await this . VerifyCSharpDiagnosticAsync ( new [ ] { testCode1 , testCode2 , testCode3 } , EmptyDiagnosticResults , CancellationToken . None ) . ConfigureAwait ( false ) ;
149+ }
150+
151+ /// <summary>
152+ /// Verifies that a file header without XML header will ignore spurious leading / trailing whitespaces (for multiple line comments)
153+ /// This is a regression for #1356
154+ /// </summary>
155+ /// <returns>A <see cref="Task"/> representing the asynchronous unit test.</returns>
156+ [ Fact ]
157+ public async Task TestNoXmlFileHeaderWillIgnoreLeadingAndTrailingWhitespaceAroundCopyrightMessageAsync ( )
158+ {
159+ this . useNoXmlMultiLineHeaderTestSettings = true ;
160+
161+ var testCode1 = @"// copyright (c) FooCorp. All rights reserved.
162+ //
163+ // Line #3
164+
165+ namespace Bar
166+ {
167+ }
168+ " ;
169+
170+ var testCode2 = @"/*
171+ * copyright (c) FooCorp. All rights reserved.
172+ *
173+ * Line #3
174+ */
175+
176+ namespace Bar
177+ {
178+ }
179+ " ;
180+
181+ var testCode3 = @"/*
182+ copyright (c) FooCorp. All rights reserved.
183+
184+ Line #3
185+ */
186+
187+ namespace Bar
188+ {
189+ }
190+ " ;
191+
192+ await this . VerifyCSharpDiagnosticAsync ( new [ ] { testCode1 , testCode2 , testCode3 } , EmptyDiagnosticResults , CancellationToken . None ) . ConfigureAwait ( false ) ;
193+ }
194+
195+ /// <inheritdoc/>
77196 /// <summary>
78197 /// Verifies that a file header with an incorrect copyright text the fix only replaces the text.
79198 /// </summary>
@@ -116,5 +235,21 @@ protected override CodeFixProvider GetCSharpCodeFixProvider()
116235 {
117236 return new FileHeaderCodeFixProvider ( ) ;
118237 }
238+
239+ /// <inheritdoc/>
240+ protected override string GetSettings ( )
241+ {
242+ if ( this . useMultiLineHeaderTestSettings )
243+ {
244+ return MultiLineHeaderTestSettings ;
245+ }
246+
247+ if ( this . useNoXmlMultiLineHeaderTestSettings )
248+ {
249+ return NoXmlMultiLineHeaderTestSettings ;
250+ }
251+
252+ return base . GetSettings ( ) ;
253+ }
119254 }
120255}
0 commit comments