-
-
Notifications
You must be signed in to change notification settings - Fork 5
/
Copy pathtest.js
151 lines (127 loc) · 4.61 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
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
'use strict';
require('mocha');
const assert = require('assert');
const romanize = require('romanize');
const listitem = require('./');
let li;
describe('listitem', () => {
beforeEach(() => {
li = listitem();
})
it('should not indent a list item when a level is not passed:', () => {
assert.equal(li(0, 'a'), '- a');
});
it('should use default indentation when not passed on options:', () => {
li = listitem({indent: ' '});
assert.equal(li(0, 'a'), '- a');
assert.equal(li(1, 'a'), ' * a');
assert.equal(li(2, 'a'), ' + a');
assert.equal(li(3, 'a'), ' - a');
});
it('should use an `indent` string when passed on the options:', () => {
li = listitem({indent: ' '});
assert.equal(li(0, 'a'), '- a');
assert.equal(li(1, 'a'), ' * a');
assert.equal(li(2, 'a'), ' + a');
assert.equal(li(3, 'a'), ' - a');
});
it('should respect zero indentation if define with `indent`:', () => {
li = listitem({indent: ''});
assert.equal(li(0, 'a'), '- a');
assert.equal(li(1, 'a'), '* a');
assert.equal(li(2, 'a'), '+ a');
assert.equal(li(3, 'a'), '- a');
});
it('should rotate default bullets:', () => {
assert.equal(li(0, 'a'), '- a');
assert.equal(li(1, 'a'), ' * a');
assert.equal(li(2, 'a'), ' + a');
assert.equal(li(3, 'a'), ' - a');
assert.equal(li(4, 'a'), ' * a');
assert.equal(li(5, 'a'), ' + a');
assert.equal(li(6, 'a'), ' - a');
assert.equal(li(7, 'a'), ' * a');
assert.equal(li(8, 'a'), ' + a');
assert.notEqual(li(7, 'a'), ' * a');
});
});
describe('custom characters', () => {
beforeEach(() => {
li = listitem();
})
it('should use no bullet when `nobullet` is passed:', () => {
li = listitem({nobullet: true});
assert.equal(li(0, 'a'), 'a');
assert.equal(li(1, 'a'), ' a');
assert.equal(li(2, 'a'), ' a');
assert.equal(li(3, 'a'), ' a');
assert.notEqual(li(7, 'a'), ' + a');
});
it('should use an array of custom characters:', () => {
li = listitem({chars: ['A', 'B', 'C', 'D']});
assert.equal(li(0, 'a'), 'A a');
assert.equal(li(1, 'a'), ' B a');
assert.equal(li(2, 'a'), ' C a');
assert.equal(li(3, 'a'), ' D a');
assert.notEqual(li(7, 'a'), ' + a');
});
it('should rotate custom characters:', () => {
li = listitem({chars: ['A', 'B', 'C', 'D']});
assert.equal(li(0, 'a'), 'A a');
assert.equal(li(1, 'a'), ' B a');
assert.equal(li(2, 'a'), ' C a');
assert.equal(li(3, 'a'), ' D a');
assert.equal(li(4, 'a'), ' A a');
assert.equal(li(5, 'a'), ' B a');
assert.equal(li(6, 'a'), ' C a');
assert.equal(li(7, 'a'), ' D a');
assert.equal(li(8, 'a'), ' A a');
assert.notEqual(li(7, 'a'), ' + a');
});
it('should expand a range of characters from a string:', () => {
li = listitem({ chars: '1..5' }, (indent, ch, index) => {
return indent + index + '.';
});
assert.equal(li(0), '1.');
assert.equal(li(1), ' 2.');
assert.equal(li(2), ' 3.');
assert.equal(li(3), ' 4.');
assert.equal(li(4), ' 5.');
});
it('should allow a function to modify the default characters:', () => {
li = listitem((indent, ch) => indent + ch + ch + ch + ' a');
assert.equal(li(0), '--- a');
assert.equal(li(1), ' *** a');
assert.equal(li(2), ' +++ a');
assert.equal(li(3), ' --- a');
});
it('should take an array of characters', () => {
li = listitem({ chars: [1, 2, 3, 4, 5, 6] }, (indent, ch) => {
return indent + romanize(ch) + '.';
});
let sub = listitem({ chars: [1, 2, 3, 4, 5, 6] }, (indent, ch) => {
return ' ' + ch;
});
assert.equal(li(0) + sub(0), 'I. 1');
assert.equal(li(0) + sub(1), 'I. 2');
assert.equal(li(0) + sub(2), 'I. 3');
assert.equal(li(1), ' II.');
assert.equal(li(2), ' III.');
assert.equal(li(3), ' IV.');
assert.equal(li(4), ' V.');
assert.equal(li(5), ' VI.');
});
it('should use a custom function when characters are generated by fill-range:', () => {
li = listitem({ chars: '1..100..10' }, (indent, ch, index) => {
return indent + romanize(ch) + '.';
});
assert.equal(li(0), 'I.');
assert.equal(li(1), ' XI.');
assert.equal(li(2), ' XXI.');
assert.equal(li(3), ' XXXI.');
assert.equal(li(4), ' XLI.');
});
it('should throw an error:', () => {
assert.throws(() => li(), /expected level to be a number/);
});
});