Browse files

hard break, passes test

  • Loading branch information...
1 parent 811b873 commit 24e58243d6026f6340bb6e5c24f191b48c20c974 @substack committed Aug 26, 2011
Showing with 18 additions and 3 deletions.
  1. +5 −2 index.js
  2. +13 −1 test/break.js
View
7 index.js
@@ -24,9 +24,12 @@ var wordwrap = module.exports = function (start, stop, params) {
var chunks = text.toString()
.split(re)
.reduce(function (acc, x) {
- for (var i = 0; i < x.length; i += stop - start) {
- acc.push(x.slice(i, i + stop - start));
+ if (mode === 'hard') {
+ for (var i = 0; i < x.length; i += stop - start) {
+ acc.push(x.slice(i, i + stop - start));
+ }
}
+ else acc.push(x)
return acc;
}, [])
;
View
14 test/break.js
@@ -2,7 +2,6 @@ var assert = require('assert');
var wordwrap = require('../');
exports.hard = function () {
- var wrap = wordwrap.hard(80);
var s = 'Assert from {"type":"equal","ok":false,"found":1,"wanted":2,'
+ '"stack":[],"id":"b7ddcd4c409de8799542a74d1a04689b",'
+ '"browser":"chrome/6.0"}'
@@ -16,3 +15,16 @@ exports.hard = function () {
assert.equal(s, s_.replace(/\n/g, ''));
};
+
+exports.break = function () {
+ var s = new Array(55+1).join('a');
+ var s_ = wordwrap.hard(20)(s);
+
+ var lines = s_.split('\n');
+ assert.equal(lines.length, 3);
+ assert.ok(lines[0].length === 20);
+ assert.ok(lines[1].length === 20);
+ assert.ok(lines[2].length === 15);
+
+ assert.equal(s, s_.replace(/\n/g, ''));
+};

0 comments on commit 24e5824

Please sign in to comment.