forked from angus-c/just
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathindex.js
More file actions
70 lines (63 loc) · 1.87 KB
/
Copy pathindex.js
File metadata and controls
70 lines (63 loc) · 1.87 KB
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
70
var test = require('../util/test')(__filename);
var prune = require('../../packages/string-prune');
test('string defaulted with default suffix', function(t) {
t.plan(2);
var str = 'when shall we three meet again';
var result = prune(str, 9);
t.equal(result, 'when...');
result = prune(str, 13);
t.equal(result, 'when shall...');
t.end();
});
test('string defaulted with custom suffix', function(t) {
t.plan(2);
var str = 'when shall we three meet again';
var result = prune(str, 16, ' (etc)');
t.equal(result, 'when shall (etc)');
result = prune(str, 16, '');
t.equal(result, 'when shall we');
t.end();
});
test('no length specified', function(t) {
t.plan(1);
var str = 'when shall we three meet again';
var result = prune(str);
t.equal(result, 'when shall we three meet again');
t.end();
});
test('truncation length minus suffix length is shorter than first word', function(
t
) {
t.plan(1);
var str = 'when shall we three meet again';
var result = prune(str, 6);
t.equal(result, '...');
t.end();
});
test('string is shorter than truncation length', function(t) {
t.plan(2);
var str = 'when shall we';
var result = prune(str, 25);
t.equal(result, 'when shall we');
result = prune(str, 20, ' (more)');
t.equal(result, 'when shall we');
t.end();
});
test('suffix is greater than or equal to truncation length', function(t) {
t.plan(2);
var str = 'when shall we three meet again';
var result = prune(str, 10, ' (etc etc etc)');
t.equal(result, ' (etc etc etc)');
result = prune(str, 7, ' (more)');
t.equal(result, ' (more)');
t.end();
});
test('suffix is greater than or equal to string length', function(t) {
t.plan(2);
var str = 'when shall';
var result = prune(str, 10, ' very long suffix');
t.equal(result, 'when shall');
result = prune(str, 17, ' very long suffix');
t.equal(result, 'when shall');
t.end();
});