@@ -650,11 +650,60 @@ describe('Validation Tests', () => {
650
650
const validator = parseSetup ( content ) ;
651
651
validator
652
652
. then ( function ( result ) {
653
- console . debug ( result ) ;
654
653
assert . equal ( result . length , 0 ) ;
655
654
} )
656
655
. then ( done , done ) ;
657
656
} ) ;
657
+
658
+ it ( 'Anchor reference with a validation error in a sub-object emits the error in the right location' , ( done ) => {
659
+ languageService . addSchema ( SCHEMA_ID , {
660
+ type : 'object' ,
661
+ properties : {
662
+ src : { } ,
663
+ dest : {
664
+ type : 'object' ,
665
+ properties : {
666
+ outer : {
667
+ type : 'object' ,
668
+ required : [ 'otherkey' ] ,
669
+ } ,
670
+ } ,
671
+ } ,
672
+ } ,
673
+ required : [ 'src' , 'dest' ] ,
674
+ } ) ;
675
+ const content = `
676
+ src: &src
677
+ outer:
678
+ akey: avalue
679
+
680
+ dest:
681
+ <<: *src
682
+ ` ;
683
+ const validator = parseSetup ( content ) ;
684
+ validator
685
+ . then ( function ( result ) {
686
+ assert . equal ( result . length , 1 ) ;
687
+ // The key thing we're checking is *where* the validation error gets reported.
688
+ // "outer" isn't required to contain "otherkey" inside "src", but it is inside
689
+ // "dest". Since "outer" doesn't appear inside "dest" because of the alias, we
690
+ // need to move the error into "src".
691
+ assert . deepEqual (
692
+ result [ 0 ] ,
693
+ createDiagnosticWithData (
694
+ MissingRequiredPropWarning . replace ( '{0}' , 'otherkey' ) ,
695
+ 2 ,
696
+ 10 ,
697
+ 2 ,
698
+ 15 ,
699
+ DiagnosticSeverity . Error ,
700
+ `yaml-schema: file:///${ SCHEMA_ID } ` ,
701
+ `file:///${ SCHEMA_ID } `
702
+ )
703
+ ) ;
704
+ } )
705
+ . then ( done , done ) ;
706
+ } ) ;
658
707
} ) ;
659
708
660
709
describe ( 'Custom tag tests' , ( ) => {
0 commit comments