-
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain-tests.js
215 lines (165 loc) · 6.33 KB
/
main-tests.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
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
const { throws, deepEqual } = require('assert');
const mod = require('./main.js');
describe('OLSKStringFormatted', function test_OLSKStringFormatted() {
it('throws error if not string', function() {
throws(function() {
mod.OLSKStringFormatted(null);
}, /OLSKErrorInputNotValid/);
});
it('returns inputString if param1 without formatIdentifier', function() {
deepEqual(mod.OLSKStringFormatted('alfa', 'bravo'), 'alfa');
});
it('returns inputString if param2 without substitutions', function() {
deepEqual(mod.OLSKStringFormatted('alfa %@'), 'alfa %@');
});
it('returns formattedString for single formatIdentifier', function() {
deepEqual(mod.OLSKStringFormatted('alfa %@', 'bravo'), 'alfa bravo');
});
it('returns formattedString for multiple formatIdentifiers', function() {
deepEqual(mod.OLSKStringFormatted('alfa %@ %@', 'bravo', 'charlie'), 'alfa bravo charlie');
});
it('returns formattedString for single ordered formatIdentifier', function() {
deepEqual(mod.OLSKStringFormatted('alfa %$1@', 'bravo'), 'alfa bravo');
});
it('returns formattedString for multiple ordered formatIdentifiers', function() {
deepEqual(mod.OLSKStringFormatted('alfa %$2@ %$1@', 'bravo', 'charlie'), 'alfa charlie bravo');
});
});
describe('OLSKStringReplaceTokens', function test_OLSKStringReplaceTokens() {
it('throws error if param1 not string', function() {
throws(function() {
mod.OLSKStringReplaceTokens(null, {});
}, /OLSKErrorInputNotValid/);
});
it('throws error if param2 not object', function() {
throws(function() {
mod.OLSKStringReplaceTokens('', null);
}, /OLSKErrorInputNotValid/);
});
it('returns inputString', function() {
deepEqual(mod.OLSKStringReplaceTokens('', {}), '');
});
it('replaces token single', function() {
deepEqual(mod.OLSKStringReplaceTokens('alfa', {
alfa: 'bravo',
}), 'bravo');
});
it('replaces token multiple', function() {
deepEqual(mod.OLSKStringReplaceTokens('alfa alfa', {
alfa: 'bravo',
}), 'bravo bravo');
});
});
describe('OLSKStringPatch', function test_OLSKStringPatch() {
it('throws error if param1 not string', function() {
throws(function() {
mod.OLSKStringPatch(null, '', '');
}, /OLSKErrorInputNotValid/);
});
it('throws error if param2 not string', function() {
throws(function() {
mod.OLSKStringPatch('', null, '');
}, /OLSKErrorInputNotValid/);
});
it('throws error if param3 not string', function() {
throws(function() {
mod.OLSKStringPatch('', '', null);
}, /OLSKErrorInputNotValid/);
});
it('throws error if param2 in param3', function() {
throws(function() {
mod.OLSKStringPatch('alfa', 'alfa', 'alfa bravo');
}, /OLSKErrorInputNotValid/);
});
it('throws error if param2 and param3 not in param1', function() {
throws(function() {
mod.OLSKStringPatch('alfa', 'bravo', 'charlie');
}, /OLSKErrorInputNotValid/);
});
it.skip('throws error if replaces more than once', function() {
throws(function() {
mod.OLSKStringPatch('alfa', 'alfa', '// alfa');
}, /OLSKErrorInputNotValid/);
});
it('returns string', function() {
deepEqual(mod.OLSKStringPatch('alfa', 'alfa', 'bravo'), 'bravo');
});
it('replaces single', function() {
deepEqual(mod.OLSKStringPatch('alfa bravo', 'bravo', 'charlie'), 'alfa charlie');
});
it('replaces multiple', function() {
deepEqual(mod.OLSKStringPatch('alfa bravo bravo', 'bravo', 'charlie'), 'alfa charlie charlie');
});
});
describe('OLSKStringMatch', function test_OLSKStringMatch() {
it('throws error if param1 not string', function() {
throws(function() {
mod.OLSKStringMatch(null, Math.random().toString());
}, /OLSKErrorInputNotValid/);
});
it('throws error if param2 not string', function() {
throws(function() {
mod.OLSKStringMatch(Math.random().toString(), null);
}, /OLSKErrorInputNotValid/);
});
it('returns false if no match', function () {
deepEqual(mod.OLSKStringMatch(Math.random().toString(), Math.random().toString()), false);
});
it('matches exact', function () {
const item = Math.random().toString();
deepEqual(mod.OLSKStringMatch(item, item), true);
});
it('matches partial', function () {
const item = Math.random().toString();
deepEqual(mod.OLSKStringMatch(item.slice(0, 5), item), true);
});
it('matches case insensitive', function () {
deepEqual(mod.OLSKStringMatch('alf', 'ALF'), true);
});
it('matches diacritic insensitive', function () {
deepEqual(mod.OLSKStringMatch('alf', 'álfa'), true);
});
it('throws error if param3 not string', function() {
throws(function() {
mod.OLSKStringMatch(Math.random().toString(), Math.random().toString(), null);
}, /OLSKErrorInputNotValid/);
});
});
describe('OLSKStringSnippet', function test_OLSKStringSnippet() {
it('throws error if not string', function() {
throws(function() {
mod.OLSKStringSnippet(null);
}, /OLSKErrorInputNotValid/);
});
it('returns subset if large', function() {
const item = 'Lorem Ipsum is simply dummy text of the printing and typesetting industry. Lorem Ipsum has been the industry\'s standard dummy text ever since the 1500s, when an unknown printer took a galley of type and scrambled it to make a type specimen book. It has survived not only five centuries, but also the leap into electronic typesetting, remaining essentially unchanged. It was popularised in the 1960s with the release of Letraset sheets containing Lorem Ipsum passages, and more recently with desktop publishing software like Aldus PageMaker including versions of Lorem Ipsum.';
deepEqual(mod.OLSKStringSnippet(item), item.slice(0, 100).split(' ').slice(0, -1).join(' ') + '…');
});
it('returns all if small', function() {
deepEqual(mod.OLSKStringSnippet('alfa bravo'), 'alfa bravo');
});
});
describe('OLSKStringEncode', function test_OLSKStringEncode() {
it('throws error if not string', function() {
throws(function() {
mod.OLSKStringEncode(null);
}, /OLSKErrorInputNotValid/);
});
it('returns string', function() {
const item = Math.random().toString();
deepEqual(mod.OLSKStringEncode(item), item);
});
it('encodes url', function() {
const item = uLink();
deepEqual(mod.OLSKStringEncode(item), encodeURIComponent(item));
});
it('encodes brackets', function() {
const item = JSON.stringify({
alfa: '(bravo)',
});
deepEqual(mod.OLSKStringEncode(item), mod.OLSKStringReplaceTokens(encodeURIComponent(item), {
'\\(': '%28',
'\\)': '%29',
}));
});
});