Files
languageservices/actions-languageservice/src/test-utils/cursor-position.test.ts
T

33 lines
1.2 KiB
TypeScript
Raw Normal View History

2022-11-15 14:08:12 -05:00
import {getPositionFromCursor} from "./cursor-position";
2022-11-08 17:00:59 -08:00
describe("getPositionFromCursor", () => {
it("returns the position of the cursor and the document without that cursor", () => {
const input = "on: push\njobs:|";
const [newDoc, position] = getPositionFromCursor(input);
2022-11-15 14:08:12 -05:00
expect(position).toEqual({line: 1, character: 5});
2022-11-08 17:00:59 -08:00
expect(newDoc.getText()).toEqual("on: push\njobs:");
});
it("throws an error if no cursor is found", () => {
const input = "on: push\njobs:";
2022-11-15 14:08:12 -05:00
expect(() => getPositionFromCursor(input)).toThrowError("No cursor found in document");
2022-11-08 17:00:59 -08:00
});
it("handles a cursor at the beginning of the document", () => {
const input = "|on: push\njobs:";
const [newDoc, position] = getPositionFromCursor(input);
2022-11-15 14:08:12 -05:00
expect(position).toEqual({line: 0, character: 0});
2022-11-08 17:00:59 -08:00
expect(newDoc.getText()).toEqual("on: push\njobs:");
});
2023-01-18 16:54:53 -08:00
it("handles a cursor in the middle of the document", () => {
const input = "on: push\n jobs|:\n build:";
const [newDoc, position] = getPositionFromCursor(input);
expect(position).toEqual({line: 1, character: 6});
expect(newDoc.getText()).toEqual("on: push\n jobs:\n build:");
});
2022-11-08 17:00:59 -08:00
});