Skip to content

Commit

Permalink
Showing 2 changed files with 36 additions and 0 deletions.
28 changes: 28 additions & 0 deletions __tests__/corner-cases.js
Original file line number Diff line number Diff line change
@@ -53,3 +53,31 @@ test('eemeli/yaml#8', () => {
expect(doc.errors).toHaveLength(1)
expect(doc.errors[0]).toBeInstanceOf(YAMLSemanticError)
})

describe('eemeli/yaml#10', () => {
test('reported', () => {
const src = `
aliases:
- restore_cache:
- v1-yarn-cache
- save_cache:
paths:
- ~/.cache/yarn
- &restore_deps_cache
keys:
- v1-deps-cache-{{ checksum "yarn.lock" }}\n`
const docs = YAML.parseDocuments(src)
expect(docs).toHaveLength(1)
expect(docs[0].errors).toHaveLength(0)
})
test('minimal', () => {
const src = `
- a
- b:
- c
- d`
const docs = YAML.parseDocuments(src)
expect(docs[0].errors).toHaveLength(0)
expect(docs[0].toJSON()).toMatchObject(['a', { b: ['c'] }, 'd'])
})
})
8 changes: 8 additions & 0 deletions src/ast/Collection.js
Original file line number Diff line number Diff line change
@@ -98,6 +98,14 @@ export default class Collection extends Node {
offset = Node.normalizeOffset(src, node.range.end)
ch = src[offset]
atLineStart = false
// Need to reset lineStart here if preceding node's range has advanced to
// check the current line's indentation level -- eemeli/yaml#10
if (ch && ch !== '\n' && ch !== '#') {
let ls = offset - 1
let prev = src[ls]
while (prev === ' ' || prev === '\t') prev = src[--ls]
if (prev === '\n') lineStart = ls
}
trace: 'item-end', node.type, { offset, ch: JSON.stringify(ch) }
}
trace: 'items', this.items

0 comments on commit 50f0073

Please sign in to comment.