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