Skip to content

Commit 166c25d

Browse files
committed
Merged in changes from upstream master.
2 parents 31084f0 + be984ba commit 166c25d

24 files changed

Lines changed: 967 additions & 85 deletions

LICENSE

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,21 @@ specific language governing permissions and limitations under the License.
1616
This project uses other open source projects, which are used under the terms
1717
of the following license(s).
1818

19+
.NET Compiler Platform ("Roslyn")
20+
21+
Copyright Microsoft.
22+
23+
Licensed under the Apache License, Version 2.0 (the "License"); you may not use
24+
these files except in compliance with the License. You may obtain a copy of the
25+
License at
26+
27+
http://www.apache.org/licenses/LICENSE-2.0
28+
29+
Unless required by applicable law or agreed to in writing, software distributed
30+
under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR
31+
CONDITIONS OF ANY KIND, either express or implied. See the License for the
32+
specific language governing permissions and limitations under the License.
33+
1934
Code Cracker
2035

2136
Copyright 2014 Giovanni Bassi and Elemar Jr.

StyleCop.Analyzers/StyleCop.Analyzers.Test/DocumentationRules/FileHeaderTestBase.cs

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,11 +4,9 @@
44
namespace StyleCop.Analyzers.Test.DocumentationRules
55
{
66
using System.Collections.Generic;
7-
using System.Linq;
87
using System.Threading;
98
using System.Threading.Tasks;
109
using Analyzers.DocumentationRules;
11-
using Microsoft.CodeAnalysis;
1210
using Microsoft.CodeAnalysis.Diagnostics;
1311
using TestHelper;
1412
using Xunit;

StyleCop.Analyzers/StyleCop.Analyzers.Test/DocumentationRules/SA1633UnitTests.cs

Lines changed: 37 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,41 @@ public async Task TestValidFileHeaderNoContentAsync()
4747
}
4848

4949
/// <summary>
50-
/// Verifies that a valid file header with leading directives will not produce a diagnostic message.
50+
/// Verifies that a file with a valid header and no other content will not produce a diagnostic message.
51+
/// </summary>
52+
/// <returns>A <see cref="Task"/> representing the asynchronous unit test.</returns>
53+
[Fact]
54+
public async Task TestValidMultilineCommentFileHeadersAsync()
55+
{
56+
var testCode1 = @"/* <copyright file=""Test0.cs"" company=""FooCorp"">
57+
Copyright (c) FooCorp. All rights reserved.
58+
</copyright> */
59+
";
60+
61+
var testCode2 = @"/*
62+
<copyright file=""Test1.cs"" company=""FooCorp"">
63+
Copyright (c) FooCorp. All rights reserved.
64+
</copyright>
65+
*/
66+
";
67+
68+
var testCode3 = @"/*<copyright file=""Test2.cs"" company=""FooCorp"">
69+
Copyright (c) FooCorp. All rights reserved.
70+
</copyright>*/
71+
";
72+
73+
var testCode4 = @"/*
74+
* <copyright file=""Test3.cs"" company=""FooCorp"">
75+
* Copyright (c) FooCorp. All rights reserved.
76+
* </copyright>
77+
*/
78+
";
79+
80+
await this.VerifyCSharpDiagnosticAsync(new[] { testCode1, testCode2, testCode3, testCode4 }, EmptyDiagnosticResults, CancellationToken.None).ConfigureAwait(false);
81+
}
82+
83+
/// <summary>
84+
/// Verifies that a valid file header with leading directives will produce the correct diagnostic message.
5185
/// </summary>
5286
/// <returns>A <see cref="Task"/> representing the asynchronous unit test.</returns>
5387
[Fact]
@@ -66,7 +100,8 @@ namespace Bar
66100
}
67101
";
68102

69-
await this.VerifyCSharpDiagnosticAsync(testCode, EmptyDiagnosticResults, CancellationToken.None).ConfigureAwait(false);
103+
var expected = this.CSharpDiagnostic(FileHeaderAnalyzers.SA1633DescriptorMissing).WithLocation(1, 1);
104+
await this.VerifyCSharpDiagnosticAsync(testCode, expected, CancellationToken.None).ConfigureAwait(false);
70105
}
71106

72107
/// <summary>

StyleCop.Analyzers/StyleCop.Analyzers.Test/DocumentationRules/SA1636UnitTests.cs

Lines changed: 135 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -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
}
Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
// Copyright (c) Tunnel Vision Laboratories, LLC. All Rights Reserved.
2+
// Licensed under the Apache License, Version 2.0. See LICENSE in the project root for license information.
3+
4+
namespace StyleCop.Analyzers.Test.HelperTests
5+
{
6+
using System.Linq;
7+
using Analyzers.Helpers;
8+
using Microsoft.CodeAnalysis;
9+
using Microsoft.CodeAnalysis.CSharp;
10+
using Xunit;
11+
12+
public class TokenHelperTests
13+
{
14+
[Fact]
15+
public void TestIsFirstInLineSpecialCase()
16+
{
17+
string testCode = @"class MyClass {
18+
} /// <summary>
19+
/// Text
20+
/// </summary>
21+
struct MyStruct { }";
22+
var syntaxTree = CSharpSyntaxTree.ParseText(testCode);
23+
var root = syntaxTree.GetRoot();
24+
25+
Assert.True(root.DescendantTokens().Single(i => i.IsKind(SyntaxKind.StructKeyword)).IsFirstInLine());
26+
}
27+
28+
[Fact]
29+
public void TestIsLastInLineSpecialCase()
30+
{
31+
string testCode = @"class MyClass {
32+
} /// <summary>
33+
/// Text
34+
/// </summary>
35+
struct /**
36+
Foo
37+
**/ MyStruct { }";
38+
var syntaxTree = CSharpSyntaxTree.ParseText(testCode);
39+
var root = syntaxTree.GetRoot();
40+
41+
Assert.True(root.DescendantTokens().Single(i => i.IsKind(SyntaxKind.StructKeyword)).IsLastInLine());
42+
}
43+
}
44+
}

0 commit comments

Comments
 (0)