-
Notifications
You must be signed in to change notification settings - Fork 123
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
test: enable uri tests on windows with hacks
- Loading branch information
Showing
3 changed files
with
45 additions
and
19 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,25 +1,43 @@ | ||
open Lsp | ||
|
||
let run_with_modes f = | ||
print_endline "Unix:"; | ||
Lsp.Uri.Private.win32 := false; | ||
f (); | ||
print_endline "Windows:"; | ||
Lsp.Uri.Private.win32 := true; | ||
f () | ||
|
||
let test_uri_parsing = | ||
let test s = | ||
let uri = Uri.t_of_yojson (`String s) in | ||
Printf.printf "%s -> %s\n" s (Uri.to_path uri) | ||
in | ||
fun uris -> run_with_modes (fun () -> List.iter test uris) | ||
|
||
let%expect_test "test uri parsing" = | ||
let uri = Uri.t_of_yojson (`String "file:///Users/foo") in | ||
print_endline (Uri.to_path uri); | ||
[%expect {| | ||
/Users/foo |}]; | ||
print_endline (Uri.to_string uri); | ||
[%expect {| file:///Users/foo |}]; | ||
let uri = Uri.t_of_yojson (`String "file:///c:/Users/foo") in | ||
print_endline (Uri.to_path uri); | ||
[%expect {| /c:/Users/foo |}]; | ||
print_endline (Uri.to_string uri); | ||
test_uri_parsing [ "file:///Users/foo"; "file:///c:/Users/foo" ]; | ||
[%expect {| | ||
file:///c:/Users/foo |}] | ||
Unix: | ||
file:///Users/foo -> /Users/foo | ||
file:///c:/Users/foo -> /c:/Users/foo | ||
Windows: | ||
file:///Users/foo -> Users/foo | ||
file:///c:/Users/foo -> c:/Users/foo |}] | ||
|
||
let uri_of_path = | ||
let test path = | ||
let uri = Uri.of_path path in | ||
Printf.printf "%s -> %s\n" path (Uri.to_string uri) | ||
in | ||
fun uris -> run_with_modes (fun () -> List.iter test uris) | ||
|
||
let%expect_test "uri of path" = | ||
let uri = Uri.of_path "/foo/bar.ml" in | ||
print_endline (Uri.to_string uri); | ||
[%expect {| | ||
file:///foo/bar.ml |}]; | ||
let uri = Uri.of_path "foo/bar.mli" in | ||
print_endline (Uri.to_string uri); | ||
uri_of_path [ "/foo/bar.ml"; "foo/bar.mli" ]; | ||
[%expect {| | ||
file:///foo/bar.mli |}] | ||
Unix: | ||
/foo/bar.ml -> file:///foo/bar.ml | ||
foo/bar.mli -> file:///foo/bar.mli | ||
Windows: | ||
/foo/bar.ml -> file:///foo/bar.ml | ||
foo/bar.mli -> file:///foo/bar.mli |}] |