-
-
Notifications
You must be signed in to change notification settings - Fork 11
/
test.js
114 lines (99 loc) · 3.15 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
/*!
* align-text <https://github.com/jonschlinkert/align-text>
*
* Copyright (c) 2015-2017, Jon Schlinkert.
* Released under the MIT License.
*/
'use strict';
var assert = require('assert');
var align = require('./');
var fixture = [
'Lorem ipsum dolor sit amet,',
'consectetur adipiscing',
'elit, sed do eiusmod tempor incididunt',
'ut labore et dolore',
'magna aliqua. Ut enim ad minim',
'veniam, quis'
];
var expected = [
' Lorem ipsum dolor sit amet,',
' consectetur adipiscing',
'elit, sed do eiusmod tempor incididunt',
' ut labore et dolore',
' magna aliqua. Ut enim ad minim',
' veniam, quis'
];
var integer = [
' Lorem ipsum dolor sit amet,',
' consectetur adipiscing',
' elit, sed do eiusmod tempor incididunt',
' ut labore et dolore',
' magna aliqua. Ut enim ad minim',
' veniam, quis'
];
var prefixed = [
'- Lorem ipsum dolor sit amet,',
'- consectetur adipiscing',
'- elit, sed do eiusmod tempor incididunt',
'- ut labore et dolore',
'- magna aliqua. Ut enim ad minim',
'- veniam, quis'
];
var character = [
'~~~~~Lorem ipsum dolor sit amet,',
'~~~~~~~~consectetur adipiscing',
'elit, sed do eiusmod tempor incididunt',
'~~~~~~~~~ut labore et dolore',
'~~~~magna aliqua. Ut enim ad minim',
'~~~~~~~~~~~~~veniam, quis'
];
describe('align', function() {
describe('indent', function() {
it('should indent lines to the given value', function() {
assert.deepEqual(align(fixture, 5), integer);
});
it('should indent values to the longest length in an array', function() {
assert.deepEqual(align([7, 8, 9, 10]), [' 7', ' 8', ' 9', '10']);
assert.deepEqual(align(['a', ' b']), [' a', ' b']);
});
});
describe('function', function() {
it('should indent a string to the returned number', function() {
var actual = align(fixture, function(len, max, line, lines) {
return Math.floor((max - len) / 2);
});
assert.deepEqual(actual, expected);
});
it('should indent lines in an array to the returned number', function() {
var actual = align(fixture.join('\n'), function(len, max, line, lines) {
return Math.floor((max - len) / 2);
});
assert.deepEqual(actual, expected.join('\n'));
});
});
describe('object', function() {
it('should use the `indent` property', function() {
var actual = align(fixture, function(len, max, line, lines) {
return { indent: Math.floor((max - len) / 2) };
});
assert.deepEqual(actual, expected);
});
it('should use the `prefix` property', function() {
var actual = align(fixture, function(len, max, line, lines) {
return { prefix: '- ' };
});
assert.deepEqual(actual, prefixed);
});
it('should use the `character` property', function() {
var actual = align(fixture, function(len, max, line, lines) {
return { indent: Math.floor((max - len) / 2), character: '~', };
});
assert.deepEqual(actual, character);
});
});
it('should throw an error on invalid args', function() {
assert.throws(function() {
align();
});
});
});