Seppo.Social -> Seppo.mro.name
[Seppo.git] / test / t_ds_cdb.ml
blob0978ee1e67ff56095ec1b38f688c643fafb85965
1 open Seppo_lib
3 let find_1 (fn : string) (k : string) : string option =
4 let cdb = fn |> Ds_cdb.open_cdb_in in
5 let ret =
6 match k |> Bytes.of_string |> Ds_cdb.find_first cdb with
7 | Some b -> Some (b |> Bytes.to_string)
8 | None -> None
9 in
10 cdb |> Ds_cdb.close_cdb_in;
11 ret
13 let test_find_1 () =
14 "s" |> find_1 "mini.cdb" |> Option.get |> Assrt.equals_string __LOC__ "ß";
15 assert (None = ("zzz" |> find_1 "mini.cdb"));
16 assert true
18 let test_make () =
19 let fn = "tmp/t.cdb" in
20 (try Unix.unlink fn with Unix.Unix_error (_, _, _) -> ());
21 let cdb = Ds_cdb.open_out fn in
22 Ds_cdb.add cdb ("k" |> Bytes.of_string) ("v" |> Bytes.of_string);
23 Ds_cdb.close_cdb_out cdb;
25 find_1 fn "k" |> Option.get |> Assrt.equals_string __LOC__ "v";
26 assert true
28 let () =
29 Unix.chdir "../../../test/";
30 test_find_1 ();
31 test_make ();
32 assert true