Skip to content

Commit 3992663

Browse files
andrew-stripeevidolob
authored andcommitted
Add another test for anchor error rendering
1 parent b546073 commit 3992663

File tree

1 file changed

+50
-1
lines changed

1 file changed

+50
-1
lines changed

test/schemaValidation.test.ts

+50-1
Original file line numberDiff line numberDiff line change
@@ -650,11 +650,60 @@ describe('Validation Tests', () => {
650650
const validator = parseSetup(content);
651651
validator
652652
.then(function (result) {
653-
console.debug(result);
654653
assert.equal(result.length, 0);
655654
})
656655
.then(done, done);
657656
});
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+
});
658707
});
659708

660709
describe('Custom tag tests', () => {

0 commit comments

Comments
 (0)