diff --git a/client.ml b/client.ml index 45c1b07..eb4de33 100644 --- a/client.ml +++ b/client.ml @@ -116,9 +116,10 @@ let handle_command cli iobuf cmd = () | (None, "KILL", [nickname; comment], None) -> () - | (None, "PING", [server], None) -> - () - | (None, "PONG", [server], None) -> + | (None, "PING", [], Some text) + | (None, "PING", [text], None) -> + write cli (Command.create (Some !(Irc.name)) "PONG" [!(Irc.name)] (Some text)) + | (None, "PONG", [payload], None) -> () | (None, "ERROR", [], Some message) -> () diff --git a/command.ml b/command.ml index 4fda1c1..7d1295e 100644 --- a/command.ml +++ b/command.ml @@ -45,7 +45,7 @@ let rec from_string line = match (c, acc) with | (None, name :: args) -> (* End of line, no text part *) - create sender name args None + create sender (String.uppercase name) args None | (None, []) -> (* End of line, no text part, no args, no command *) raise (Failure "No command, eh?") @@ -55,7 +55,7 @@ let rec from_string line = loop (Some (Str.string_after word 1)) acc rest | (Some ':', name :: args) -> (* Not first word, starts with ':' *) - create sender name args (Some (Str.string_after line 1)) + create sender (String.uppercase name) args (Some (Str.string_after line 1)) | (Some _, _) -> (* Argument *) let (word, rest) = extract_word line in diff --git a/tests.ml b/tests.ml index 0569ca4..fc665dd 100644 --- a/tests.ml +++ b/tests.ml @@ -20,6 +20,10 @@ let unit_tests = ~printer:Command.as_string (Command.create None "NICK" ["name"] None) (Command.from_string "NICK name"); + assert_equal + ~printer:Command.as_string + (Command.create None "NICK" ["name"] None) + (Command.from_string "nick name"); assert_equal ~printer:Command.as_string (Command.create (Some "foo") "NICK" ["name"] None) @@ -48,14 +52,19 @@ let regression_tests = [ "Simple connection" >:: (do_chat ((do_login "nick") @ - [Send "BLARGH\r\n"; - Recv ":testserver.test 421 nick BLARGH :Unknown or misconstructed command\r\n"; - Send "MOTD\r\n"; - Recv ":testserver.test 422 nick :MOTD File is missing\r\n"; - Send "TIME\r\n"; - Regex ":testserver\\.test 391 nick testserver\\.test :[-0-9]+T[:0-9]+Z\r\n"; - Send "VERSION\r\n"; - Recv ":testserver.test 351 nick 0.1 testserver.test :\r\n"; + [ + Send "BLARGH\r\n"; + Recv ":testserver.test 421 nick BLARGH :Unknown or misconstructed command\r\n"; + Send "MOTD\r\n"; + Recv ":testserver.test 422 nick :MOTD File is missing\r\n"; + Send "TIME\r\n"; + Regex ":testserver\\.test 391 nick testserver\\.test :[-0-9]+T[:0-9]+Z\r\n"; + Send "VERSION\r\n"; + Recv ":testserver.test 351 nick 0.1 testserver.test :\r\n"; + Send "PING snot\r\n"; + Recv ":testserver.test PONG testserver.test :snot\r\n"; + Send "PING :snot\r\n"; + Recv ":testserver.test PONG testserver.test :snot\r\n"; ])); ]