Source file Unit_FPath.ml
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
let with_file contents f =
let file, oc = Filename.open_temp_file "test_pfff_read_file_" ".dat" in
Fun.protect
~finally:(fun () ->
close_out_noerr oc;
Sys.remove file)
(fun () ->
output_string oc contents;
close_out oc;
f file)
let realpath s = Common.fullpath s
let test_path_conversion () =
let check_path path =
FPath.to_string (FPath.of_string path) = realpath path
in
let data = String.make 150 'v' in
assert (check_path ".");
assert (check_path "..");
assert (check_path "../..");
assert (FPath.to_string (FPath.of_string "/") = realpath "/");
with_file data (fun file ->
let path = FPath.of_string file in
let max_len = 24 in
assert (FPath.to_string path = realpath file);
assert (FPath.read_file path = data);
assert (FPath.cat path = [ data ]);
assert (FPath.read_file ~max_len path = Str.first_chars data max_len);
assert (FPath.file_exists path);
assert (not (FPath.is_directory path)));
assert (
FPath.to_string FPath.(of_string "." / "." / ".." / "." / "..")
= realpath "../..")
let tests =
Testutil.pack_tests "FPath" [ ("path_conversion", test_path_conversion) ]