Skip to content

Commit

Permalink
Add tests for multiple documents in a single file
Browse files Browse the repository at this point in the history
  • Loading branch information
adamvoss committed Jul 15, 2017
1 parent c680399 commit c0903b4
Show file tree
Hide file tree
Showing 2 changed files with 39 additions and 2 deletions.
15 changes: 15 additions & 0 deletions src/test/nodeOffset.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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")
})
})
26 changes: 24 additions & 2 deletions src/test/parser.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1382,7 +1382,7 @@ suite('YAML Parser', () => {
})

suite('Multiple Documents', () => {
test.only("are parsed", function(){
test("are parsed", function () {
const input = `---
value: 1
...
Expand All @@ -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)
})
});

Expand Down

0 comments on commit c0903b4

Please sign in to comment.