@@ -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,60 @@ 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+
862+ new DiagnosticResult
863+ {
864+ Id = "CS1513" ,
865+ Severity = DiagnosticSeverity . Error ,
866+ Locations = new [ ] { new DiagnosticResultLocation ( "Test0.cs" , 3 , 28 ) } ,
867+ Message = "} expected"
868+ } ,
869+
870+ new DiagnosticResult
871+ {
872+ Id = "CS1022" ,
873+ Severity = DiagnosticSeverity . Error ,
874+ Locations = new [ ] { new DiagnosticResultLocation ( "Test0.cs" , 3 , 28 ) } ,
875+ Message = "Type or namespace definition, or end-of-file expected"
876+ } ,
877+
878+ new DiagnosticResult
879+ {
880+ Id = "CS1022" ,
881+ Severity = DiagnosticSeverity . Error ,
882+ Locations = new [ ] { new DiagnosticResultLocation ( "Test0.cs" , 6 , 1 ) } ,
883+ Message = "Type or namespace definition, or end-of-file expected"
884+ }
885+ } ;
886+
887+ await this . VerifyCSharpDiagnosticAsync ( testCode , expected , CancellationToken . None ) . ConfigureAwait ( false ) ;
888+ }
889+
835890 /// <inheritdoc/>
836891 protected override IEnumerable < DiagnosticAnalyzer > GetCSharpDiagnosticAnalyzers ( )
837892 {
0 commit comments