(** Tests for commit message parsing and conventional commit type extraction. These functions drive both the pill display and the commit type filter. *) open Ogit.Views.Repo let test_parse_message_none () = let msg = parse_commit_message None in Alcotest.(check string) "summary" "" msg.summary; Alcotest.(check string) "body" "" msg.body let test_parse_message_single_line () = let msg = parse_commit_message (Some "single line") in Alcotest.(check string) "summary" "single line" msg.summary; Alcotest.(check string) "body" "" msg.body let test_parse_message_with_body () = let msg = parse_commit_message (Some "summary\n\nbody paragraph") in Alcotest.(check string) "summary" "summary" msg.summary; Alcotest.(check string) "body" "body paragraph" msg.body let test_parse_message_body_trimmed () = let msg = parse_commit_message (Some "title\n\n indented\n\n") in Alcotest.(check string) "summary" "title" msg.summary; Alcotest.(check string) "body trimmed" "indented" msg.body let test_conventional_feat () = let typ, rest = parse_conventional "feat: add login" in Alcotest.(check (option string)) "type" (Some "feat") typ; Alcotest.(check string) "rest" "add login" rest let test_conventional_with_scope () = let typ, rest = parse_conventional "fix(auth): handle timeout" in Alcotest.(check (option string)) "type" (Some "fix") typ; Alcotest.(check string) "rest" "handle timeout" rest let test_conventional_uppercase () = let typ, rest = parse_conventional "FEAT: uppercase" in Alcotest.(check (option string)) "type" (Some "feat") typ; Alcotest.(check string) "rest" "uppercase" rest let test_conventional_unknown_type () = let typ, rest = parse_conventional "unknown: something" in Alcotest.(check (option string)) "type" None typ; Alcotest.(check string) "rest" "unknown: something" rest let test_conventional_no_colon () = let typ, rest = parse_conventional "just a message" in Alcotest.(check (option string)) "type" None typ; Alcotest.(check string) "rest" "just a message" rest let test_conventional_empty () = let typ, rest = parse_conventional "" in Alcotest.(check (option string)) "type" None typ; Alcotest.(check string) "rest" "" rest let test_conventional_all_types () = List.iter (fun expected_type -> let input = expected_type ^ ": msg" in let typ, _ = parse_conventional input in Alcotest.(check (option string)) expected_type (Some expected_type) typ) [ "feat"; "fix"; "docs"; "style"; "refactor"; "perf"; "test"; "build"; "ci"; "chore"; "revert"; ] let suite = ( "commit parsing", [ Alcotest.test_case "None message" `Quick test_parse_message_none; Alcotest.test_case "single line" `Quick test_parse_message_single_line; Alcotest.test_case "with body" `Quick test_parse_message_with_body; Alcotest.test_case "body trimmed" `Quick test_parse_message_body_trimmed; Alcotest.test_case "feat type" `Quick test_conventional_feat; Alcotest.test_case "scoped type" `Quick test_conventional_with_scope; Alcotest.test_case "uppercase" `Quick test_conventional_uppercase; Alcotest.test_case "unknown type" `Quick test_conventional_unknown_type; Alcotest.test_case "no colon" `Quick test_conventional_no_colon; Alcotest.test_case "empty string" `Quick test_conventional_empty; Alcotest.test_case "all known types" `Quick test_conventional_all_types; ] )