(* Copyright (c) 2024-2026 Thomas Gazagnaire Permission to use, copy, modify, and distribute this software for any purpose with or without fee is hereby granted, provided that the above copyright notice and this permission notice appear in all copies. THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. *) let hash = Test_helpers.hash let test_basic () = let r = Git.Reference.v "refs/heads/main" in Alcotest.(check string) "to_string" "refs/heads/main" (Git.Reference.to_string r); Alcotest.(check (list string)) "segs" [ "refs"; "heads"; "main" ] (Git.Reference.segs r) let test_contents () = let h = Git.Hash.of_hex "da39a3ee5e6b4b0d3255bfef95601890afd80709" in let hash_contents = Git.Reference.Hash h in let s = Git.Reference.contents_to_string hash_contents in (match Git.Reference.contents_of_string s with | Ok (Git.Reference.Hash h') -> Alcotest.(check hash) "hash" h h' | Ok (Git.Reference.Ref _) -> Alcotest.fail "expected hash" | Error (`Msg m) -> Alcotest.fail m); let ref_contents = Git.Reference.Ref (Git.Reference.v "refs/heads/main") in let s = Git.Reference.contents_to_string ref_contents in match Git.Reference.contents_of_string s with | Ok (Git.Reference.Ref r) -> Alcotest.(check string) "ref" "refs/heads/main" (Git.Reference.to_string r) | Ok (Git.Reference.Hash _) -> Alcotest.fail "expected ref" | Error (`Msg m) -> Alcotest.fail m let tests = [ Alcotest.test_case "basic" `Quick test_basic; Alcotest.test_case "contents" `Quick test_contents; ] let suite = ("reference", tests)