2017-06-02 01:52:29 +03:00
|
|
|
const prettier = require("../..");
|
|
|
|
|
|
|
|
test("translates cursor correctly in basic case", () => {
|
|
|
|
expect(prettier.formatWithCursor(" 1", { cursorOffset: 2 })).toEqual({
|
|
|
|
formatted: "1;\n",
|
|
|
|
cursorOffset: 1
|
|
|
|
});
|
|
|
|
});
|
2017-06-06 04:51:53 +03:00
|
|
|
|
|
|
|
test("positions cursor relative to closest node, not SourceElement", () => {
|
|
|
|
const code = "return 15";
|
|
|
|
expect(prettier.formatWithCursor(code, { cursorOffset: 15 })).toEqual({
|
|
|
|
formatted: "return 15;\n",
|
|
|
|
cursorOffset: 7
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
test("keeps cursor inside formatted node", () => {
|
|
|
|
const code = "return 15";
|
|
|
|
expect(prettier.formatWithCursor(code, { cursorOffset: 14 })).toEqual({
|
|
|
|
formatted: "return 15;\n",
|
|
|
|
cursorOffset: 14 // TODO fix this
|
|
|
|
});
|
|
|
|
});
|