@@ -5,8 +5,14 @@ namespace StyleCop.Analyzers.Test.CSharp8.SpacingRules
55{
66 using System . Threading ;
77 using System . Threading . Tasks ;
8+
9+ using Microsoft . CodeAnalysis . CSharp ;
10+ using Microsoft . CodeAnalysis . Testing ;
11+
812 using StyleCop . Analyzers . Test . CSharp7 . SpacingRules ;
13+
914 using Xunit ;
15+
1016 using static StyleCop . Analyzers . Test . Verifiers . StyleCopCodeFixVerifier <
1117 StyleCop . Analyzers . SpacingRules . SA1013ClosingBracesMustBeSpacedCorrectly ,
1218 StyleCop . Analyzers . SpacingRules . TokenSpacingCodeFixProvider > ;
@@ -62,5 +68,30 @@ public void TestMethod(object value)
6268 var expected = Diagnostic ( ) . WithSpan ( 14 , 37 , 14 , 38 ) . WithArguments ( string . Empty , "followed" ) ;
6369 await VerifyCSharpFixAsync ( testCode , expected , fixedCode , CancellationToken . None ) . ConfigureAwait ( false ) ;
6470 }
71+
72+ /// <summary>
73+ /// Validates that a closing brace followed by a null-forgiving operator does not require a space.
74+ /// </summary>
75+ /// <returns>A <see cref="Task"/> representing the asynchronous unit test.</returns>
76+ [ Fact ]
77+ [ WorkItem ( 3172 , "https://github.com/DotNetAnalyzers/StyleCopAnalyzers/issues/3172" ) ]
78+ public async Task TestCloseBraceWithNullForgivingOperatorAsync ( )
79+ {
80+ const string testCode = @"#nullable enable
81+ public class Foo
82+ {
83+ public void TestMethod()
84+ {
85+ var test = new[]
86+ {
87+ new { Value = ""a"" }!,
88+ new { Value = ""b"" } !,
89+ };
90+ }
91+ }
92+ " ;
93+
94+ await VerifyCSharpDiagnosticAsync ( LanguageVersion . CSharp8 , testCode , DiagnosticResult . EmptyDiagnosticResults , CancellationToken . None ) . ConfigureAwait ( false ) ;
95+ }
6596 }
6697}
0 commit comments