[OCaml] Mobile-friendly clone of cgit.
1
(** Tests for commit message parsing and conventional commit type extraction.
2
These functions drive both the pill display and the commit type filter. *)
3
4
open Ogit.Views.Repo
5
6
let test_parse_message_none () =
7
let msg = parse_commit_message None in
8
Alcotest.(check string) "summary" "" msg.summary;
9
Alcotest.(check string) "body" "" msg.body
10
11
let test_parse_message_single_line () =
12
let msg = parse_commit_message (Some "single line") in
13
Alcotest.(check string) "summary" "single line" msg.summary;
14
Alcotest.(check string) "body" "" msg.body
15
16
let test_parse_message_with_body () =
17
let msg = parse_commit_message (Some "summary\n\nbody paragraph") in
18
Alcotest.(check string) "summary" "summary" msg.summary;
19
Alcotest.(check string) "body" "body paragraph" msg.body
20
21
let test_parse_message_body_trimmed () =
22
let msg = parse_commit_message (Some "title\n\n indented\n\n") in
23
Alcotest.(check string) "summary" "title" msg.summary;
24
Alcotest.(check string) "body trimmed" "indented" msg.body
25
26
let test_conventional_feat () =
27
let typ, rest = parse_conventional "feat: add login" in
28
Alcotest.(check (option string)) "type" (Some "feat") typ;
29
Alcotest.(check string) "rest" "add login" rest
30
31
let test_conventional_with_scope () =
32
let typ, rest = parse_conventional "fix(auth): handle timeout" in
33
Alcotest.(check (option string)) "type" (Some "fix") typ;
34
Alcotest.(check string) "rest" "handle timeout" rest
35
36
let test_conventional_uppercase () =
37
let typ, rest = parse_conventional "FEAT: uppercase" in
38
Alcotest.(check (option string)) "type" (Some "feat") typ;
39
Alcotest.(check string) "rest" "uppercase" rest
40
41
let test_conventional_unknown_type () =
42
let typ, rest = parse_conventional "unknown: something" in
43
Alcotest.(check (option string)) "type" None typ;
44
Alcotest.(check string) "rest" "unknown: something" rest
45
46
let test_conventional_no_colon () =
47
let typ, rest = parse_conventional "just a message" in
48
Alcotest.(check (option string)) "type" None typ;
49
Alcotest.(check string) "rest" "just a message" rest
50
51
let test_conventional_empty () =
52
let typ, rest = parse_conventional "" in
53
Alcotest.(check (option string)) "type" None typ;
54
Alcotest.(check string) "rest" "" rest
55
56
let test_conventional_all_types () =
57
List.iter
58
(fun expected_type ->
59
let input = expected_type ^ ": msg" in
60
let typ, _ = parse_conventional input in
61
Alcotest.(check (option string)) expected_type (Some expected_type) typ)
62
[
63
"feat";
64
"fix";
65
"docs";
66
"style";
67
"refactor";
68
"perf";
69
"test";
70
"build";
71
"ci";
72
"chore";
73
"revert";
74
]
75
76
let suite =
77
( "commit parsing",
78
[
79
Alcotest.test_case "None message" `Quick test_parse_message_none;
80
Alcotest.test_case "single line" `Quick test_parse_message_single_line;
81
Alcotest.test_case "with body" `Quick test_parse_message_with_body;
82
Alcotest.test_case "body trimmed" `Quick test_parse_message_body_trimmed;
83
Alcotest.test_case "feat type" `Quick test_conventional_feat;
84
Alcotest.test_case "scoped type" `Quick test_conventional_with_scope;
85
Alcotest.test_case "uppercase" `Quick test_conventional_uppercase;
86
Alcotest.test_case "unknown type" `Quick test_conventional_unknown_type;
87
Alcotest.test_case "no colon" `Quick test_conventional_no_colon;
88
Alcotest.test_case "empty string" `Quick test_conventional_empty;
89
Alcotest.test_case "all known types" `Quick test_conventional_all_types;
90
] )
91