Git object storage and pack files for Eio
at main 51 lines 2.1 kB view raw
1(* Copyright (c) 2024-2026 Thomas Gazagnaire <thomas@gazagnaire.org> 2 3 Permission to use, copy, modify, and distribute this software for any 4 purpose with or without fee is hereby granted, provided that the above 5 copyright notice and this permission notice appear in all copies. 6 7 THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES 8 WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF 9 MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR 10 ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES 11 WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN 12 ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF 13 OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. *) 14 15let hash = Test_helpers.hash 16 17let test_basic () = 18 let r = Git.Reference.v "refs/heads/main" in 19 Alcotest.(check string) 20 "to_string" "refs/heads/main" 21 (Git.Reference.to_string r); 22 Alcotest.(check (list string)) 23 "segs" 24 [ "refs"; "heads"; "main" ] 25 (Git.Reference.segs r) 26 27let test_contents () = 28 let h = Git.Hash.of_hex "da39a3ee5e6b4b0d3255bfef95601890afd80709" in 29 let hash_contents = Git.Reference.Hash h in 30 let s = Git.Reference.contents_to_string hash_contents in 31 (match Git.Reference.contents_of_string s with 32 | Ok (Git.Reference.Hash h') -> Alcotest.(check hash) "hash" h h' 33 | Ok (Git.Reference.Ref _) -> Alcotest.fail "expected hash" 34 | Error (`Msg m) -> Alcotest.fail m); 35 let ref_contents = Git.Reference.Ref (Git.Reference.v "refs/heads/main") in 36 let s = Git.Reference.contents_to_string ref_contents in 37 match Git.Reference.contents_of_string s with 38 | Ok (Git.Reference.Ref r) -> 39 Alcotest.(check string) 40 "ref" "refs/heads/main" 41 (Git.Reference.to_string r) 42 | Ok (Git.Reference.Hash _) -> Alcotest.fail "expected ref" 43 | Error (`Msg m) -> Alcotest.fail m 44 45let tests = 46 [ 47 Alcotest.test_case "basic" `Quick test_basic; 48 Alcotest.test_case "contents" `Quick test_contents; 49 ] 50 51let suite = ("reference", tests)