Add failing test for empty node scenario

This commit is contained in:
Christopher Schleiden
2022-11-23 07:43:29 -08:00
parent 99a9f08a3c
commit 1901924387
2 changed files with 16 additions and 1 deletions
@@ -174,4 +174,18 @@ jobs:
token: ["job", TokenType.String, "runs-"]
});
});
it("empty node", () => {
expect(
testFindToken(`on: push
jobs:
build:
concurrency:
runs-on: ubu|`)
).toEqual({
parent: ["job-factory", TokenType.Mapping],
key: [null, TokenType.String, "runs-on"],
token: ["runs-on", TokenType.String, "ubu"]
});
});
});
@@ -67,6 +67,7 @@ export function findToken(pos: Position, root?: TemplateToken): TokenResult {
for (let i = 0; i < mappingToken.count; i++) {
const {key, value} = mappingToken.get(i);
// If the position is within the key, immediately return it as the token.
if (posInToken(pos, key)) {
return {
parent: mappingToken,
@@ -75,7 +76,7 @@ export function findToken(pos: Position, root?: TemplateToken): TokenResult {
};
}
// Empty nodes positions won't always match the cursor, so check if we're on the same line
// If the value is an empty node (null, empty string)
if (emptyNode(value)) {
return {
parent: mappingToken,