Skip to content

Commit 24b043b

Browse files
committed
Assert "root"
1 parent b1640a1 commit 24b043b

File tree

1 file changed

+22
-3
lines changed

1 file changed

+22
-3
lines changed

tests/yaml-test-suite/yaml-test-suite.test.ts

Lines changed: 22 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
import * as YAML from "yaml";
12
import yamlTestSuite from "yaml-test-suite";
23
import { parse } from "../../src/parse.ts";
34

@@ -21,11 +22,29 @@ for (const { id, cases, name } of yamlTestSuite) {
2122

2223
if ("fail" in testCase && testCase.fail) {
2324
expect(() => parse(input)).toThrowErrorMatchingSnapshot();
25+
return;
26+
}
27+
28+
const ast = parse(input);
29+
expect(ast.type).toBe("root");
30+
expect(ast.position.start).toStrictEqual({
31+
line: 1,
32+
column: 1,
33+
offset: 0,
34+
});
35+
expect(ast.position.end.offset).toBe(input.length);
36+
37+
const yamlDocuments = YAML.parseAllDocuments(input);
38+
// Fixing
39+
if (filename !== "8G76.yaml" && filename !== "98YD.yaml") {
40+
expect(ast.children.length).toBe(yamlDocuments.length);
2441
} else {
25-
await expect({ input, ast: parse(input) }).toMatchFileSnapshot(
26-
`ast-snapshots/${fileBasename}.snapshot.yaml`,
27-
);
42+
expect(ast.children.length).not.toBe(yamlDocuments.length);
2843
}
44+
45+
await expect({ input, ast: parse(input) }).toMatchFileSnapshot(
46+
`ast-snapshots/${fileBasename}.snapshot.yaml`,
47+
);
2948
},
3049
);
3150
}

0 commit comments

Comments
 (0)