Skip to content

Commit

Permalink
Calculate maxLength correctly, respecting options
Browse files Browse the repository at this point in the history
  • Loading branch information
LinuxMercedes committed Sep 5, 2015
1 parent 40bcc91 commit 03b7eb4
Show file tree
Hide file tree
Showing 3 changed files with 39 additions and 2 deletions.
2 changes: 1 addition & 1 deletion lib/irc.js
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
12 changes: 11 additions & 1 deletion test/data/fixtures.json
Original file line number Diff line number Diff line change
Expand Up @@ -177,5 +177,15 @@
"maxLength": 5,
"result": ["abc", "abcde", "f abc", "abcd", "abc"]
}
]
],
"_speak": [
{
"length": 30,
"expected": 10
},
{
"length": 7,
"expected": 1
}
]
}
27 changes: 27 additions & 0 deletions test/test-irc.js
Original file line number Diff line number Diff line change
Expand Up @@ -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();
});

0 comments on commit 03b7eb4

Please sign in to comment.