-
-
Notifications
You must be signed in to change notification settings - Fork 0
/
test.js
113 lines (103 loc) · 2.32 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
/*!
* right-align-values <https://github.com/jonschlinkert/right-align-values>
*
* Copyright (c) 2015, Jon Schlinkert.
* Licensed under the MIT License.
*/
'use strict';
require('mocha');
var assert = require('assert');
var align = require('./');
var arr = [{a: 'b'}, {a: 'bb'}, {a: 'bbbb'}, {a: 'bbb'}, {a: 'bb'}];
describe('right align values', function () {
describe('array', function () {
it('should right-align the values for the given property', function () {
assert.deepEqual(align(arr, 'a'), [
{a: ' b'},
{a: ' bb'},
{a: 'bbbb'},
{a: ' bbb'},
{a: ' bb'}
]);
});
});
describe('objects', function () {
it('should right-align the values of an object', function () {
assert.deepEqual(align({a: 'b', c: 'dddddd', e: 'fff', g: 'hhhhh'}), {
a: ' b',
c: 'dddddd',
e: ' fff',
g: ' hhhhh',
});
});
it('should right-align values of a specific object property', function() {
var res = align('foo', {
a: {
foo: 'a',
bar: 'z'
},
b: {
foo: 'aaaaaaa',
bar: 'z'
},
c: {
foo: 'aaa',
bar: 'z'
}
});
assert.deepEqual(res, {
a: {
foo: ' a',
bar: 'z'
},
b: {
foo: 'aaaaaaa',
bar: 'z'
},
c: {
foo: ' aaa',
bar: 'z'
}
});
});
it('should right-align values for multiple properties', function() {
var res = align(['foo', 'bar'], {
a: {
foo: 'a',
bar: 'zzz'
},
b: {
foo: 'aaaaaaa',
bar: 'zz'
},
c: {
foo: 'aaa',
bar: 'zzzz'
}
});
assert.deepEqual(res, {
a: {
foo: ' a',
bar: ' zzz'
},
b: {
foo: 'aaaaaaa',
bar: ' zz'
},
c: {
foo: ' aaa',
bar: 'zzzz'
}
});
});
});
it('should throw an error when an array is not passed', function(cb) {
try {
align();
cb(new Error('expected an error'));
} catch (err) {
assert.equal(err.message, 'right-align-values expects an object or array.');
cb();
}
});
});