PING and PONG

This commit is contained in:
Neale Pickett 2008-03-06 16:11:57 -07:00
parent ac369d30c2
commit 4d9ed389a2
3 changed files with 23 additions and 13 deletions

View File

@ -116,9 +116,10 @@ let handle_command cli iobuf cmd =
() ()
| (None, "KILL", [nickname; comment], None) -> | (None, "KILL", [nickname; comment], None) ->
() ()
| (None, "PING", [server], None) -> | (None, "PING", [], Some text)
() | (None, "PING", [text], None) ->
| (None, "PONG", [server], None) -> write cli (Command.create (Some !(Irc.name)) "PONG" [!(Irc.name)] (Some text))
| (None, "PONG", [payload], None) ->
() ()
| (None, "ERROR", [], Some message) -> | (None, "ERROR", [], Some message) ->
() ()

View File

@ -45,7 +45,7 @@ let rec from_string line =
match (c, acc) with match (c, acc) with
| (None, name :: args) -> | (None, name :: args) ->
(* End of line, no text part *) (* End of line, no text part *)
create sender name args None create sender (String.uppercase name) args None
| (None, []) -> | (None, []) ->
(* End of line, no text part, no args, no command *) (* End of line, no text part, no args, no command *)
raise (Failure "No command, eh?") raise (Failure "No command, eh?")
@ -55,7 +55,7 @@ let rec from_string line =
loop (Some (Str.string_after word 1)) acc rest loop (Some (Str.string_after word 1)) acc rest
| (Some ':', name :: args) -> | (Some ':', name :: args) ->
(* Not first word, starts with ':' *) (* 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 _, _) -> | (Some _, _) ->
(* Argument *) (* Argument *)
let (word, rest) = extract_word line in let (word, rest) = extract_word line in

View File

@ -20,6 +20,10 @@ let unit_tests =
~printer:Command.as_string ~printer:Command.as_string
(Command.create None "NICK" ["name"] None) (Command.create None "NICK" ["name"] None)
(Command.from_string "NICK name"); (Command.from_string "NICK name");
assert_equal
~printer:Command.as_string
(Command.create None "NICK" ["name"] None)
(Command.from_string "nick name");
assert_equal assert_equal
~printer:Command.as_string ~printer:Command.as_string
(Command.create (Some "foo") "NICK" ["name"] None) (Command.create (Some "foo") "NICK" ["name"] None)
@ -48,7 +52,8 @@ let regression_tests =
[ [
"Simple connection" >:: "Simple connection" >::
(do_chat ((do_login "nick") @ (do_chat ((do_login "nick") @
[Send "BLARGH\r\n"; [
Send "BLARGH\r\n";
Recv ":testserver.test 421 nick BLARGH :Unknown or misconstructed command\r\n"; Recv ":testserver.test 421 nick BLARGH :Unknown or misconstructed command\r\n";
Send "MOTD\r\n"; Send "MOTD\r\n";
Recv ":testserver.test 422 nick :MOTD File is missing\r\n"; Recv ":testserver.test 422 nick :MOTD File is missing\r\n";
@ -56,6 +61,10 @@ let regression_tests =
Regex ":testserver\\.test 391 nick testserver\\.test :[-0-9]+T[:0-9]+Z\r\n"; Regex ":testserver\\.test 391 nick testserver\\.test :[-0-9]+T[:0-9]+Z\r\n";
Send "VERSION\r\n"; Send "VERSION\r\n";
Recv ":testserver.test 351 nick 0.1 testserver.test :\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";
])); ]));
] ]