2025-11-03 01:52:26 +08:00
|
|
|
import { cursor, hardline } from "../../src/document/index.js";
|
2025-11-02 21:18:15 +08:00
|
|
|
import { printDocToString } from "../../src/document/printer/printer.js";
|
2022-08-26 21:33:49 +08:00
|
|
|
|
2022-09-06 15:57:47 +03:00
|
|
|
const options = { printWidth: 80, tabWidth: 2 };
|
|
|
|
|
|
2022-08-26 21:33:49 +08:00
|
|
|
test("Should reject if too many cursor in doc", () => {
|
|
|
|
|
expect(() => {
|
2022-09-06 15:57:47 +03:00
|
|
|
printDocToString([cursor, cursor, cursor], options);
|
2022-08-26 21:33:49 +08:00
|
|
|
}).toThrow({ message: "There are too many 'cursor' in doc." });
|
|
|
|
|
});
|
2022-09-06 15:57:47 +03:00
|
|
|
|
|
|
|
|
test("Should trim blank first line", () => {
|
|
|
|
|
expect(
|
2026-06-08 18:16:28 +08:00
|
|
|
printDocToString([" ".repeat(3), hardline, "Prettier", hardline], options)
|
2022-09-06 15:57:47 +03:00
|
|
|
.formatted,
|
|
|
|
|
).toBe("\nPrettier\n");
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
test("Should properly trim with cursor", () => {
|
|
|
|
|
expect(
|
|
|
|
|
printDocToString(
|
2024-09-27 14:35:32 +01:00
|
|
|
["123", cursor, "Prettier \t", cursor, "\t \t", hardline],
|
2022-09-06 15:57:47 +03:00
|
|
|
options,
|
|
|
|
|
),
|
2026-01-22 23:53:24 +08:00
|
|
|
).toStrictEqual({
|
2024-09-27 14:35:32 +01:00
|
|
|
formatted: "123Prettier\n",
|
|
|
|
|
cursorNodeStart: 3,
|
2022-09-06 15:57:47 +03:00
|
|
|
cursorNodeText: "Prettier",
|
|
|
|
|
});
|
|
|
|
|
});
|