From 03b7eb40a29031f60c75cb5a9d5ee04883b31754 Mon Sep 17 00:00:00 2001 From: LinuxMercedes Date: Thu, 23 Jul 2015 17:10:36 -0500 Subject: [PATCH] Calculate maxLength correctly, respecting options --- lib/irc.js | 2 +- test/data/fixtures.json | 12 +++++++++++- test/test-irc.js | 27 +++++++++++++++++++++++++++ 3 files changed, 39 insertions(+), 2 deletions(-) diff --git a/lib/irc.js b/lib/irc.js index b9159b25..23f9af6e 100644 --- a/lib/irc.js +++ b/lib/irc.js @@ -952,7 +952,7 @@ Client.prototype.notice = function(target, text) { Client.prototype._speak = function(kind, target, text) { var self = this; - var maxLength = this.maxLineLength - target.length; + var maxLength = Math.min(this.maxLineLength - target.length, this.opt.messageSplit); if (typeof text !== 'undefined') { text.toString().split(/\r?\n/).filter(function(line) { return line.length > 0; diff --git a/test/data/fixtures.json b/test/data/fixtures.json index 00833469..cbc48735 100644 --- a/test/data/fixtures.json +++ b/test/data/fixtures.json @@ -177,5 +177,15 @@ "maxLength": 5, "result": ["abc", "abcde", "f abc", "abcd", "abc"] } - ] + ], + "_speak": [ + { + "length": 30, + "expected": 10 + }, + { + "length": 7, + "expected": 1 + } + ] } diff --git a/test/test-irc.js b/test/test-irc.js index c9b27e9e..5e86b7de 100644 --- a/test/test-irc.js +++ b/test/test-irc.js @@ -84,3 +84,30 @@ test ('splitting of long lines', function(t) { }); mock.close(); }); + +test ('opt.messageSplit used when set', function(t) { + var port = 6667; + var mock = testHelpers.MockIrcd(port, 'utf-8', false); + var client = new irc.Client('localhost', 'testbot', { + secure: false, + selfSigned: true, + port: port, + retryCount: 0, + debug: true, + messageSplit: 10 + }); + + var group = testHelpers.getFixtures('_speak'); + t.plan(group.length); + group.forEach(function(item) { + client.maxLineLength = item.length; + client._splitLongLines = function(words, maxLength, destination) { + t.equal(maxLength, item.expected); + return [words]; + } + client._speak("kind", "target", "test message"); + }); + + mock.close(); +}); +