Skip to content

Commit

Permalink
Add tests about type equality and Conduit.repr
Browse files Browse the repository at this point in the history
  • Loading branch information
dinosaure committed Nov 29, 2020
1 parent 2b59b5e commit 5b03c98
Showing 1 changed file with 59 additions and 0 deletions.
59 changes: 59 additions & 0 deletions tests/flow.ml
Original file line number Diff line number Diff line change
Expand Up @@ -247,6 +247,64 @@ let test_output_strings =
(String.concat "" (List.map Bytes.to_string bufs))
"Hello World!"

(* XXX(dinosaure): ensure type equality. *)

module Dummy_flow = struct
type input = bytes

type output = string

type +'a io = 'a

type flow = Flow

type error = |

let pp_error : Format.formatter -> error -> unit = fun _ -> function _ -> .

let recv Flow _ = Ok `End_of_flow

let send Flow _ = Ok 0

let close Flow = Ok ()
end

module Dummy_protocol = struct
include Dummy_flow

type endpoint = |

let connect : endpoint -> (flow, error) result io = function _ -> .
end

module Dummy_service = struct
include Dummy_flow

type configuration = Configuration

type t = T

let init Configuration = Ok T

let accept T = Ok Flow

let close T = Ok ()
end

let dummy_protocol = Conduit.register (module Dummy_protocol)

let dummy_service =
Conduit.Service.register (module Dummy_service) dummy_protocol

let test_type_equality =
Alcotest.test_case "type equality" `Quick @@ fun () ->
let[@warning "-8"] (Ok t) =
Conduit.Service.init dummy_service Dummy_service.Configuration in
let module Repr = (val Conduit.repr dummy_protocol) in
match Conduit.Service.accept dummy_service t with
| Ok (Repr.T Dummy_flow.Flow) -> Alcotest.(check pass) "type equality" () ()
| _ -> Alcotest.failf "Invalid flow value"

let tests =
[
( "flow",
Expand All @@ -255,5 +313,6 @@ let tests =
test_output_string;
test_input_strings;
test_output_strings;
test_type_equality;
] );
]

0 comments on commit 5b03c98

Please sign in to comment.