Skip to content

Commit 42ace2e

Browse files
committed
test: enable uri tests on windows with hacks
1 parent 7aa21de commit 42ace2e

File tree

3 files changed

+45
-19
lines changed

3 files changed

+45
-19
lines changed

lsp/src/uri0.ml

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,9 @@
11
open Import
22

3+
module Private = struct
4+
let win32 = ref Sys.win32
5+
end
6+
37
type t = Uri_lexer.t =
48
{ scheme : string option
59
; authority : string
@@ -46,7 +50,7 @@ let to_path t =
4650
|> String.replace_all ~pattern:"%3D" ~with_:"="
4751
|> String.replace_all ~pattern:"%3F" ~with_:"?"
4852
in
49-
if Sys.win32 then path else Filename.concat "/" path
53+
if !Private.win32 then path else Filename.concat "/" path
5054

5155
let of_path (path : string) =
5256
let path = Uri_lexer.escape_path path in

lsp/src/uri0.mli

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,3 +17,7 @@ val to_path : t -> string
1717
val of_path : string -> t
1818

1919
val to_string : t -> string
20+
21+
module Private : sig
22+
val win32 : bool ref
23+
end

lsp/test/uri_tests.ml

Lines changed: 36 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -1,25 +1,43 @@
11
open Lsp
22

3+
let run_with_modes f =
4+
print_endline "Unix:";
5+
Lsp.Uri.Private.win32 := false;
6+
f ();
7+
print_endline "Windows:";
8+
Lsp.Uri.Private.win32 := true;
9+
f ()
10+
11+
let test_uri_parsing =
12+
let test s =
13+
let uri = Uri.t_of_yojson (`String s) in
14+
Printf.printf "%s -> %s\n" s (Uri.to_path uri)
15+
in
16+
fun uris -> run_with_modes (fun () -> List.iter test uris)
17+
318
let%expect_test "test uri parsing" =
4-
let uri = Uri.t_of_yojson (`String "file:///Users/foo") in
5-
print_endline (Uri.to_path uri);
6-
[%expect {|
7-
/Users/foo |}];
8-
print_endline (Uri.to_string uri);
9-
[%expect {| file:///Users/foo |}];
10-
let uri = Uri.t_of_yojson (`String "file:///c:/Users/foo") in
11-
print_endline (Uri.to_path uri);
12-
[%expect {| /c:/Users/foo |}];
13-
print_endline (Uri.to_string uri);
19+
test_uri_parsing [ "file:///Users/foo"; "file:///c:/Users/foo" ];
1420
[%expect {|
15-
file:///c:/Users/foo |}]
21+
Unix:
22+
file:///Users/foo -> /Users/foo
23+
file:///c:/Users/foo -> /c:/Users/foo
24+
Windows:
25+
file:///Users/foo -> Users/foo
26+
file:///c:/Users/foo -> c:/Users/foo |}]
27+
28+
let uri_of_path =
29+
let test path =
30+
let uri = Uri.of_path path in
31+
Printf.printf "%s -> %s\n" path (Uri.to_string uri)
32+
in
33+
fun uris -> run_with_modes (fun () -> List.iter test uris)
1634

1735
let%expect_test "uri of path" =
18-
let uri = Uri.of_path "/foo/bar.ml" in
19-
print_endline (Uri.to_string uri);
20-
[%expect {|
21-
file:///foo/bar.ml |}];
22-
let uri = Uri.of_path "foo/bar.mli" in
23-
print_endline (Uri.to_string uri);
36+
uri_of_path [ "/foo/bar.ml"; "foo/bar.mli" ];
2437
[%expect {|
25-
file:///foo/bar.mli |}]
38+
Unix:
39+
/foo/bar.ml -> file:///foo/bar.ml
40+
foo/bar.mli -> file:///foo/bar.mli
41+
Windows:
42+
/foo/bar.ml -> file:///foo/bar.ml
43+
foo/bar.mli -> file:///foo/bar.mli |}]

0 commit comments

Comments
 (0)