An embedded, single-file key-value store for OCaml, inspired by BoltDB and LMDB.
1(** Tests for Types module conversions *)
2
3let test_key_string_roundtrip () =
4 let open Lithos.Types in
5 let original = "hello_world" in
6 let key = key_of_string original in
7 let result = string_of_key key in
8 Alcotest.(check string) "key roundtrip" original result
9;;
10
11let test_value_string_roundtrip () =
12 let open Lithos.Types in
13 let original = "test_value_123" in
14 let value = value_of_string original in
15 let result = string_of_value value in
16 Alcotest.(check string) "value string roundtrip" original result
17;;
18
19let test_value_bytes_roundtrip () =
20 let open Lithos.Types in
21 let original = Bytes.of_string "binary_data" in
22 let value = value_of_bytes original in
23 let result = bytes_of_value value in
24 Alcotest.(check bool) "value bytes roundtrip" true (Bytes.equal original result)
25;;
26
27let test_empty_key () =
28 let open Lithos.Types in
29 let key = key_of_string "" in
30 let result = string_of_key key in
31 Alcotest.(check string) "empty key" "" result
32;;
33
34let test_empty_value () =
35 let open Lithos.Types in
36 let value = value_of_string "" in
37 let result = string_of_value value in
38 Alcotest.(check string) "empty value" "" result
39;;
40
41let test_binary_data () =
42 let open Lithos.Types in
43 let original = Bytes.of_string "\x00\x01\x02\xff\xfe\xfd" in
44 let value = value_of_bytes original in
45 let result = bytes_of_value value in
46 Alcotest.(check bool) "binary data preservation" true (Bytes.equal original result)
47;;
48
49let test_value_length () =
50 let open Lithos.Types in
51 let original = "test" in
52 let value = value_of_string original in
53 let len = Bigarray.Array1.dim value in
54 Alcotest.(check int) "value length" (String.length original) len
55;;
56
57let suite =
58 [ "key_string_roundtrip", `Quick, test_key_string_roundtrip
59 ; "value_string_roundtrip", `Quick, test_value_string_roundtrip
60 ; "value_bytes_roundtrip", `Quick, test_value_bytes_roundtrip
61 ; "empty_key", `Quick, test_empty_key
62 ; "empty_value", `Quick, test_empty_value
63 ; "binary_data", `Quick, test_binary_data
64 ; "value_length", `Quick, test_value_length
65 ]
66;;