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
152 lines (149 loc) · 4.23 KB
/
Copy pathindex.js
File metadata and controls
152 lines (149 loc) · 4.23 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
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
152
var test = require('../util/test')(__filename);
var leftPad = require('../../packages/string-left-pad');
test('left pad with default pad character', function(t1) {
test('strings with sufficient padding', function(t) {
t.plan(2);
t.equal(leftPad('hello', 9), ' hello');
t.equal(leftPad('a', 2), ' a');
t.end();
});
test('strings with insufficient padding', function(t) {
t.plan(2);
t.equal(leftPad('hello', 3), 'hello');
t.equal(leftPad('a', 1), 'a');
t.end();
});
test('empty string arg', function(t) {
t.plan(1);
t.equal(leftPad('', 4), ' ');
t.end();
});
test('zero length arg', function(t) {
t.plan(2);
t.equal(leftPad('hello', 0), 'hello');
t.equal(leftPad('', 0), '');
t.end();
});
test('strings with surrogate pairs', function(t) {
t.plan(2);
t.equal(leftPad('\uD83D\uDC04\uD83D\uDC04', 9), ' 🐄🐄');
t.equal(leftPad('\uD83D\uDC04\u00F6\u00F6\uD83D\uDC04', 9), ' 🐄öö🐄');
t.end();
});
t1.end();
test('first argument must be a string', function(t) {
t.plan(2);
t.throws(function() {
leftPad(['hello'], 8);
});
t.throws(function() {
leftPad(27, 9);
});
t.end();
});
test('second argument must be a positive finite integer', function(t) {
t.plan(5);
t.throws(function() {
leftPad('hello', '4');
});
t.throws(function() {
leftPad('hello', NaN);
});
t.throws(function() {
leftPad('hello', Number.POSITIVE_INFINITY);
});
t.throws(function() {
leftPad('hello', -1);
});
t.throws(function() {
leftPad('hello', 4.3);
});
t.end();
});
});
test('left pad with custom pad character', function(t2) {
test('strings with sufficient padding', function(t) {
t.plan(2);
t.equal(leftPad('hello', 9, '.'), '....hello');
t.equal(leftPad('a', 2, '_'), '_a');
t.end();
});
test('empty padding string treated as a space', function(t) {
t.plan(1);
t.equal(leftPad('no-pad', 12, ''), ' no-pad');
t.end();
});
test('strings with insufficient padding', function(t) {
t.plan(3);
t.equal(leftPad('hello', 3, '.'), 'hello');
t.equal(leftPad('a', 1, '_'), 'a');
t.equal(leftPad('no-pad', 4, ''), 'no-pad');
t.end();
});
test('empty string arg', function(t) {
t.plan(1);
t.equal(leftPad('', 4, '.'), '....');
t.end();
});
test('zero length arg', function(t) {
t.plan(2);
t.equal(leftPad('hello', 0, '.'), 'hello');
t.equal(leftPad('', 0, '.'), '');
t.end();
});
test('surrogate pairs as pad chars', function(t) {
t.plan(2);
t.equal(leftPad('hello', 9, '\uD83D\uDC04'), '🐄🐄🐄🐄hello');
t.equal(leftPad('hello', 6, '\uD83D\uDC11'), '🐑hello');
t.end();
});
test('pad argument must be a string', function(t) {
t.plan(2);
t.throws(function() {
leftPad('hello', 9, false);
});
t.throws(function() {
leftPad('hello', 12, 31);
});
t.end();
});
t2.end();
});
test('left pad with multiple custom pad characters', function(t3) {
test('strings with sufficient padding', function(t) {
t.plan(4);
t.equal(leftPad('hello', 9, '..'), '....hello');
t.equal(leftPad('hello', 8, '..'), '...hello');
t.equal(leftPad('hello', 9, 'ab'), 'ababhello');
t.equal(leftPad('hello', 8, 'ab'), 'babhello');
t.end();
});
test('strings with insufficient padding', function(t) {
t.plan(3);
t.equal(leftPad('hello', 3, '..'), 'hello');
t.equal(leftPad('a', 1, 'ab'), 'a');
t.equal(leftPad('no-pad', 4, '**'), 'no-pad');
t.end();
});
test('empty string arg', function(t) {
t.plan(3);
t.equal(leftPad('', 4, '..'), '....');
t.equal(leftPad('', 3, '..'), '...');
t.equal(leftPad('', 3, 'ab'), 'bab');
t.end();
});
test('surrogate pairs as pad chars', function(t) {
t.plan(2);
t.equal(leftPad('hello', 9, '\uD83D\uDC11\uD83D\uDC04'), '🐑🐄🐑🐄hello');
t.equal(leftPad('hello', 10, '\uD83D\uDC11\uD83D\uDC04'), '🐄🐑🐄🐑🐄hello');
t.end();
});
test("padding can't mix regular characters and surrogate pairs", function(t) {
t.plan(1);
t.throws(function() {
leftPad('hello', 9, 'o0053\uD83D\uDC04');
});
t.end();
});
t3.end();
});