swim protocol in ocaml interoperable with membership lib and serf cli
1open Alcotest
2
3let hex_to_string hex =
4 let len = String.length hex / 2 in
5 let buf = Bytes.create len in
6 for i = 0 to len - 1 do
7 let c = int_of_string ("0x" ^ String.sub hex (i * 2) 2) in
8 Bytes.set buf i (Char.chr c)
9 done;
10 Bytes.to_string buf
11
12let test_decompress_go_data () =
13 let compressed =
14 hex_to_string
15 "00919461c3e60d0b1057dec861432604082a68d2cc01211144181074cacca103e28d19104cb45c0131e64d1b387234ce49f3c68d8b80"
16 in
17 match Swim.Lzw.decompress_lsb8 compressed with
18 | Ok result ->
19 check string "decompressed matches"
20 "Hello, World! This is a test of LZW compression." result
21 | Error e ->
22 fail
23 (Printf.sprintf "decompression failed: %s" (Swim.Lzw.error_to_string e))
24
25let () =
26 run "lzw"
27 [ ("decompress", [ test_case "go_data" `Quick test_decompress_go_data ]) ]