Permalink
Browse files

Some tests for irc.parseMessage

  • Loading branch information...
1 parent 3588438 commit 099da4e1721acdde4e7e44fa46010a4538596847 @martynsmith committed Jan 20, 2013
Showing with 68 additions and 0 deletions.
  1. +4 −0 Makefile
  2. +2 −0 lib/irc.js
  3. +62 −0 test/parse-line.js
View
@@ -0,0 +1,4 @@
+test:
+ ./node_modules/.bin/mocha --reporter list
+
+.PHONY: test
View
@@ -889,3 +889,5 @@ function parseMessage(line, stripColors) { // {{{
return message;
} // }}}
+
+exports.parseMessage = parseMessage;
View
@@ -0,0 +1,62 @@
+var irc = require('../lib/irc.js');
+var should = require('should');
+var _ = require('underscore');
+
+describe("irc.parseMessage", function() {
+ var checks = {
+ ':irc.dollyfish.net.nz 372 nodebot :The message of the day was last changed: 2012-6-16 23:57': {
+ prefix: "irc.dollyfish.net.nz",
+ server: "irc.dollyfish.net.nz",
+ command: "rpl_motd",
+ rawCommand: "372",
+ commandType: "reply",
+ args: [ "nodebot", "The message of the day was last changed: 2012-6-16 23:57" ]
+ },
+ ':Ned!~martyn@irc.dollyfish.net.nz PRIVMSG #test :Hello nodebot!': {
+ prefix: "Ned!~martyn@irc.dollyfish.net.nz",
+ nick: "Ned",
+ user: "~martyn",
+ host: "irc.dollyfish.net.nz",
+ command: "PRIVMSG",
+ rawCommand: "PRIVMSG",
+ commandType: "normal",
+ args: [ "#test", "Hello nodebot!" ]
+ },
+ ':Ned!~martyn@irc.dollyfish.net.nz PRIVMSG #test ::-)': {
+ prefix: "Ned!~martyn@irc.dollyfish.net.nz",
+ nick: "Ned",
+ user: "~martyn",
+ host: "irc.dollyfish.net.nz",
+ command: "PRIVMSG",
+ rawCommand: "PRIVMSG",
+ commandType: "normal",
+ args: [ "#test", ":-)" ]
+ },
+ ':Ned!~martyn@irc.dollyfish.net.nz PRIVMSG #test ::': {
+ prefix: "Ned!~martyn@irc.dollyfish.net.nz",
+ nick: "Ned",
+ user: "~martyn",
+ host: "irc.dollyfish.net.nz",
+ command: "PRIVMSG",
+ rawCommand: "PRIVMSG",
+ commandType: "normal",
+ args: [ "#test", ":" ]
+ },
+ ":Ned!~martyn@irc.dollyfish.net.nz PRIVMSG #test ::^:^:": {
+ prefix: "Ned!~martyn@irc.dollyfish.net.nz",
+ nick: "Ned",
+ user: "~martyn",
+ host: "irc.dollyfish.net.nz",
+ command: "PRIVMSG",
+ rawCommand: "PRIVMSG",
+ commandType: "normal",
+ args: [ "#test", ":^:^:" ]
+ }
+ };
+
+ _.each(checks, function(result, line) {
+ it('parse ' + line, function() {
+ JSON.stringify(result).should.equal(JSON.stringify(irc.parseMessage(line)));
+ });
+ });
+});

0 comments on commit 099da4e

Please sign in to comment.