-
-
Notifications
You must be signed in to change notification settings - Fork 57
/
test.js
69 lines (54 loc) · 3.97 KB
/
test.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
'use strict';
require('mocha');
var assert = require('assert');
var wrap = require('./');
var str = 'A project without documentation is like a project that doesn\'t exist. Verb solves this by making it dead simple to generate project documentation, using simple markdown templates, with zero configuration required. ';
describe('wrap', function () {
it('should use defaults to wrap words in the given string:', function () {
assert.equal(wrap(str), ' A project without documentation is like a project \n that doesn\'t exist. Verb solves this by making it \n dead simple to generate project documentation, \n using simple markdown templates, with zero \n configuration required. ');
});
it('should wrap to the specified width:', function () {
assert.equal(wrap(str, {width: 40}), ' A project without documentation is like \n a project that doesn\'t exist. Verb \n solves this by making it dead simple to \n generate project documentation, using \n simple markdown templates, with zero \n configuration required. ');
});
it('should indent the specified amount:', function () {
assert.equal(wrap(str, {indent: ' '}), ' A project without documentation is like a project \n that doesn\'t exist. Verb solves this by making it \n dead simple to generate project documentation, \n using simple markdown templates, with zero \n configuration required. ');
});
it('should use the given string for newlines:', function () {
assert.equal(wrap(str, {newline: '\n\n-'}), ' A project without documentation is like a project \n\n-that doesn\'t exist. Verb solves this by making it \n\n-dead simple to generate project documentation, \n\n-using simple markdown templates, with zero \n\n-configuration required. ');
});
it('should run the escape function on each line', function () {
assert.equal(
wrap(str, {escape: function(e) {return e.replace('\'', '\\\'')}}),
' A project without documentation is like a project \n that doesn\\\'t exist. Verb solves this by making it \n dead simple to generate project documentation, \n using simple markdown templates, with zero \n configuration required. '
)
});
it('should trim trailing whitespace:', function () {
assert.equal(wrap(str, {trim: true}), ' A project without documentation is like a project\n that doesn\'t exist. Verb solves this by making it\n dead simple to generate project documentation,\n using simple markdown templates, with zero\n configuration required.');
});
it('should trim trailing whitespace (even for empty lines):', function () {
assert.equal(wrap("a \n\nb \n \nc\t", {trim: true}), ' a\n\n b\n\n c');
});
it('should handle strings with just newlines', function () {
assert.equal(wrap('\r\n', {indent: '\r\n', width: 18}), '\r\n');
});
it('should handle newlines that occur at the same position as `options.width`', function () {
assert.equal(wrap('asdfg\nqwert', {width:5}), ' asdfg\n qwert');
assert.equal(wrap('aaaaaa\nbbbbbb\ncccccc', {width:6}), ' aaaaaa\n bbbbbb\n cccccc');
});
it('should handle strings that break where there are multiple spaces', function() {
assert.equal(wrap('foo foo. bar', {width:8}), ' foo foo. \n bar');
assert.equal(wrap('foo foo. bar', {width:8, trim: true}), ' foo foo.\n bar');
});
it('should cut one long word', function() {
assert.equal(wrap('Supercalifragilisticexpialidocious', {width:24, cut:true}), ' Supercalifragilisticexpi\n alidocious');
});
it('should cut long words', function() {
assert.equal(wrap('Supercalifragilisticexpialidocious and Supercalifragilisticexpialidocious', {width:24, cut:true}), ' Supercalifragilisticexpi\n alidocious and Supercali\n fragilisticexpialidociou\n s');
});
it('should wrap on zero space characters', function () {
assert.equal(
wrap('Supercalifragilistic\u200Bexpialidocious', {width: 24}),
' Supercalifragilistic\u200B\n expialidocious'
);
});
});