wrap.js (1035B)
1 var assert = require('assert'); 2 var wordwrap = require('wordwrap'); 3 4 var fs = require('fs'); 5 var idleness = fs.readFileSync(__dirname + '/idleness.txt', 'utf8'); 6 7 exports.stop80 = function () { 8 var lines = wordwrap(80)(idleness).split(/\n/); 9 var words = idleness.split(/\s+/); 10 11 lines.forEach(function (line) { 12 assert.ok(line.length <= 80, 'line > 80 columns'); 13 var chunks = line.match(/\S/) ? line.split(/\s+/) : []; 14 assert.deepEqual(chunks, words.splice(0, chunks.length)); 15 }); 16 }; 17 18 exports.start20stop60 = function () { 19 var lines = wordwrap(20, 100)(idleness).split(/\n/); 20 var words = idleness.split(/\s+/); 21 22 lines.forEach(function (line) { 23 assert.ok(line.length <= 100, 'line > 100 columns'); 24 var chunks = line 25 .split(/\s+/) 26 .filter(function (x) { return x.match(/\S/) }) 27 ; 28 assert.deepEqual(chunks, words.splice(0, chunks.length)); 29 assert.deepEqual(line.slice(0, 20), new Array(20 + 1).join(' ')); 30 }); 31 };