wrap.js 1.0 KB

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