Skip to content

Commit 9d9a139

Browse files
robinsedlaczeksharwell
authored andcommitted
Add regression tests for tabs within comments
1 parent 8769e8b commit 9d9a139

1 file changed

Lines changed: 125 additions & 0 deletions

File tree

StyleCop.Analyzers/StyleCop.Analyzers.Test/SpacingRules/SA1027UnitTests.cs

Lines changed: 125 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -97,6 +97,131 @@ public void Bar()
9797
await this.VerifyCSharpFixAsync(testCode, fixedTestCode, cancellationToken: CancellationToken.None).ConfigureAwait(false);
9898
}
9999

100+
[Fact]
101+
public async Task TestInvalidTabsInDocumentationCommentsAsync()
102+
{
103+
var testCode =
104+
"\t/// <summary>\r\n" +
105+
"\t/// foo bar\r\n" +
106+
"\t/// </summary>\r\n" +
107+
"\tpublic class Foo\r\n" +
108+
"\t{\r\n" +
109+
"\t \t/// <MyElement> Value </MyElement>\r\n" +
110+
"\t\t/// <MyElement> Value </MyElement>\r\n" +
111+
"\t}\r\n";
112+
113+
var fixedTestCode = @" /// <summary>
114+
/// foo bar
115+
/// </summary>
116+
public class Foo
117+
{
118+
/// <MyElement> Value </MyElement>
119+
/// <MyElement> Value </MyElement>
120+
}
121+
";
122+
123+
DiagnosticResult[] expected =
124+
{
125+
this.CSharpDiagnostic().WithLocation(1, 1),
126+
this.CSharpDiagnostic().WithLocation(2, 1),
127+
this.CSharpDiagnostic().WithLocation(3, 1),
128+
this.CSharpDiagnostic().WithLocation(4, 1),
129+
this.CSharpDiagnostic().WithLocation(5, 1),
130+
this.CSharpDiagnostic().WithLocation(6, 1),
131+
this.CSharpDiagnostic().WithLocation(7, 1),
132+
this.CSharpDiagnostic().WithLocation(8, 1),
133+
};
134+
135+
await this.VerifyCSharpDiagnosticAsync(testCode, expected, CancellationToken.None).ConfigureAwait(false);
136+
await this.VerifyCSharpDiagnosticAsync(fixedTestCode, EmptyDiagnosticResults, CancellationToken.None).ConfigureAwait(false);
137+
await this.VerifyCSharpFixAsync(testCode, fixedTestCode, cancellationToken: CancellationToken.None).ConfigureAwait(false);
138+
}
139+
140+
[Fact]
141+
public async Task TestInvalidTabsInCommentsAsync()
142+
{
143+
var testCode =
144+
"\tpublic class Foo\r\n" +
145+
"\t{\r\n" +
146+
"\t\tpublic void Bar()\r\n" +
147+
"\t\t{\r\n" +
148+
"\t\t \t//\tComment\t\t1\r\n" +
149+
"\t \t\t// Comment 2\r\n" +
150+
"\t\t}\r\n" +
151+
"\t}\r\n";
152+
153+
var fixedTestCode = @" public class Foo
154+
{
155+
public void Bar()
156+
{
157+
// Comment 1
158+
// Comment 2
159+
}
160+
}
161+
";
162+
163+
DiagnosticResult[] expected =
164+
{
165+
this.CSharpDiagnostic().WithLocation(1, 1),
166+
this.CSharpDiagnostic().WithLocation(2, 1),
167+
this.CSharpDiagnostic().WithLocation(3, 1),
168+
this.CSharpDiagnostic().WithLocation(4, 1),
169+
this.CSharpDiagnostic().WithLocation(5, 1),
170+
this.CSharpDiagnostic().WithLocation(5, 5),
171+
this.CSharpDiagnostic().WithLocation(6, 1),
172+
this.CSharpDiagnostic().WithLocation(7, 1),
173+
this.CSharpDiagnostic().WithLocation(8, 1),
174+
};
175+
176+
await this.VerifyCSharpDiagnosticAsync(testCode, expected, CancellationToken.None).ConfigureAwait(false);
177+
await this.VerifyCSharpDiagnosticAsync(fixedTestCode, EmptyDiagnosticResults, CancellationToken.None).ConfigureAwait(false);
178+
await this.VerifyCSharpFixAsync(testCode, fixedTestCode, cancellationToken: CancellationToken.None).ConfigureAwait(false);
179+
}
180+
181+
[Fact]
182+
public async Task TestInvalidTabsInMultiLineCommentsAsync()
183+
{
184+
var testCode =
185+
"\tpublic class Foo\r\n" +
186+
"\t{\r\n" +
187+
"\t\tpublic void Bar()\r\n" +
188+
"\t\t{\r\n" +
189+
"\t\t \t/*\r\n" +
190+
"\t\t\tComment\t\t1\r\n" +
191+
"\t \t\tComment 2\r\n" +
192+
" \t\t\t*/\r\n" +
193+
"\t\t}\r\n" +
194+
"\t}\r\n";
195+
196+
var fixedTestCode = @" public class Foo
197+
{
198+
public void Bar()
199+
{
200+
/*
201+
Comment 1
202+
Comment 2
203+
*/
204+
}
205+
}
206+
";
207+
208+
DiagnosticResult[] expected =
209+
{
210+
this.CSharpDiagnostic().WithLocation(1, 1),
211+
this.CSharpDiagnostic().WithLocation(2, 1),
212+
this.CSharpDiagnostic().WithLocation(3, 1),
213+
this.CSharpDiagnostic().WithLocation(4, 1),
214+
this.CSharpDiagnostic().WithLocation(5, 1),
215+
this.CSharpDiagnostic().WithLocation(5, 5),
216+
this.CSharpDiagnostic().WithLocation(9, 1),
217+
this.CSharpDiagnostic().WithLocation(10, 1),
218+
};
219+
220+
await this.VerifyCSharpDiagnosticAsync(testCode, expected, CancellationToken.None).ConfigureAwait(false);
221+
await this.VerifyCSharpDiagnosticAsync(fixedTestCode, EmptyDiagnosticResults, CancellationToken.None).ConfigureAwait(false);
222+
await this.VerifyCSharpFixAsync(testCode, fixedTestCode, cancellationToken: CancellationToken.None).ConfigureAwait(false);
223+
}
224+
100225
/// <inheritdoc/>
101226
protected override IEnumerable<DiagnosticAnalyzer> GetCSharpDiagnosticAnalyzers()
102227
{

0 commit comments

Comments
 (0)