Add failing test for empty node scenario
This commit is contained in:
@@ -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,
|
||||
|
||||
Reference in New Issue
Block a user