Git object storage and pack files for Eio
at main 61 lines 2.5 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_roundtrip () = 18 let tree_hash = Git.Hash.of_hex "da39a3ee5e6b4b0d3255bfef95601890afd80709" in 19 let author = 20 Git.User.v ~name:"Alice" ~email:"alice@example.com" ~date:1234567890L () 21 in 22 let commit = 23 Git.Commit.v ~tree:tree_hash ~author ~committer:author 24 (Some "Initial commit\n") 25 in 26 let s = Git.Commit.to_string commit in 27 match Git.Commit.of_string s with 28 | Ok commit' -> 29 Alcotest.(check hash) "tree" tree_hash (Git.Commit.tree commit'); 30 Alcotest.(check (list hash)) "parents" [] (Git.Commit.parents commit'); 31 Alcotest.(check (option string)) 32 "message" (Some "Initial commit\n") 33 (Git.Commit.message commit') 34 | Error (`Msg m) -> Alcotest.fail m 35 36let test_with_parents () = 37 let tree_hash = Git.Hash.of_hex "da39a3ee5e6b4b0d3255bfef95601890afd80709" in 38 let parent1 = Git.Hash.of_hex "0000000000000000000000000000000000000001" in 39 let parent2 = Git.Hash.of_hex "0000000000000000000000000000000000000002" in 40 let author = 41 Git.User.v ~name:"Alice" ~email:"alice@example.com" ~date:1234567890L () 42 in 43 let commit = 44 Git.Commit.v ~tree:tree_hash ~author ~committer:author 45 ~parents:[ parent1; parent2 ] (Some "Merge commit\n") 46 in 47 let s = Git.Commit.to_string commit in 48 match Git.Commit.of_string s with 49 | Ok commit' -> 50 Alcotest.(check (list hash)) 51 "parents" [ parent1; parent2 ] 52 (Git.Commit.parents commit') 53 | Error (`Msg m) -> Alcotest.fail m 54 55let tests = 56 [ 57 Alcotest.test_case "roundtrip" `Quick test_roundtrip; 58 Alcotest.test_case "with_parents" `Quick test_with_parents; 59 ] 60 61let suite = ("commit", tests)