forked from prettier/prettier
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Get rid of regexp and handle cursor in trim in doc printer (prettier#…
- Loading branch information
Showing
2 changed files
with
51 additions
and
14 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,8 +1,29 @@ | ||
import { cursor } from "../../src/document/builders.js"; | ||
import { cursor, hardline } from "../../src/document/builders.js"; | ||
import { printDocToString } from "../../src/document/printer.js"; | ||
|
||
const options = { printWidth: 80, tabWidth: 2 }; | ||
|
||
test("Should reject if too many cursor in doc", () => { | ||
expect(() => { | ||
printDocToString([cursor, cursor, cursor], { printWidth: 80, tabWidth: 2 }); | ||
printDocToString([cursor, cursor, cursor], options); | ||
}).toThrow({ message: "There are too many 'cursor' in doc." }); | ||
}); | ||
|
||
test("Should trim blank first line", () => { | ||
expect( | ||
printDocToString([" ", hardline, "Prettier", hardline], options).formatted | ||
).toBe("\nPrettier\n"); | ||
}); | ||
|
||
test("Should properly trim with cursor", () => { | ||
expect( | ||
printDocToString( | ||
[cursor, "Prettier \t", cursor, "\t \t", hardline], | ||
options | ||
) | ||
).toEqual({ | ||
formatted: "Prettier\n", | ||
cursorNodeStart: 0, | ||
cursorNodeText: "Prettier", | ||
}); | ||
}); |