diff --git a/test/models/network.js b/test/models/network.js index 000c2cef..f41d0ec4 100644 --- a/test/models/network.js +++ b/test/models/network.js @@ -10,6 +10,7 @@ describe("Network", function() { it("should produce an valid object", function() { var network = new Network({name: "networkName"}); + network.setNick("chillin`"); network.channels.push(new Chan({name: "#thelounge"})); network.channels.push(new Chan({name: "&foobar"})); @@ -22,7 +23,7 @@ describe("Network", function() { username: "", realname: "", commands: [], - nick: "", + nick: "chillin`", join: "#thelounge,&foobar", ip: null, hostname: null diff --git a/test/tests/nickhighlights.js b/test/tests/nickhighlights.js new file mode 100644 index 00000000..9ef9f36b --- /dev/null +++ b/test/tests/nickhighlights.js @@ -0,0 +1,63 @@ +"use strict"; + +var expect = require("chai").expect; + +var Network = require("../../src/models/network"); + +var network = new Network({name: "networkName"}); + +describe("Nickname highlights", function() { + it("should NOT highlight nickname", function() { + network.setNick("lounge-bot"); + + expect("").to.not.match(network.highlightRegex); + expect(" ").to.not.match(network.highlightRegex); + expect("completely unrelated sentence").to.not.match(network.highlightRegex); + expect("foobarlounge-bot").to.not.match(network.highlightRegex); + expect("lounge-botfoobar").to.not.match(network.highlightRegex); + expect("\x03123lounge-bot").to.not.match(network.highlightRegex); + expect("lo\x0312unge-bot").to.not.match(network.highlightRegex); + expect("123lounge-bot").to.not.match(network.highlightRegex); + expect("lounge-botz").to.not.match(network.highlightRegex); + expect("lounge-bot123").to.not.match(network.highlightRegex); + expect("lounge- bot").to.not.match(network.highlightRegex); + expect("lounge_bot").to.not.match(network.highlightRegex); + expect("lounge- bot").to.not.match(network.highlightRegex); + expect("Alounge-bot").to.not.match(network.highlightRegex); + expect("lounge-botW").to.not.match(network.highlightRegex); + }); + + it("should highlight nickname", function() { + network.setNick("lounge-bot"); + + expect("lounge-bot").to.match(network.highlightRegex); + expect("LoUnge-Bot").to.match(network.highlightRegex); + expect("LoUnge-Bot:hello").to.match(network.highlightRegex); + expect("lounge-bot, hello").to.match(network.highlightRegex); + expect("lounge-bot: hello").to.match(network.highlightRegex); + expect("lounge-bot hello").to.match(network.highlightRegex); + expect("\x0312lounge-bot").to.match(network.highlightRegex); + expect("lounge-bot\x0312 test").to.match(network.highlightRegex); + expect("|lounge-bot").to.match(network.highlightRegex); + expect("www.lounge-bot.example.com").to.match(network.highlightRegex); + expect(" lounge-bot").to.match(network.highlightRegex); + expect("@lounge-bot").to.match(network.highlightRegex); + expect("+lounge-bot").to.match(network.highlightRegex); + expect("lounge-bot_, hey").to.match(network.highlightRegex); + expect("lounge-bot-, hey").to.match(network.highlightRegex); + expect("lounge-bot|sleep, hey").to.match(network.highlightRegex); + expect("LOUNGE-bot|sleep, hey").to.match(network.highlightRegex); + }); + + it("changing name should update regex", function() { + network.setNick("lounge-bot"); + + expect("lounge-bot, hello").to.match(network.highlightRegex); + expect("cool_person, hello").to.not.match(network.highlightRegex); + + network.setNick("cool_person"); + + expect("lounge-bot, hello").to.not.match(network.highlightRegex); + expect("cool_person, hello").to.match(network.highlightRegex); + }); +});