Something went wrong. Try again.
Git format in pure OCaml
Something went wrong. Try again.
12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849(* Copyright (c) 2024-2026 Thomas Gazagnaire <thomas@gazagnaire.org>
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 check = Alcotest.(check (option (pair string string)))
let test_parse () = check "key and value" (Some ("tree", "abc123")) (Git.Object_header.parse "tree abc123"); check "value keeps spaces" (Some ("author", "A U Thor <a@example.com> 1700000000 +0000")) (Git.Object_header.parse "author A U Thor <a@example.com> 1700000000 +0000"); check "splits at first space only" (Some ("k", "a b c")) (Git.Object_header.parse "k a b c")
let test_reject () = check "no space" None (Git.Object_header.parse "treeabc123"); check "empty line" None (Git.Object_header.parse "")
let test_edges () = check "leading space gives empty key" (Some ("", "tree abc")) (Git.Object_header.parse " tree abc"); check "trailing space gives empty value" (Some ("tree", "")) (Git.Object_header.parse "tree "); check "lone space" (Some ("", "")) (Git.Object_header.parse " ")
let tests = [ Alcotest.test_case "parse" `Quick test_parse; Alcotest.test_case "reject" `Quick test_reject; Alcotest.test_case "edges" `Quick test_edges; ]
let suite = ("object_header", tests)