forked from
gazagnaire.org/irmin
Persistent store with Git semantics: lazy reads, delayed writes, content-addressing
1open Irmin
2
3let test_git_tree_format () =
4 let node = Codec.Git.empty_node in
5 Alcotest.(check bool) "empty is empty" true (Codec.Git.is_empty node);
6 let h = Hash.sha1 "content" in
7 let node = Codec.Git.add node "file.txt" (`Contents h) in
8 Alcotest.(check bool) "not empty after add" false (Codec.Git.is_empty node);
9 match Codec.Git.find node "file.txt" with
10 | Some (`Contents h') ->
11 Alcotest.(check bool) "find matches" true (Hash.equal h h')
12 | _ -> Alcotest.fail "entry not found"
13
14let test_git_tree_serialization () =
15 let h = Hash.sha1 "content" in
16 let node = Codec.Git.empty_node in
17 let node = Codec.Git.add node "file.txt" (`Contents h) in
18 let bytes = Codec.Git.bytes_of_node node in
19 match Codec.Git.node_of_bytes bytes with
20 | Ok node' ->
21 let entries = Codec.Git.list node' in
22 Alcotest.(check int) "one entry" 1 (List.length entries)
23 | Error (`Msg msg) -> Alcotest.fail msg
24
25let suite =
26 ( "Codec",
27 [
28 Alcotest.test_case "git tree format" `Quick test_git_tree_format;
29 Alcotest.test_case "git tree serialization" `Quick
30 test_git_tree_serialization;
31 ] )