add Mode.Parse.chan_modes tests

This commit is contained in:
tali 2024-01-25 18:25:52 -05:00
parent b49b1db26b
commit 2bea08d04f
1 changed files with 25 additions and 1 deletions

View File

@ -249,7 +249,7 @@ let%expect_test _ =
let print_set_nl s = Printf.printf "[%s]\n" (Set.to_string s) in
let print_bool_nl b = print_endline (if b then "true" else "false") in
let print_change_nl c = Format.printf "%a\n" Set.pp_change c in
let print_change_nl c = Format.kasprintf print_string "%a\n" Set.pp_change c in
print_set_nl Set.empty; [%expect {| [] |}];
print_set_nl Set.(of_string "i"); [%expect {| [i] |}];
@ -279,3 +279,27 @@ let%expect_test _ =
let m, c = Set.normalize (Set.of_string "iw") (Parse.user_modes "-w+io") in
Format.printf "%a -> [%a]" Set.pp_change c Set.pp m;
[%expect {| +o-w -> [io] |}];
let print_chan_modes (m : Parse.chan_modes) =
Format.printf "[%a" Set.pp_change m.chan_modes;
begin match m.chan_limit with
| Some (`set n) -> Format.printf " +l:%d" n
| Some `unset -> Format.printf " -l"
| None -> ()
end;
begin match m.chan_key with
| Some (`set k) -> Format.printf " +k:%S" k
| Some `unset -> Format.printf " -k"
| None -> ()
end;
Format.printf "]\n@."
in
print_chan_modes (Parse.chan_modes "+im-nm+s" []);
[%expect {| [+is-mn] |}];
print_chan_modes (Parse.chan_modes "+l-ik+lt" ["100"; "*"; "200"]);
[%expect {| [+t-i +l:200 -k] |}];
print_chan_modes (Parse.chan_modes "+k-k+k" ["a"; "b"; "c"]);
[%expect {| [+ +k:"c"] |}];