Git object storage and pack files for Eio
at main 80 lines 3.2 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 test_stats_empty () = 16 let s = Git.Diff.stats [] in 17 Alcotest.(check int) "additions" 0 s.additions; 18 Alcotest.(check int) "deletions" 0 s.deletions; 19 Alcotest.(check int) "modifications" 0 s.modifications 20 21let test_stats_mixed () = 22 let h = Git.Hash.of_hex (String.make 40 'a') in 23 let changes = 24 [ 25 Git.Diff.Added { path = "a.txt"; hash = h; perm = `Normal }; 26 Git.Diff.Added { path = "b.txt"; hash = h; perm = `Normal }; 27 Git.Diff.Removed { path = "c.txt"; hash = h; perm = `Normal }; 28 Git.Diff.Modified 29 { 30 path = "d.txt"; 31 old_hash = h; 32 new_hash = h; 33 old_perm = `Normal; 34 new_perm = `Normal; 35 }; 36 ] 37 in 38 let s = Git.Diff.stats changes in 39 Alcotest.(check int) "additions" 2 s.additions; 40 Alcotest.(check int) "deletions" 1 s.deletions; 41 Alcotest.(check int) "modifications" 1 s.modifications 42 43let test_filter_by_path_empty () = 44 let result = Git.Diff.filter_by_path ~prefix:"src" [] in 45 Alcotest.(check int) "empty list" 0 (List.length result) 46 47let test_filter_by_path () = 48 let h = Git.Hash.of_hex (String.make 40 'b') in 49 let changes = 50 [ 51 Git.Diff.Added { path = "src/a.ml"; hash = h; perm = `Normal }; 52 Git.Diff.Added { path = "test/b.ml"; hash = h; perm = `Normal }; 53 Git.Diff.Added { path = "src/lib/c.ml"; hash = h; perm = `Normal }; 54 ] 55 in 56 let filtered = Git.Diff.filter_by_path ~prefix:"src" changes in 57 Alcotest.(check int) "filtered count" 2 (List.length filtered) 58 59let test_pp_change () = 60 let h = Git.Hash.of_hex (String.make 40 'c') in 61 let change = Git.Diff.Added { path = "foo.ml"; hash = h; perm = `Normal } in 62 let s = Fmt.to_to_string Git.Diff.pp_change change in 63 Alcotest.(check bool) "contains path" true (String.length s > 0) 64 65let test_pp_stats () = 66 let s = { Git.Diff.additions = 1; deletions = 2; modifications = 3 } in 67 let out = Fmt.to_to_string Git.Diff.pp_stats s in 68 Alcotest.(check bool) "non-empty" true (String.length out > 0) 69 70let tests = 71 [ 72 Alcotest.test_case "stats_empty" `Quick test_stats_empty; 73 Alcotest.test_case "stats_mixed" `Quick test_stats_mixed; 74 Alcotest.test_case "filter_by_path_empty" `Quick test_filter_by_path_empty; 75 Alcotest.test_case "filter_by_path" `Quick test_filter_by_path; 76 Alcotest.test_case "pp_change" `Quick test_pp_change; 77 Alcotest.test_case "pp_stats" `Quick test_pp_stats; 78 ] 79 80let suite = ("diff", tests)