63 lines
2.0 KiB
OCaml
63 lines
2.0 KiB
OCaml
let%expect_test _ =
|
|
let print_bool_nl = function
|
|
| true -> print_endline "true"
|
|
| false -> print_endline "false"
|
|
in
|
|
let print_int_nl x = print_int x; print_newline () in
|
|
let print_exn_nl f =
|
|
try ignore (f ()); print_endline "{}"
|
|
with e -> print_endline (Printexc.to_string e)
|
|
in
|
|
|
|
let router = Router.make () in
|
|
|
|
let u1 =
|
|
User.make "beenie"
|
|
~userinfo:{
|
|
username="x";
|
|
realname="y";
|
|
hostname="z";
|
|
}
|
|
~outbox:(Outbox.make ())
|
|
in
|
|
|
|
let u2 =
|
|
User.make "bobbie"
|
|
~userinfo:{
|
|
username="x";
|
|
realname="y";
|
|
hostname="z";
|
|
}
|
|
~outbox:(Outbox.make ())
|
|
in
|
|
|
|
let c1 = Chan.make ~name:"#wire-fraud" in
|
|
let c2 = Chan.make ~name:"#spiderman" in
|
|
|
|
User.register u1 ~router;
|
|
User.register u2 ~router;
|
|
Chan.register c1 ~router;
|
|
Chan.register c2 ~router;
|
|
print_bool_nl (Router.find_user router "beenie" == u1); [%expect "true"];
|
|
print_bool_nl (Router.find_user router "bobbie" == u2); [%expect "true"];
|
|
print_bool_nl (Router.find_chan router "#wire-fraud" == c1); [%expect "true"];
|
|
print_bool_nl (Router.find_chan router "#spiderman" == c2); [%expect "true"];
|
|
|
|
print_bool_nl (Chan.is_empty c1); [%expect "true"];
|
|
print_int_nl c1.member_count; [%expect "0"];
|
|
let m11 = Router.join c1 u1 in
|
|
print_bool_nl (Chan.is_empty c1); [%expect "false"];
|
|
print_int_nl c1.member_count; [%expect "1"];
|
|
let m12 = Router.join c1 u2 in
|
|
print_bool_nl (Chan.is_empty c1); [%expect "false"];
|
|
print_int_nl c1.member_count; [%expect "2"];
|
|
print_bool_nl (Router.membership c1 u1 == m11); [%expect "true"];
|
|
print_bool_nl (Router.membership c1 u2 == m12); [%expect "true"];
|
|
Router.part m11;
|
|
print_bool_nl (Chan.is_empty c1); [%expect "false"];
|
|
print_int_nl c1.member_count; [%expect "1"];
|
|
Router.part m12;
|
|
print_bool_nl (Chan.is_empty c1); [%expect "true"];
|
|
print_int_nl c1.member_count; [%expect "0"];
|
|
print_exn_nl (fun () -> Router.membership c1 u1); [%expect "Not_found"];
|