-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Some work to improve the handling of text locations by the `TextDocument`. This makes sure that locations are allways at a consistent line colum offset. Previously the first line was 0-based and the remaining lines 1-based. Still not totally sure if we want the position objects to be 0-based like Firethorn or 1-based ready for output to the screen.
- Loading branch information
1 parent
ee8d230
commit f18b1b2
Showing
6 changed files
with
57 additions
and
15 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
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
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 |
---|---|---|
@@ -0,0 +1,32 @@ | ||
module TextTests | ||
|
||
open Feersum.CompilerServices.Text | ||
open Xunit | ||
|
||
[<Fact>] | ||
let ``text document for empty string`` () = | ||
let doc = TextDocument.fromParts "hello.scm" "" | ||
|
||
Assert.Equal(TextPoint.FromParts("hello.scm", 1, 1), TextDocument.offsetToPoint doc 0) | ||
|
||
[<Fact>] | ||
let ``text document points`` () = | ||
let body = | ||
@"(define hello 123) | ||
(let ((id (lammbda (x) x))) (id (hello 123))) | ||
;; Blank lines and comments | ||
990 | ||
" | ||
|
||
let doc = TextDocument.fromParts "test.scm" body | ||
|
||
let c (line, col) off = | ||
Assert.Equal(TextPoint.FromParts("test.scm", line, col), TextDocument.offsetToPoint doc off) | ||
|
||
c (1, 1) 0 | ||
c (6, 1) (body.LastIndexOf("990")) | ||
c (7, 1) (body.LastIndexOf("0") + 2) | ||
c (2, 2) (body.IndexOf("let")) | ||
c (4, 10) (body.IndexOf("lines and comments")) |