forked from realworldocaml/mdx
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtest_block.ml
49 lines (47 loc) · 1.79 KB
/
test_block.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
40
41
42
43
44
45
46
47
48
49
let test_infer_from_file =
let make_test ~file ~expected =
let test_name = Printf.sprintf "Header.infer_from_file: %S" file in
let test_fun () =
let actual = Mdx.Block.Header.infer_from_file file in
Alcotest.(check (option Testable.header)) test_name expected actual
in
(test_name, `Quick, test_fun)
in
[
make_test ~file:"" ~expected:None;
make_test ~file:"foo" ~expected:None;
make_test ~file:"foo.bar" ~expected:None;
make_test ~file:"dune" ~expected:(Some (Other "scheme"));
make_test ~file:"dune-project" ~expected:(Some (Other "scheme"));
make_test ~file:"foo.sh" ~expected:(Some (Shell `Sh));
make_test ~file:"foo/foo/foo.ml" ~expected:(Some OCaml);
]
let test_mk =
let make_test ~name ~labels ~header ~contents ~expected =
let test_name = Printf.sprintf "mk: %S" name in
let test_fun () =
let actual =
Mdx.Block.mk ~loc:Location.none ~section:None ~labels
~legacy_labels:false ~header ~contents ~errors:[] ~delim:None
in
let expected =
Result.map_error
(function
| `Msg m ->
`Msg ({|File "_none_", line 1: invalid code block: |} ^ m))
expected
in
Alcotest.(check (Testable.errormsg Testable.block))
test_name expected actual
in
(test_name, `Quick, test_fun)
in
[
make_test ~name:"invalid ocaml" ~labels:[ Block_kind OCaml ]
~header:(Some OCaml) ~contents:[ "# let x = 2;;" ]
~expected:(Error (`Msg "toplevel syntax is not allowed in OCaml blocks."));
make_test ~name:"invalid toplevel" ~labels:[ Block_kind Toplevel ]
~header:(Some OCaml) ~contents:[ "let x = 2;;" ]
~expected:(Error (`Msg "invalid toplevel syntax in toplevel blocks."));
]
let suite = ("Block", test_infer_from_file @ test_mk)