Skip to content

Commit 0f062b3

Browse files
pjsk-stripedatho7561
authored andcommitted
fix test safety for when parse fails
1 parent 9d9e4c4 commit 0f062b3

File tree

1 file changed

+15
-7
lines changed

1 file changed

+15
-7
lines changed

test/yamlParser.test.ts

Lines changed: 15 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
import * as assert from 'assert';
66
import { expect } from 'chai';
77
import { ArrayASTNode, ObjectASTNode, PropertyASTNode } from '../src/languageservice/jsonASTTypes';
8-
import { parse } from './../src/languageservice/parser/yamlParser07';
8+
import { parse, YAMLDocument } from './../src/languageservice/parser/yamlParser07';
99
import { aliasDepth } from '../src/languageservice/parser/ast-converter';
1010

1111
describe('YAML parser', () => {
@@ -248,16 +248,20 @@ describe('YAML parser', () => {
248248
it('parse aliases up to a depth', () => {
249249
// If maxRefCount is set to 1, it will only resolve one layer of aliases, which means
250250
// `b` below will inherit `a`, but `c` will not inherit `a`.
251-
aliasDepth.maxRefCount = 1;
252-
const parsedDocument = parse(`
251+
let parsedDocument: YAMLDocument;
252+
try {
253+
aliasDepth.maxRefCount = 1;
254+
parsedDocument = parse(`
253255
a: &a
254256
foo: "web"
255257
b: &b
256258
<<: *a
257259
c: &c
258260
<<: *b
259261
`);
260-
aliasDepth.maxRefCount = 1000;
262+
} finally {
263+
aliasDepth.maxRefCount = 1000;
264+
}
261265

262266
const anode: ObjectASTNode = (parsedDocument.documents[0].root.children[0] as PropertyASTNode).valueNode as ObjectASTNode;
263267
const aval = anode.properties[0].valueNode;
@@ -278,8 +282,10 @@ c: &c
278282
it('parse aliases up to a depth for multiple objects', () => {
279283
// In the below configuration, `c` will not inherit `a` because of depth issues
280284
// but the following object `o` will still resolve correctly.
281-
aliasDepth.maxRefCount = 1;
282-
const parsedDocument = parse(`
285+
let parsedDocument: YAMLDocument;
286+
try {
287+
aliasDepth.maxRefCount = 1;
288+
parsedDocument = parse(`
283289
a: &a
284290
foo: "web"
285291
b: &b
@@ -290,7 +296,9 @@ c: &c
290296
o: &o
291297
<<: *a
292298
`);
293-
aliasDepth.maxRefCount = 1000;
299+
} finally {
300+
aliasDepth.maxRefCount = 1000;
301+
}
294302

295303
const onode: ObjectASTNode = (parsedDocument.documents[0].root.children[3] as PropertyASTNode).valueNode as ObjectASTNode;
296304
const ovalprops: PropertyASTNode = (onode.properties[0].valueNode as ObjectASTNode).properties[0];

0 commit comments

Comments
 (0)