Skip to content

Commit

Permalink
update to ocamlformat 0.21
Browse files Browse the repository at this point in the history
  • Loading branch information
hannesm committed Apr 6, 2022
1 parent b0fd5e8 commit 0f82a37
Show file tree
Hide file tree
Showing 7 changed files with 29 additions and 53 deletions.
2 changes: 1 addition & 1 deletion .ocamlformat
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
version=0.17.0
version=0.21.0
module-item-spacing=compact
break-struct=natural
break-infix=fit-or-vertical
Expand Down
3 changes: 1 addition & 2 deletions bin/pipe.ml
Original file line number Diff line number Diff line change
Expand Up @@ -192,8 +192,7 @@ let command =
compressed/decompressed data to standard output."
] in
let term = Term.(ret (const run $ deflate $ format))
and info = Cmd.info "pipe" ~doc ~man
in
and info = Cmd.info "pipe" ~doc ~man in
Cmd.v info term

let () = exit (Cmd.eval' command)
2 changes: 0 additions & 2 deletions lib/de.ml
Original file line number Diff line number Diff line change
Expand Up @@ -641,7 +641,6 @@ module Inf = struct
| End_of_inflate

and jump = Length | Extra_length | Distance | Extra_distance | Write

and ret = Await | Flush | End | K | Malformed of string

let malformedf fmt = kstrf (fun s -> Malformed s) fmt
Expand Down Expand Up @@ -3911,7 +3910,6 @@ module Lz77 = struct
let _8 = {good_length= 32; max_lazy= 128; nice_length= 258; max_chain= 1024}
let _9 = {good_length= 32; max_lazy= 258; nice_length= 258; max_chain= 4096}
let _mem_level = 8 (* default *)

let _hash_bits = _mem_level + 7
let _hash_size = 1 lsl _hash_bits
let _hash_mask = _hash_size - 1
Expand Down
1 change: 0 additions & 1 deletion lib/lz.ml
Original file line number Diff line number Diff line change
Expand Up @@ -147,7 +147,6 @@ let _7 = {good_length= 8; max_lazy= 32; nice_length= 128; max_chain= 256}
let _8 = {good_length= 32; max_lazy= 128; nice_length= 258; max_chain= 1024}
let _9 = {good_length= 32; max_lazy= 258; nice_length= 258; max_chain= 4096}
let _mem_level = 8 (* default *)

let _hash_bits = _mem_level + 7
let _hash_size = 1 lsl _hash_bits
let _hash_mask = _hash_size - 1
Expand Down
1 change: 0 additions & 1 deletion lib/lzo.ml
Original file line number Diff line number Diff line change
Expand Up @@ -175,7 +175,6 @@ type ('a, 'error) t =
| Lazy : ('a, 'error) t Lazy.t -> ('a, 'error) t

and 'a value = Byte : char value | Short : [ `LE | `BE ] -> int value

and state = State.t

type v = {
Expand Down
12 changes: 6 additions & 6 deletions test/test.ml
Original file line number Diff line number Diff line change
Expand Up @@ -316,8 +316,8 @@ let fuzz2 () =
; "\x7e\x7e\x7e\x7e\x7e\x7e\x7e\x7e\x7e\x7e\x7e\x7e\x7e\x7e\x7e\x7e"
(* ~~~~~~~~~~~~~~~~ *)
; "\x7e\x7e\x7e\x7e\x7e\x7e\x7e\x7e\x7e\x7e\x7e\x7e\x7e\x7e\x7e\x7e"
(* ~~~~~~~~~~~~~~~~ *); "\x7e\x7e\x7e\x7e\x7e\x7e\x7e\x7e\x3a\x2c\x50"
(* ~~~~~~~~:,P *)
(* ~~~~~~~~~~~~~~~~ *)
; "\x7e\x7e\x7e\x7e\x7e\x7e\x7e\x7e\x3a\x2c\x50" (* ~~~~~~~~:,P *)
] in
Alcotest.test_case "fuzz2" `Quick @@ fun () ->
let decoder =
Expand Down Expand Up @@ -401,8 +401,8 @@ let fuzz5 () =
let expected_output =
[
"\x1a\xca\x78\x78\x78\x78\x78\x78\x78\x50\x50\x37\x50\x50\x50\x50"
(* ..xxxxxxxPP7PPPP *); "\x50\x50\x50\x50\x50\x50\x50\x50\x50"
(* PPPPPPPPP *)
(* ..xxxxxxxPP7PPPP *)
; "\x50\x50\x50\x50\x50\x50\x50\x50\x50" (* PPPPPPPPP *)
] in
Alcotest.test_case "fuzz5" `Quick @@ fun () ->
let decoder = Inf.decoder (`String (String.concat "" input)) ~o ~w in
Expand Down Expand Up @@ -458,8 +458,8 @@ let fuzz9 () =
"\x9b\x01\x95\xfc\x51\xd2\xed\xc8\xce\xc8\xff\x80\x00\x00\x7f\xff"
(* ....Q........... *)
; "\x79\x2f\xe9\x51\x88\x7b\xb8\x2f\xef\xa5\x8c\xf8\xf1\xb6\xce\xc8"
(* y/.Q.{./........ *); "\xb8\xc8\xff\x2f\x00\x7f\x88\x7b\xbc"
(* .../...{. *)
(* y/.Q.{./........ *)
; "\xb8\xc8\xff\x2f\x00\x7f\x88\x7b\xbc" (* .../...{. *)
] in
let decoder = Inf.decoder (`String (String.concat "" inputs)) ~o ~w in
Alcotest.(check decode)
Expand Down
61 changes: 21 additions & 40 deletions test/test_ns.ml
Original file line number Diff line number Diff line change
Expand Up @@ -136,40 +136,34 @@ let invalid_complement_of_length () =
Alcotest.test_case "invalid complement of length" `Quick @@ fun () ->
let src = bigstring_of_string "\x00\x00\x00\x00\x00" in
Alcotest.(check check_decode)
"invalid complement of length"
(Error `Invalid_complement_of_length)
"invalid complement of length" (Error `Invalid_complement_of_length)
(Inf.Ns.inflate src dst)

let invalid_kind_of_block () =
Alcotest.test_case "invalid kind of block" `Quick @@ fun () ->
let src = bigstring_of_string "\x06" in
Alcotest.(check check_decode)
"invalid kind of block"
(Error `Invalid_kind_of_block)
"invalid kind of block" (Error `Invalid_kind_of_block)
(Inf.Ns.inflate src dst)

let invalid_code_lengths () =
Alcotest.test_case "invalid code lengths" `Quick @@ fun () ->
let src = bigstring_of_string "\x04\x00\xfe\xff" in
Alcotest.(check check_decode)
"invalid code lengths"
(Error `Invalid_dictionary)
(Inf.Ns.inflate src dst)
"invalid code lengths" (Error `Invalid_dictionary) (Inf.Ns.inflate src dst)

let invalid_bit_length_repeat () =
Alcotest.test_case "invalid bit length repeat" `Quick @@ fun () ->
let src = bigstring_of_string "\x04\x00\x24\x49\x00" in
Alcotest.(check check_decode)
"invalid bit length repeat"
(Error `Invalid_dictionary)
"invalid bit length repeat" (Error `Invalid_dictionary)
(Inf.Ns.inflate src dst)

let invalid_codes () =
Alcotest.test_case "invalid codes -- missing end-of-block" `Quick @@ fun () ->
let src = bigstring_of_string "\x04\x00\x24\xe9\xff\x6d" in
Alcotest.(check check_decode)
"invalid codes -- missing end-of-block"
(Error `Invalid_dictionary)
"invalid codes -- missing end-of-block" (Error `Invalid_dictionary)
(Inf.Ns.inflate src dst)

let invalid_lengths () =
Expand All @@ -179,8 +173,7 @@ let invalid_lengths () =
"\x04\x80\x49\x92\x24\x49\x92\x24\x49\x92\x24\x71\xff\xff\x93\x11\x00"
in
Alcotest.(check check_decode)
"invalid literals/lengths"
(Error `Invalid_dictionary)
"invalid literals/lengths" (Error `Invalid_dictionary)
(Inf.Ns.inflate src dst)

let invalid_distances () =
Expand All @@ -189,16 +182,13 @@ let invalid_distances () =
bigstring_of_string
"\x04\x80\x49\x92\x24\x49\x92\x24\x0f\xb4\xff\xff\xc3\x84" in
Alcotest.(check check_decode)
"invalid distances"
(Error `Invalid_dictionary)
(Inf.Ns.inflate src dst)
"invalid distances" (Error `Invalid_dictionary) (Inf.Ns.inflate src dst)

let too_many_length_or_distance_symbols () =
Alcotest.test_case "too many length of distance symbols" `Quick @@ fun () ->
let src = bigstring_of_string "\xfc\x00\x00" in
Alcotest.(check check_decode)
"too many length of distance symbols"
(Error `Unexpected_end_of_input)
"too many length of distance symbols" (Error `Unexpected_end_of_input)
(Inf.Ns.inflate src dst)

(* XXX(dinosaure): error is not conform to what we expect (best will be [Invalid
Expand All @@ -208,8 +198,7 @@ let invalid_distance_code () =
Alcotest.test_case "invalid distance code" `Quick @@ fun () ->
let src = bigstring_of_string "\x02\x7e\xff\xff" in
Alcotest.(check check_decode)
"invalid distance code"
(Error `Invalid_distance_code)
"invalid distance code" (Error `Invalid_distance_code)
(Inf.Ns.inflate src dst)

(* XXX(dinosaure): see [Inf.base_dist]'s comment about this behavior. *)
Expand All @@ -220,17 +209,15 @@ let invalid_distance_too_far_back () =
bigstring_of_string "\x0c\xc0\x81\x00\x00\x00\x00\x00\x90\xff\x6b\x04\x00"
in
Alcotest.(check check_decode)
"invalid distance too far back"
(Error `Invalid_distance)
"invalid distance too far back" (Error `Invalid_distance)
(Inf.Ns.inflate src dst)

let invalid_flat_not_enough_output () =
Alcotest.test_case "invalid output with flat block" `Quick @@ fun () ->
let src = bigstring_of_string "\x01\x04\x00\xfb\xff\xde\xad\xbe\xef" in
let dst = bigstring_create 0 in
Alcotest.(check check_decode)
"invalid distance too far back"
(Error `Unexpected_end_of_output)
"invalid distance too far back" (Error `Unexpected_end_of_output)
(Inf.Ns.inflate src dst)

let invalid_literal_not_enough_output () =
Expand All @@ -246,8 +233,7 @@ let invalid_literal_not_enough_output () =
let src = bigstring_of_string res in
let dst = bigstring_create 0 in
Alcotest.(check check_decode)
"invalid distance too far back"
(Error `Unexpected_end_of_output)
"invalid distance too far back" (Error `Unexpected_end_of_output)
(Inf.Ns.inflate src dst)

let invalid_copy_not_enough_output () =
Expand All @@ -263,8 +249,7 @@ let invalid_copy_not_enough_output () =
let src = bigstring_of_string res in
let dst = bigstring_create 1 in
Alcotest.(check check_decode)
"invalid distance too far back"
(Error `Unexpected_end_of_output)
"invalid distance too far back" (Error `Unexpected_end_of_output)
(Inf.Ns.inflate src dst)

let fixed () =
Expand Down Expand Up @@ -674,8 +659,8 @@ let fuzz2 () =
; "\x7e\x7e\x7e\x7e\x7e\x7e\x7e\x7e\x7e\x7e\x7e\x7e\x7e\x7e\x7e\x7e"
(* ~~~~~~~~~~~~~~~~ *)
; "\x7e\x7e\x7e\x7e\x7e\x7e\x7e\x7e\x7e\x7e\x7e\x7e\x7e\x7e\x7e\x7e"
(* ~~~~~~~~~~~~~~~~ *); "\x7e\x7e\x7e\x7e\x7e\x7e\x7e\x7e\x3a\x2c\x50"
(* ~~~~~~~~:,P *)
(* ~~~~~~~~~~~~~~~~ *)
; "\x7e\x7e\x7e\x7e\x7e\x7e\x7e\x7e\x3a\x2c\x50" (* ~~~~~~~~:,P *)
] in
let expected = String.concat "" expected in
(* All of src is not used (last byte is useless) *)
Expand Down Expand Up @@ -779,8 +764,8 @@ let fuzz5 () =
let expected =
[
"\x1a\xca\x78\x78\x78\x78\x78\x78\x78\x50\x50\x37\x50\x50\x50\x50"
(* ..xxxxxxxPP7PPPP *); "\x50\x50\x50\x50\x50\x50\x50\x50\x50"
(* PPPPPPPPP *)
(* ..xxxxxxxPP7PPPP *)
; "\x50\x50\x50\x50\x50\x50\x50\x50\x50" (* PPPPPPPPP *)
] in
let expected = String.concat "" expected in
(* All of src is not used (last byte is useless) *)
Expand Down Expand Up @@ -831,9 +816,7 @@ let fuzz8 () =
Alcotest.test_case "fuzz8" `Quick @@ fun () ->
let src = bigstring_of_string "\x7a\x37\x6d\x99\x13" in
Alcotest.(check check_decode)
"fuzz8"
(Error `Unexpected_end_of_input)
(Inf.Ns.inflate src dst)
"fuzz8" (Error `Unexpected_end_of_input) (Inf.Ns.inflate src dst)

let fuzz9 () =
Alcotest.test_case "fuzz9" `Quick @@ fun () ->
Expand All @@ -842,14 +825,12 @@ let fuzz9 () =
"\x9b\x01\x95\xfc\x51\xd2\xed\xc8\xce\xc8\xff\x80\x00\x00\x7f\xff"
(* ....Q........... *)
; "\x79\x2f\xe9\x51\x88\x7b\xb8\x2f\xef\xa5\x8c\xf8\xf1\xb6\xce\xc8"
(* y/.Q.{./........ *); "\xb8\xc8\xff\x2f\x00\x7f\x88\x7b\xbc"
(* .../...{. *)
(* y/.Q.{./........ *)
; "\xb8\xc8\xff\x2f\x00\x7f\x88\x7b\xbc" (* .../...{. *)
] in
let src = bigstring_of_string (String.concat "" src) in
Alcotest.(check check_decode)
"fuzz9"
(Error `Invalid_distance)
(Inf.Ns.inflate src dst)
"fuzz9" (Error `Invalid_distance) (Inf.Ns.inflate src dst)

let fuzz10 () =
Alcotest.test_case "fuzz10" `Quick @@ fun () ->
Expand Down

0 comments on commit 0f82a37

Please sign in to comment.