(** Input validation for repository names, hashes, branch names and tag names. *) let test_valid_repo_names () = Alcotest.(check bool) "project.git" true (Ogit.Resolvers.is_valid_repo_name "project.git"); Alcotest.(check bool) "project" true (Ogit.Resolvers.is_valid_repo_name "project"); Alcotest.(check bool) "nested/repo" true (Ogit.Resolvers.is_valid_repo_name "nested/repo") let test_invalid_repo_names () = List.iter (fun name -> Alcotest.(check bool) (Printf.sprintf "reject %S" name) false (Ogit.Resolvers.is_valid_repo_name name)) [ ""; ".hidden"; "."; ".."; "../outside"; ".hidden/repo"; "nested/.hidden"; "nested\\repo"; "bad\x00repo"; ] let test_valid_hash_hex () = Alcotest.(check bool) "40 lowercase hex" true (Ogit.Resolvers.is_valid_hash_hex (String.make 40 'a')); Alcotest.(check bool) "40 uppercase hex" true (Ogit.Resolvers.is_valid_hash_hex (String.make 40 'A')) let test_invalid_hash_hex () = Alcotest.(check bool) "39 chars" false (Ogit.Resolvers.is_valid_hash_hex (String.make 39 'a')); Alcotest.(check bool) "41 chars" false (Ogit.Resolvers.is_valid_hash_hex (String.make 41 'a')); Alcotest.(check bool) "non-hex char" false (Ogit.Resolvers.is_valid_hash_hex (String.make 39 'a' ^ "x")) let test_short_hash () = Alcotest.(check string) "short input" "abc" (Ogit.Resolvers.short_hash "abc"); Alcotest.(check string) "long input" "01234567" (Ogit.Resolvers.short_hash "0123456789") let test_branch_name () = Alcotest.(check (option string)) "main" (Some "main") (Ogit.Resolvers.Reference.branch_name "refs/heads/main"); Alcotest.(check (option string)) "feature/topic" (Some "feature/topic") (Ogit.Resolvers.Reference.branch_name "refs/heads/feature/topic"); Alcotest.(check (option string)) "HEAD" None (Ogit.Resolvers.Reference.branch_name "HEAD") let test_tag_name () = Alcotest.(check (option string)) "v1.0.0" (Some "v1.0.0") (Ogit.Resolvers.Reference.tag_name "refs/tags/v1.0.0"); Alcotest.(check (option string)) "not a tag" None (Ogit.Resolvers.Reference.tag_name "refs/heads/v1.0.0") let suite = ( "validation", [ Alcotest.test_case "valid repo names" `Quick test_valid_repo_names; Alcotest.test_case "invalid repo names" `Quick test_invalid_repo_names; Alcotest.test_case "valid hash hex" `Quick test_valid_hash_hex; Alcotest.test_case "invalid hash hex" `Quick test_invalid_hash_hex; Alcotest.test_case "short hash" `Quick test_short_hash; Alcotest.test_case "branch name" `Quick test_branch_name; Alcotest.test_case "tag name" `Quick test_tag_name; ] )