create some basic server unit tests
This commit is contained in:
parent
2d9aaff4ef
commit
d8ef67310a
|
@ -3,4 +3,6 @@
|
|||
(name server)
|
||||
(libraries
|
||||
lwt lwt.unix lwt-dllist fmt
|
||||
logging irc))
|
||||
logging irc)
|
||||
(inline_tests)
|
||||
(preprocess (pps ppx_expect)))
|
||||
|
|
|
@ -0,0 +1,25 @@
|
|||
open Import
|
||||
|
||||
let%expect_test _ =
|
||||
let print_list print_ele xs =
|
||||
let rec iter pre post = function
|
||||
| [] -> print_string post
|
||||
| x :: xs ->
|
||||
print_string pre;
|
||||
print_ele x;
|
||||
iter ";" "]" xs
|
||||
in
|
||||
iter "[" "[]" xs
|
||||
in
|
||||
|
||||
let print_ints_nl xs = print_list print_int xs; print_newline () in
|
||||
|
||||
print_ints_nl
|
||||
(List.flat_map
|
||||
(function
|
||||
| 1 -> [1;2;3]
|
||||
| 2 -> [4;5;6]
|
||||
| _ -> [7;8;9])
|
||||
[1;2;3;1;2]);
|
||||
[%expect {| [1;2;3;4;5;6;7;8;9;1;2;3;4;5;6] |}];
|
||||
|
|
@ -0,0 +1,62 @@
|
|||
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"];
|
Loading…
Reference in New Issue