-
Notifications
You must be signed in to change notification settings - Fork 13
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Fix incorrect logic in #parseHostmaskFromPrefix(). Extend #toString()…
… tests, add misc. tests for utility methods.
- Loading branch information
Fionn Kelleher
committed
Dec 20, 2013
1 parent
2168f8a
commit f96acdf
Showing
3 changed files
with
77 additions
and
9 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
Message = require "../" | ||
vows = require "vows" | ||
should = require("chai").should() | ||
|
||
vows.describe("Utility methods").addBatch( | ||
"#prefixIsHostmask()": | ||
"when prefix is valid hostname": | ||
topic: Message ":[email protected] PRIVMSG #Test :Testing!" | ||
"should return `true`": (topic) -> | ||
topic.prefixIsHostmask().should.be.true | ||
|
||
"when prefix is invalid hostname": | ||
topic: Message ":127.0.0.1 PRIVMSG #Test :Testing!" | ||
"should return `false`": (topic) -> | ||
topic.prefixIsHostmask().should.be.false | ||
|
||
"#prefixIsServer()": | ||
"when prefix is valid server hostname": | ||
topic: Message ":127.0.0.1 NOTICE * :Looking up your hostname..." | ||
"should return `true`": (topic) -> | ||
topic.prefixIsServer().should.be.true | ||
|
||
"when prefix is invalid server hostname": | ||
topic: Message ":[email protected] NOTICE * :Looking up your hostname..." | ||
"should return `false`": (topic) -> | ||
topic.prefixIsServer().should.be.false | ||
|
||
"#parseHostmaskFromPrefix()": | ||
"when prefix is '[email protected]'": | ||
topic: (Message ":[email protected] PRIVMSG #test :Hello!").parseHostmaskFromPrefix() | ||
"should have property 'nickname' of 'james'": (topic) -> | ||
topic.nickname.should.equal "james" | ||
"should have property 'username' of 'baz'": (topic) -> | ||
topic.username.should.equal "baz" | ||
"should have property 'hostname' of 'my.awesome-rdns.co'": (topic) -> | ||
topic.hostname.should.equal "my.awesome-rdns.co" | ||
|
||
"when prefix is '127.0.0.1'": | ||
topic: (Message ":127.0.0.1 NOTICE * :Looking up your hostname...").parseHostmaskFromPrefix() | ||
"should return `null`": (topic) -> | ||
(topic == null).should.be.true | ||
).export(module) | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,13 +1,37 @@ | ||
Message = require "../" | ||
vows = require "vows" | ||
assert = require "assert" | ||
should = require("chai").should() | ||
|
||
vows.describe("irc-message #toString()").addBatch( | ||
"Invoking #toString() on a parsed message": | ||
"with prefix, command and two parameters": | ||
topic: Message ":[email protected] PRIVMSG #launch :JeffA: go ahead and do another multi line message" | ||
vows.describe("Converting parsed messages to strings").addBatch( | ||
"#toString() on parsed message": | ||
"with command only": | ||
topic: Message "FOO" | ||
"should return 'FOO'": (topic) -> | ||
topic.toString().should.equal "FOO" | ||
|
||
"should yield exact same raw line": (topic) -> | ||
assert.equal topic.toString(), ":[email protected] PRIVMSG #launch :JeffA: go ahead and do another multi line message" | ||
"with prefix, command": | ||
topic: Message ":test FOO" | ||
"should return ':test FOO'": (topic) -> | ||
topic.toString().should.equal ":test FOO" | ||
|
||
"with prefix, command, middle, trailing parameter": | ||
topic: Message ":[email protected] PRIVMSG #Test :This is a test" | ||
"should return ':[email protected] PRIVMSG #Test :This is a test'": (topic) -> | ||
topic.toString().should.equal ":[email protected] PRIVMSG #Test :This is a test" | ||
|
||
"with no prefix, command, middle, trailing with spaces": | ||
topic: Message "PRIVMSG #foo :This is a test" | ||
"should return 'PRIVMSG #foo :This is a test'": (topic) -> | ||
topic.toString().should.equal "PRIVMSG #foo :This is a test" | ||
|
||
"with multiple middle params, prefix": | ||
topic: Message ":test FOO bar baz quux" | ||
"should return ':test FOO bar baz quux'": (topic) -> | ||
topic.toString().should.equal ":test FOO bar baz quux" | ||
|
||
"with tags, prefix, command, middle params, trailing params": | ||
topic: Message "@test=super;single :[email protected] FOO bar baz quux :This is a test" | ||
"should return '@test=super;single :[email protected] FOO bar baz quux :This is a test'": (topic) -> | ||
topic.toString().should.equal "@test=super;single :[email protected] FOO bar baz quux :This is a test" | ||
|
||
).export(module) |