@@ -6,6 +6,7 @@ namespace StyleCop.Analyzers.Test.LayoutRules
66 using System . Collections . Generic ;
77 using System . Threading ;
88 using System . Threading . Tasks ;
9+ using Microsoft . CodeAnalysis ;
910 using Microsoft . CodeAnalysis . CodeFixes ;
1011 using Microsoft . CodeAnalysis . Diagnostics ;
1112 using StyleCop . Analyzers . LayoutRules ;
@@ -832,6 +833,57 @@ public int TestProperty
832833 await this . VerifyCSharpFixAsync ( testCode , fixedTestCode ) . ConfigureAwait ( false ) ;
833834 }
834835
836+ /// <summary>
837+ /// Verifies that an invalid syntax will not crash the analyzer.
838+ /// This is a regression test for #1534
839+ /// </summary>
840+ /// <returns>A <see cref="Task"/> representing the asynchronous unit test.</returns>
841+ [ Fact ]
842+ public async Task TestInvalidSyntaxAsync ( )
843+ {
844+ var testCode = @"namespace TestNamespace
845+ {
846+ public class TestClass /
847+ {
848+ }
849+ }
850+ " ;
851+
852+ DiagnosticResult [ ] expected =
853+ {
854+ new DiagnosticResult
855+ {
856+ Id = "CS1514" ,
857+ Severity = DiagnosticSeverity . Error ,
858+ Locations = new [ ] { new DiagnosticResultLocation ( "Test0.cs" , 3 , 28 ) } ,
859+ Message = "{ expected"
860+ } ,
861+ new DiagnosticResult
862+ {
863+ Id = "CS1513" ,
864+ Severity = DiagnosticSeverity . Error ,
865+ Locations = new [ ] { new DiagnosticResultLocation ( "Test0.cs" , 3 , 28 ) } ,
866+ Message = "} expected"
867+ } ,
868+ new DiagnosticResult
869+ {
870+ Id = "CS1022" ,
871+ Severity = DiagnosticSeverity . Error ,
872+ Locations = new [ ] { new DiagnosticResultLocation ( "Test0.cs" , 3 , 28 ) } ,
873+ Message = "Type or namespace definition, or end-of-file expected"
874+ } ,
875+ new DiagnosticResult
876+ {
877+ Id = "CS1022" ,
878+ Severity = DiagnosticSeverity . Error ,
879+ Locations = new [ ] { new DiagnosticResultLocation ( "Test0.cs" , 6 , 1 ) } ,
880+ Message = "Type or namespace definition, or end-of-file expected"
881+ }
882+ } ;
883+
884+ await this . VerifyCSharpDiagnosticAsync ( testCode , expected , CancellationToken . None ) . ConfigureAwait ( false ) ;
885+ }
886+
835887 /// <inheritdoc/>
836888 protected override IEnumerable < DiagnosticAnalyzer > GetCSharpDiagnosticAnalyzers ( )
837889 {
0 commit comments