Skip to content

Commit f951587

Browse files
committed
Avoid placing expected results as test inputs
1 parent 25f82b1 commit f951587

File tree

1 file changed

+23
-16
lines changed

1 file changed

+23
-16
lines changed

StyleCop.Analyzers/StyleCop.Analyzers.Test/LayoutRules/SA1518UnitTests.cs

Lines changed: 23 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -55,19 +55,23 @@ internal async Task TestWithBlankLinesAtEndOfFileAsync(OptionSetting? newlineAtE
5555
/// Verifies file with white space only and no cr/lf at end of file will produce a warning when setting requires.
5656
/// </summary>
5757
/// <param name="newlineAtEndOfFile">The effective <see cref="OptionSetting"/> setting.</param>
58-
/// <param name="expectedText">The expected text to appear at the end of the file.</param>
5958
/// <returns>A <see cref="Task"/> representing the asynchronous unit test.</returns>
6059
[Theory]
61-
[InlineData(null, null)]
62-
[InlineData(OptionSetting.Allow, null)]
63-
[InlineData(OptionSetting.Require, "\r\n")]
64-
[InlineData(OptionSetting.Omit, null)]
65-
internal async Task TestWithWhiteSpaceOnlyAsync(OptionSetting? newlineAtEndOfFile, string expectedText)
60+
[InlineData(null)]
61+
[InlineData(OptionSetting.Allow)]
62+
[InlineData(OptionSetting.Require)]
63+
[InlineData(OptionSetting.Omit)]
64+
internal async Task TestWithWhiteSpaceOnlyAsync(OptionSetting? newlineAtEndOfFile)
6665
{
6766
var testCode = WhiteSpace;
68-
var fixedCode = expectedText;
6967

70-
if (expectedText == null)
68+
var fixedCode = newlineAtEndOfFile switch
69+
{
70+
OptionSetting.Require => "\r\n",
71+
_ => null,
72+
};
73+
74+
if (fixedCode == null)
7175
{
7276
await VerifyCSharpDiagnosticAsync(newlineAtEndOfFile, testCode, DiagnosticResult.EmptyDiagnosticResults, CancellationToken.None).ConfigureAwait(false);
7377
}
@@ -82,19 +86,22 @@ internal async Task TestWithWhiteSpaceOnlyAsync(OptionSetting? newlineAtEndOfFil
8286
/// Verifies file with white space only and cr/lf at end of file will produce a warning when setting requires.
8387
/// </summary>
8488
/// <param name="newlineAtEndOfFile">The effective <see cref="OptionSetting"/> setting.</param>
85-
/// <param name="expectedText">The expected text to appear at the end of the file.</param>
8689
/// <returns>A <see cref="Task"/> representing the asynchronous unit test.</returns>
8790
[Theory]
88-
[InlineData(null, null)]
89-
[InlineData(OptionSetting.Allow, null)]
90-
[InlineData(OptionSetting.Require, null)]
91-
[InlineData(OptionSetting.Omit, "")]
92-
internal async Task TestWithWhiteSpaceAndNewlineOnlyAsync(OptionSetting? newlineAtEndOfFile, string expectedText)
91+
[InlineData(null)]
92+
[InlineData(OptionSetting.Allow)]
93+
[InlineData(OptionSetting.Require)]
94+
[InlineData(OptionSetting.Omit)]
95+
internal async Task TestWithWhiteSpaceAndNewlineOnlyAsync(OptionSetting? newlineAtEndOfFile)
9396
{
9497
var testCode = WhiteSpace + "\r\n";
95-
var fixedCode = expectedText;
98+
var fixedCode = newlineAtEndOfFile switch
99+
{
100+
OptionSetting.Omit => string.Empty,
101+
_ => null,
102+
};
96103

97-
if (expectedText == null)
104+
if (fixedCode == null)
98105
{
99106
await VerifyCSharpDiagnosticAsync(newlineAtEndOfFile, testCode, DiagnosticResult.EmptyDiagnosticResults, CancellationToken.None).ConfigureAwait(false);
100107
}

0 commit comments

Comments
 (0)