@@ -6,6 +6,7 @@ namespace StyleCop.Analyzers.Test.LayoutRules
66 using System . Threading ;
77 using System . Threading . Tasks ;
88 using StyleCop . Analyzers . LayoutRules ;
9+ using StyleCop . Analyzers . Lightup ;
910 using TestHelper ;
1011 using Xunit ;
1112
@@ -461,5 +462,66 @@ public int[] TestProperty
461462 await this . VerifyCSharpDiagnosticAsync ( fixedTestCode , EmptyDiagnosticResults , CancellationToken . None ) . ConfigureAwait ( false ) ;
462463 await this . VerifyCSharpFixAsync ( testCode , fixedTestCode ) . ConfigureAwait ( false ) ;
463464 }
465+
466+ /// <summary>
467+ /// Verifies that a property declaration missing the opening brace will be handled correctly.
468+ /// </summary>
469+ /// <returns>A <see cref="Task"/> representing the asynchronous unit test.</returns>
470+ [ Fact ]
471+ public async Task TestAccessorMissingOpeningBraceAsync ( )
472+ {
473+ var testCode = @"
474+ class ClassName
475+ {
476+ int Property
477+ {
478+ get
479+ }
480+ }
481+ }" ;
482+
483+ DiagnosticResult accessorError ;
484+ if ( LightupHelpers . SupportsCSharp7 )
485+ {
486+ accessorError = this . CSharpCompilerError ( "CS8180" ) . WithMessage ( "{ or ; or => expected" ) ;
487+ }
488+ else
489+ {
490+ accessorError = this . CSharpCompilerError ( "CS1043" ) . WithMessage ( "{ or ; expected" ) ;
491+ }
492+
493+ DiagnosticResult [ ] expected =
494+ {
495+ accessorError . WithLocation ( 6 , 12 ) ,
496+ this . CSharpCompilerError ( "CS1022" ) . WithMessage ( "Type or namespace definition, or end-of-file expected" ) . WithLocation ( 9 , 1 ) ,
497+ } ;
498+ await this . VerifyCSharpDiagnosticAsync ( testCode , expected , CancellationToken . None ) . ConfigureAwait ( false ) ;
499+ }
500+
501+ /// <summary>
502+ /// Verifies that a property declaration missing the closing brace at the end of the source file will be handled
503+ /// correctly.
504+ /// </summary>
505+ /// <returns>A <see cref="Task"/> representing the asynchronous unit test.</returns>
506+ [ Fact ]
507+ public async Task TestAccessorMissingClosingBraceAtEndOfFileAsync ( )
508+ {
509+ var testCode = @"
510+ class ClassName
511+ {
512+ int Property
513+ {
514+ get
515+ {" ;
516+
517+ DiagnosticResult [ ] expected =
518+ {
519+ this . CSharpCompilerError ( "CS0161" ) . WithMessage ( "'ClassName.Property.get': not all code paths return a value" ) . WithLocation ( 6 , 9 ) ,
520+ this . CSharpCompilerError ( "CS1513" ) . WithMessage ( "} expected" ) . WithLocation ( 7 , 10 ) ,
521+ this . CSharpCompilerError ( "CS1513" ) . WithMessage ( "} expected" ) . WithLocation ( 7 , 10 ) ,
522+ this . CSharpCompilerError ( "CS1513" ) . WithMessage ( "} expected" ) . WithLocation ( 7 , 10 ) ,
523+ } ;
524+ await this . VerifyCSharpDiagnosticAsync ( testCode , expected , CancellationToken . None ) . ConfigureAwait ( false ) ;
525+ }
464526 }
465527}
0 commit comments