@@ -56,5 +56,64 @@ public class TestClass
5656
5757 await VerifyCSharpDiagnosticAsync ( LanguageVersion . CSharp8 , testCode , DiagnosticResult . EmptyDiagnosticResults , CancellationToken . None ) . ConfigureAwait ( false ) ;
5858 }
59+
60+ [ Fact ]
61+ [ WorkItem ( 3052 , "https://github.com/DotNetAnalyzers/StyleCopAnalyzers/issues/3052" ) ]
62+ public async Task TestClosingSquareBracketFollowedByExclamationAsync ( )
63+ {
64+ var testCode = @"namespace TestNamespace
65+ {
66+ public class TestClass
67+ {
68+ public void TestMethod(object?[] arguments)
69+ {
70+ object o = arguments[0]!;
71+ string s = arguments[0]!.ToString();
72+ }
73+ }
74+ }
75+ " ;
76+
77+ await VerifyCSharpDiagnosticAsync ( LanguageVersion . CSharp8 , testCode , DiagnosticResult . EmptyDiagnosticResults , CancellationToken . None ) . ConfigureAwait ( false ) ;
78+ }
79+
80+ [ Fact ]
81+ [ WorkItem ( 3052 , "https://github.com/DotNetAnalyzers/StyleCopAnalyzers/issues/3052" ) ]
82+ public async Task TestInvalidClosingSquareBracketFollowedByExclamationAsync ( )
83+ {
84+ var testCode = @"namespace TestNamespace
85+ {
86+ public class TestClass
87+ {
88+ public void TestMethod(object?[] arguments)
89+ {
90+ object o = arguments[0] !;
91+ string s = arguments[0] !.ToString();
92+ }
93+ }
94+ }
95+ " ;
96+
97+ var fixedCode = @"namespace TestNamespace
98+ {
99+ public class TestClass
100+ {
101+ public void TestMethod(object?[] arguments)
102+ {
103+ object o = arguments[0]!;
104+ string s = arguments[0]!.ToString();
105+ }
106+ }
107+ }
108+ " ;
109+
110+ DiagnosticResult [ ] expected =
111+ {
112+ Diagnostic ( ) . WithArguments ( " not" , "followed" ) . WithLocation ( 7 , 35 ) ,
113+ Diagnostic ( ) . WithArguments ( " not" , "followed" ) . WithLocation ( 8 , 35 ) ,
114+ } ;
115+
116+ await VerifyCSharpFixAsync ( LanguageVersion . CSharp8 , testCode , expected , fixedCode , CancellationToken . None ) . ConfigureAwait ( false ) ;
117+ }
59118 }
60119}
0 commit comments