@@ -29,6 +29,8 @@ public void Bar(int i)
2929 }
3030}" ;
3131
32+ private const string WhiteSpace = "\t " ;
33+
3234 /// <summary>
3335 /// Verifies that blank lines at the end of the file will produce a warning.
3436 /// </summary>
@@ -49,6 +51,83 @@ internal async Task TestWithBlankLinesAtEndOfFileAsync(OptionSetting? newlineAtE
4951 await VerifyCSharpFixAsync ( newlineAtEndOfFile , testCode , expected , fixedCode , CancellationToken . None ) . ConfigureAwait ( false ) ;
5052 }
5153
54+ /// <summary>
55+ /// Verifies file with white space only and no cr/lf at end of file will produce a warning when setting requires.
56+ /// </summary>
57+ /// <param name="newlineAtEndOfFile">The effective <see cref="OptionSetting"/> setting.</param>
58+ /// <returns>A <see cref="Task"/> representing the asynchronous unit test.</returns>
59+ [ Theory ]
60+ [ InlineData ( null ) ]
61+ [ InlineData ( OptionSetting . Allow ) ]
62+ [ InlineData ( OptionSetting . Require ) ]
63+ [ InlineData ( OptionSetting . Omit ) ]
64+ internal async Task TestWithWhiteSpaceOnlyAsync ( OptionSetting ? newlineAtEndOfFile )
65+ {
66+ var testCode = WhiteSpace ;
67+
68+ var fixedCode = newlineAtEndOfFile switch
69+ {
70+ OptionSetting . Require => "\r \n " ,
71+ _ => null ,
72+ } ;
73+
74+ if ( fixedCode == null )
75+ {
76+ await VerifyCSharpDiagnosticAsync ( newlineAtEndOfFile , testCode , DiagnosticResult . EmptyDiagnosticResults , CancellationToken . None ) . ConfigureAwait ( false ) ;
77+ }
78+ else
79+ {
80+ var expected = Diagnostic ( this . GetDescriptor ( newlineAtEndOfFile ) ) . WithLocation ( 1 , 1 ) ;
81+ await VerifyCSharpFixAsync ( newlineAtEndOfFile , testCode , expected , fixedCode , CancellationToken . None ) . ConfigureAwait ( false ) ;
82+ }
83+ }
84+
85+ /// <summary>
86+ /// Verifies file with white space only and cr/lf at end of file will produce a warning when setting requires.
87+ /// </summary>
88+ /// <param name="newlineAtEndOfFile">The effective <see cref="OptionSetting"/> setting.</param>
89+ /// <returns>A <see cref="Task"/> representing the asynchronous unit test.</returns>
90+ [ Theory ]
91+ [ InlineData ( null ) ]
92+ [ InlineData ( OptionSetting . Allow ) ]
93+ [ InlineData ( OptionSetting . Require ) ]
94+ [ InlineData ( OptionSetting . Omit ) ]
95+ internal async Task TestWithWhiteSpaceAndNewlineOnlyAsync ( OptionSetting ? newlineAtEndOfFile )
96+ {
97+ var testCode = WhiteSpace + "\r \n " ;
98+ var fixedCode = newlineAtEndOfFile switch
99+ {
100+ OptionSetting . Omit => string . Empty ,
101+ _ => null ,
102+ } ;
103+
104+ if ( fixedCode == null )
105+ {
106+ await VerifyCSharpDiagnosticAsync ( newlineAtEndOfFile , testCode , DiagnosticResult . EmptyDiagnosticResults , CancellationToken . None ) . ConfigureAwait ( false ) ;
107+ }
108+ else
109+ {
110+ var expected = Diagnostic ( this . GetDescriptor ( newlineAtEndOfFile ) ) . WithLocation ( 1 , 1 ) ;
111+ await VerifyCSharpFixAsync ( newlineAtEndOfFile , testCode , expected , fixedCode , CancellationToken . None ) . ConfigureAwait ( false ) ;
112+ }
113+ }
114+
115+ /// <summary>
116+ /// Verifies that empty files will not produce a warning.
117+ /// </summary>
118+ /// <param name="newlineAtEndOfFile">The effective <see cref="OptionSetting"/> setting.</param>
119+ /// <returns>A <see cref="Task"/> representing the asynchronous unit test.</returns>
120+ [ Theory ]
121+ [ InlineData ( null ) ]
122+ [ InlineData ( OptionSetting . Allow ) ]
123+ [ InlineData ( OptionSetting . Require ) ]
124+ [ InlineData ( OptionSetting . Omit ) ]
125+ internal async Task TestWithEmptyFileAsync ( OptionSetting ? newlineAtEndOfFile )
126+ {
127+ var testCode = string . Empty ;
128+ await VerifyCSharpDiagnosticAsync ( newlineAtEndOfFile , testCode , DiagnosticResult . EmptyDiagnosticResults , CancellationToken . None ) . ConfigureAwait ( false ) ;
129+ }
130+
52131 /// <summary>
53132 /// Verifies that linefeed only blank lines at the end of the file will produce a warning.
54133 /// </summary>
0 commit comments