Ohm-Management - Projektarbeit B-ME
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

wrap.js 1019B

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