Skip to content

Commit

Permalink
test: reproduce #1207
Browse files Browse the repository at this point in the history
Signed-off-by: Rudi Grinberg <me@rgrinberg.com>

<!-- ps-id: 271f1802-b582-4bac-b946-fe86c8e85541 -->
  • Loading branch information
rgrinberg committed Nov 28, 2023
1 parent 9dc8de2 commit 906177b
Showing 1 changed file with 21 additions and 0 deletions.
21 changes: 21 additions & 0 deletions lsp/test/text_document_tests.ml
Original file line number Diff line number Diff line change
Expand Up @@ -240,3 +240,24 @@ let%expect_test "absolute_position" =
[%expect {| position: 7/13 |}];
test (100, 0);
[%expect {| position: 13/13 |}]

let%expect_test "replace second line first line is \\n" =
let range = tuple_range (1, 2) (1, 2) in
let doc = make_document (Uri.of_path "foo.ml") ~text:"\nfoo\nbar\nbaz\n" in
let edit = TextEdit.create ~newText:"change" ~range in
Text_document.apply_text_document_edits doc [ edit ]
|> Text_document.text |> String.escaped |> print_endline;
[%expect {|
\nfochange\nfoo\nbar\nbaz\n |}]

let%expect_test "get position after change" =
let range = tuple_range (1, 2) (1, 2) in
let doc = make_document (Uri.of_path "foo.ml") ~text:"\nfoo\nbar\nbaz\n" in
let edit = TextDocumentContentChangeEvent.create ~text:"change" ~range () in
let new_doc = Text_document.apply_content_changes doc [ edit ] in
let pos = Text_document.absolute_position new_doc range.start in
new_doc |> Text_document.text |> String.escaped |> print_endline;
printf "pos: %d\n" pos;
[%expect {|
\nfochangeo\nbar\nbaz\n
pos: 19 |}]

0 comments on commit 906177b

Please sign in to comment.