title: Writing Meck testcases for gen_tcp function
body: <p>Here is a simple IRC bot module written by Erlang:
  <a href="http://jonathanroes.blogspot.se/2007/08/simple-erlang-irc-bot.html" rel="nofollow">IRC Bot</a></p>
  
  <p>Could someone helps me write the testcase for the function connect and parse_line with MECK</p>
  
  <pre><code>connect(Host, Port) -&gt;
          {ok, Sock} = gen_tcp:connect(Host, Port, [{packet, line}]),
          % According to RFC1459, we need to tell the server our nickname and username
          gen_tcp:send(Sock, "NICK " ++ ?nickname ++ "\r\n"),
          gen_tcp:send(Sock, "USER " ++ ?nickname ++ " blah blah blah blah\r\n"),
          loop(Sock).
  
  parse_line(Sock, [User,"PRIVMSG",Channel,?nickname|_]) -&gt;
          Nick = lists:nth(1, string:tokens(User, "!")),
          irc_privmsg(Sock, Channel, "You talkin to me, " ++ Nick ++ "?");            
  
  parse_line(Sock, [_,"376"|_]) -&gt;
          gen_tcp:send(Sock, "JOIN :" ++ ?channel ++ "\r\n");
  
  parse_line(Sock, ["PING"|Rest]) -&gt;
          gen_tcp:send(Sock, "PONG " ++ Rest ++ "\r\n");
  
  parse_line(_, _) -&gt;
          0.
  </code></pre>
  
  <p>Thanks you very much, I have already know how to use MECK to write some simple Erlang testcases about input/ otput, lists...but this IRC bot seems tobe quite beyond my current ability.</p>