diff --git a/src/test/nodeOffset.test.ts b/src/test/nodeOffset.test.ts index 16fa94b..bbc61b6 100644 --- a/src/test/nodeOffset.test.ts +++ b/src/test/nodeOffset.test.ts @@ -30,4 +30,19 @@ suite("Get Node from Offset", () => { // assertNameAndType(19, [], "property") //https://github.com/mulesoft-labs/yaml-ast-parser/issues/25 // assertNameAndType(21, ["outer"], "property") //https://github.com/mulesoft-labs/yaml-ast-parser/issues/25 }) + + test('Multiple Documents', function(){ + const input = `--- +value: 1 +... +--- +value: 2 +...` + + const document = YamlParser.parse(input) + const node = document.getNodeFromOffset(23) + + assert.deepStrictEqual(node.getPath(), ["value"]) + assert.deepEqual(node.type, "string") + }) }) \ No newline at end of file diff --git a/src/test/parser.test.ts b/src/test/parser.test.ts index fe774e3..44f6b94 100644 --- a/src/test/parser.test.ts +++ b/src/test/parser.test.ts @@ -1382,7 +1382,7 @@ suite('YAML Parser', () => { }) suite('Multiple Documents', () => { - test.only("are parsed", function(){ + test("are parsed", function () { const input = `--- value: 1 ... @@ -1391,7 +1391,29 @@ value: 2 ...` isValid(input); const result = YamlParser.parse(input) - console.log(result) + + const values = result.documents.map(d => d.root.getValue()) + assert.deepEqual(values, [{ value: 1 }, { value: 2 }]) + }) + + test("are validated", function () { + const input = `--- +value: 1 +... +--- +value: hello +...` + + const doc = YamlParser.parse(input) + const schema: JsonSchema.JSONSchema = { + additionalProperties: { + type: 'number' + } + }; + doc.validate(schema) + + assert.strictEqual(doc.errors.length, 0) + assert.strictEqual(doc.warnings.length, 1) }) });