Skip to content

Commit

Permalink
Fix minor issue in formatting error snippets
Browse files Browse the repository at this point in the history
  • Loading branch information
rlidwka committed Dec 18, 2020
1 parent 4508352 commit 38528f7
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 1 deletion.
2 changes: 1 addition & 1 deletion lib/snippet.js
Expand Up @@ -52,7 +52,7 @@ function makeSnippet(mark, options) {
lineEnds.push(match.index);
lineStarts.push(match.index + match[0].length);

if (mark.position < match.index && foundLineNo < 0) {
if (mark.position <= match.index && foundLineNo < 0) {
foundLineNo = lineStarts.length - 2;
}
}
Expand Down
22 changes: 22 additions & 0 deletions test/issues/0332.js
Expand Up @@ -15,4 +15,26 @@ it('Should format errors', function () {
1 | "foo\u0001bar"
-------------^`);
}

try {
yaml.load('*');
} catch (err) {
assert.strictEqual(err.toString(), `YAMLException: name of an alias node must contain at least one character (1:2)
1 | *
------^`);
}

try {
yaml.load('foo:\n bar: 1\na');
} catch (err) {
// eslint-disable-next-line max-len
assert.strictEqual(err.toString(), `YAMLException: can not read a block mapping entry; a multiline key may not be an implicit key (4:1)
1 | foo:
2 | bar: 1
3 | a
4 |
-----^`);
}
});

0 comments on commit 38528f7

Please sign in to comment.