ejv 2.1.1 → 2.1.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/.mocharc.json +8 -8
- package/CHANGELOG.md +134 -135
- package/README-KR.md +597 -597
- package/README.md +603 -603
- package/build/cjs/constants.js +1 -0
- package/build/cjs/constants.js.map +1 -1
- package/build/cjs/ejv.js +3 -0
- package/build/cjs/ejv.js.map +1 -1
- package/build/cjs/tester.js +11 -1
- package/build/cjs/tester.js.map +1 -1
- package/build/constants.d.ts +1 -0
- package/build/esm/constants.js +1 -0
- package/build/esm/constants.js.map +1 -1
- package/build/esm/ejv.js +4 -1
- package/build/esm/ejv.js.map +1 -1
- package/build/esm/tester.js +9 -0
- package/build/esm/tester.js.map +1 -1
- package/build/tester.d.ts +1 -0
- package/eslint.config.mjs +66 -59
- package/package.json +54 -54
- package/scripts/add-js-extensions.ts +59 -59
- package/spec/ArrayScheme.ts +1021 -1021
- package/spec/CommonScheme.ts +251 -251
- package/spec/DateScheme.ts +472 -472
- package/spec/NumberScheme.ts +1160 -1160
- package/spec/ObjectScheme.ts +499 -499
- package/spec/RegExpScheme.ts +112 -112
- package/spec/StringScheme.ts +1407 -1336
- package/spec/common-test-util.ts +63 -63
- package/spec/ejv.spec.ts +235 -235
- package/spec/testers.spec.ts +833 -833
- package/src/constants.ts +164 -162
- package/src/ejv.ts +1751 -1746
- package/src/index.ts +14 -14
- package/src/interfaces.ts +144 -144
- package/src/tester.ts +323 -312
- package/src/util.ts +124 -124
- package/tsconfig.cjs.json +8 -8
- package/tsconfig.esm.json +7 -7
- package/tsconfig.json +19 -19
- package/tsconfig.scripts.json +14 -14
- package/tsconfig.types.json +9 -9
package/spec/testers.spec.ts
CHANGED
|
@@ -1,833 +1,833 @@
|
|
|
1
|
-
import { describe, it } from 'mocha';
|
|
2
|
-
import { expect } from 'chai';
|
|
3
|
-
|
|
4
|
-
import { commonTestRunner } from './common-test-util';
|
|
5
|
-
|
|
6
|
-
import {
|
|
7
|
-
arrayTester,
|
|
8
|
-
arrayTypeOfTester,
|
|
9
|
-
booleanTester,
|
|
10
|
-
dateFormatTester,
|
|
11
|
-
dateTester,
|
|
12
|
-
dateTimeFormatTester,
|
|
13
|
-
definedTester,
|
|
14
|
-
emailTester,
|
|
15
|
-
enumTester,
|
|
16
|
-
exclusiveMaxDateTester,
|
|
17
|
-
exclusiveMaxNumberTester,
|
|
18
|
-
exclusiveMinDateTester,
|
|
19
|
-
exclusiveMinNumberTester,
|
|
20
|
-
hasPropertyTester,
|
|
21
|
-
indexTester,
|
|
22
|
-
integerTester,
|
|
23
|
-
lengthTester,
|
|
24
|
-
maxDateTester,
|
|
25
|
-
maxLengthTester,
|
|
26
|
-
maxNumberTester,
|
|
27
|
-
minDateTester,
|
|
28
|
-
minLengthTester,
|
|
29
|
-
minNumberTester,
|
|
30
|
-
numberTester,
|
|
31
|
-
objectTester,
|
|
32
|
-
regExpTester,
|
|
33
|
-
stringRegExpTester,
|
|
34
|
-
stringTester,
|
|
35
|
-
timeFormatTester,
|
|
36
|
-
uniqueItemsTester
|
|
37
|
-
} from '../src/tester';
|
|
38
|
-
import { DATA_TYPE } from '../src/constants';
|
|
39
|
-
|
|
40
|
-
describe('testers', function () {
|
|
41
|
-
describe('common', () => {
|
|
42
|
-
describe('definedTester()', () => {
|
|
43
|
-
it('common test', () => {
|
|
44
|
-
expect(commonTestRunner(
|
|
45
|
-
definedTester,
|
|
46
|
-
true,
|
|
47
|
-
false,
|
|
48
|
-
true,
|
|
49
|
-
true,
|
|
50
|
-
true,
|
|
51
|
-
true,
|
|
52
|
-
true
|
|
53
|
-
)).to.be.true;
|
|
54
|
-
});
|
|
55
|
-
});
|
|
56
|
-
|
|
57
|
-
describe('enumTester()', () => {
|
|
58
|
-
it('logic test', () => {
|
|
59
|
-
expect(enumTester('a', ['a', 'b', 'c'])).to.be.true;
|
|
60
|
-
expect(enumTester('a', ['b', 'c'])).to.be.false;
|
|
61
|
-
|
|
62
|
-
expect(enumTester(1, [1, 2, 3])).to.be.true;
|
|
63
|
-
expect(enumTester(1, [2, 3])).to.be.false;
|
|
64
|
-
});
|
|
65
|
-
});
|
|
66
|
-
|
|
67
|
-
describe('lengthTester()', () => {
|
|
68
|
-
it('logic test', () => {
|
|
69
|
-
expect(lengthTester('abcd', 3)).to.be.false;
|
|
70
|
-
expect(lengthTester('abcd', 4)).to.be.true;
|
|
71
|
-
expect(lengthTester('abcd', 5)).to.be.false;
|
|
72
|
-
|
|
73
|
-
expect(lengthTester([1, 2, 3, 4], 3)).to.be.false;
|
|
74
|
-
expect(lengthTester([1, 2, 3, 4], 4)).to.be.true;
|
|
75
|
-
expect(lengthTester([1, 2, 3, 4], 5)).to.be.false;
|
|
76
|
-
});
|
|
77
|
-
});
|
|
78
|
-
|
|
79
|
-
describe('minLengthTester()', () => {
|
|
80
|
-
it('logic test', () => {
|
|
81
|
-
expect(minLengthTester('abcd', 3)).to.be.true;
|
|
82
|
-
expect(minLengthTester('abcd', 4)).to.be.true;
|
|
83
|
-
expect(minLengthTester('abcd', 5)).to.be.false;
|
|
84
|
-
|
|
85
|
-
expect(minLengthTester([1, 2, 3, 4], 3)).to.be.true;
|
|
86
|
-
expect(minLengthTester([1, 2, 3, 4], 4)).to.be.true;
|
|
87
|
-
expect(minLengthTester([1, 2, 3, 4], 5)).to.be.false;
|
|
88
|
-
});
|
|
89
|
-
});
|
|
90
|
-
|
|
91
|
-
describe('maxLengthTester()', () => {
|
|
92
|
-
it('logic test', () => {
|
|
93
|
-
expect(maxLengthTester('abcd', 3)).to.be.false;
|
|
94
|
-
expect(maxLengthTester('abcd', 4)).to.be.true;
|
|
95
|
-
expect(maxLengthTester('abcd', 5)).to.be.true;
|
|
96
|
-
|
|
97
|
-
expect(maxLengthTester([1, 2, 3, 4], 3)).to.be.false;
|
|
98
|
-
expect(maxLengthTester([1, 2, 3, 4], 4)).to.be.true;
|
|
99
|
-
expect(maxLengthTester([1, 2, 3, 4], 5)).to.be.true;
|
|
100
|
-
});
|
|
101
|
-
});
|
|
102
|
-
});
|
|
103
|
-
|
|
104
|
-
describe('boolean', () => {
|
|
105
|
-
describe('booleanTester()', () => {
|
|
106
|
-
it('common test', () => {
|
|
107
|
-
expect(commonTestRunner(
|
|
108
|
-
booleanTester,
|
|
109
|
-
false,
|
|
110
|
-
false,
|
|
111
|
-
true,
|
|
112
|
-
false,
|
|
113
|
-
false,
|
|
114
|
-
false,
|
|
115
|
-
false
|
|
116
|
-
)).to.be.true;
|
|
117
|
-
});
|
|
118
|
-
|
|
119
|
-
it('logic test', () => {
|
|
120
|
-
expect(booleanTester(true)).to.be.true;
|
|
121
|
-
expect(booleanTester(false)).to.be.true;
|
|
122
|
-
|
|
123
|
-
expect(booleanTester('true')).to.be.false;
|
|
124
|
-
expect(booleanTester('false')).to.be.false;
|
|
125
|
-
|
|
126
|
-
expect(booleanTester(1)).to.be.false;
|
|
127
|
-
expect(booleanTester(0)).to.be.false;
|
|
128
|
-
});
|
|
129
|
-
});
|
|
130
|
-
});
|
|
131
|
-
|
|
132
|
-
describe('number', () => {
|
|
133
|
-
describe('numberTester()', () => {
|
|
134
|
-
it('common test', () => {
|
|
135
|
-
expect(commonTestRunner(
|
|
136
|
-
numberTester,
|
|
137
|
-
false,
|
|
138
|
-
false,
|
|
139
|
-
false,
|
|
140
|
-
true,
|
|
141
|
-
false,
|
|
142
|
-
false,
|
|
143
|
-
false
|
|
144
|
-
)).to.be.true;
|
|
145
|
-
});
|
|
146
|
-
|
|
147
|
-
it('logic test', () => {
|
|
148
|
-
expect(numberTester(true)).to.be.false;
|
|
149
|
-
expect(numberTester(null)).to.be.false;
|
|
150
|
-
|
|
151
|
-
expect(numberTester(-10.6)).to.be.true;
|
|
152
|
-
expect(numberTester(-1)).to.be.true;
|
|
153
|
-
expect(numberTester(0)).to.be.true;
|
|
154
|
-
expect(numberTester(5)).to.be.true;
|
|
155
|
-
expect(numberTester(5.5)).to.be.true;
|
|
156
|
-
|
|
157
|
-
expect(numberTester('8')).to.be.false;
|
|
158
|
-
expect(numberTester('8.5')).to.be.false;
|
|
159
|
-
|
|
160
|
-
expect(numberTester(NaN)).to.be.false;
|
|
161
|
-
});
|
|
162
|
-
});
|
|
163
|
-
|
|
164
|
-
describe('integerTester()', () => {
|
|
165
|
-
it('logic test', () => {
|
|
166
|
-
expect(integerTester(-10.6)).to.be.false;
|
|
167
|
-
expect(integerTester(-1)).to.be.true;
|
|
168
|
-
expect(integerTester(0)).to.be.true;
|
|
169
|
-
expect(integerTester(5)).to.be.true;
|
|
170
|
-
expect(integerTester(5.5)).to.be.false;
|
|
171
|
-
});
|
|
172
|
-
});
|
|
173
|
-
|
|
174
|
-
describe('indexTester()', () => {
|
|
175
|
-
it('logic test', () => {
|
|
176
|
-
expect(indexTester(-10.6)).to.be.false;
|
|
177
|
-
expect(indexTester(-1)).to.be.false;
|
|
178
|
-
expect(indexTester(0)).to.be.true;
|
|
179
|
-
expect(indexTester(5)).to.be.true;
|
|
180
|
-
expect(indexTester(5.5)).to.be.false;
|
|
181
|
-
});
|
|
182
|
-
});
|
|
183
|
-
|
|
184
|
-
describe('minNumberTester()', () => {
|
|
185
|
-
it('logic test', () => {
|
|
186
|
-
expect(minNumberTester(-11, -12)).to.be.true;
|
|
187
|
-
expect(minNumberTester(-11, -11)).to.be.true;
|
|
188
|
-
expect(minNumberTester(-11, -10)).to.be.false;
|
|
189
|
-
|
|
190
|
-
expect(minNumberTester(0, -1)).to.be.true;
|
|
191
|
-
expect(minNumberTester(0, 0)).to.be.true;
|
|
192
|
-
expect(minNumberTester(0, 1)).to.be.false;
|
|
193
|
-
|
|
194
|
-
expect(minNumberTester(50, 49.9)).to.be.true;
|
|
195
|
-
expect(minNumberTester(50, 50)).to.be.true;
|
|
196
|
-
expect(minNumberTester(50, 50.1)).to.be.false;
|
|
197
|
-
});
|
|
198
|
-
});
|
|
199
|
-
|
|
200
|
-
describe('exclusiveMinNumberTester()', () => {
|
|
201
|
-
it('logic test', () => {
|
|
202
|
-
expect(exclusiveMinNumberTester(-11, -12)).to.be.true;
|
|
203
|
-
expect(exclusiveMinNumberTester(-11, -11)).to.be.false;
|
|
204
|
-
expect(exclusiveMinNumberTester(-11, -10)).to.be.false;
|
|
205
|
-
|
|
206
|
-
expect(exclusiveMinNumberTester(0, -1)).to.be.true;
|
|
207
|
-
expect(exclusiveMinNumberTester(0, 0)).to.be.false;
|
|
208
|
-
expect(exclusiveMinNumberTester(0, 1)).to.be.false;
|
|
209
|
-
|
|
210
|
-
expect(exclusiveMinNumberTester(50, 49.9)).to.be.true;
|
|
211
|
-
expect(exclusiveMinNumberTester(50, 50)).to.be.false;
|
|
212
|
-
expect(exclusiveMinNumberTester(50, 50.1)).to.be.false;
|
|
213
|
-
});
|
|
214
|
-
});
|
|
215
|
-
|
|
216
|
-
describe('maxNumberTester()', () => {
|
|
217
|
-
it('logic test', () => {
|
|
218
|
-
expect(maxNumberTester(-11, -12)).to.be.false;
|
|
219
|
-
expect(maxNumberTester(-11, -11)).to.be.true;
|
|
220
|
-
expect(maxNumberTester(-11, -10)).to.be.true;
|
|
221
|
-
|
|
222
|
-
expect(maxNumberTester(0, -1)).to.be.false;
|
|
223
|
-
expect(maxNumberTester(0, 0)).to.be.true;
|
|
224
|
-
expect(maxNumberTester(0, 1)).to.be.true;
|
|
225
|
-
|
|
226
|
-
expect(maxNumberTester(50, 49.9)).to.be.false;
|
|
227
|
-
expect(maxNumberTester(50, 50)).to.be.true;
|
|
228
|
-
expect(maxNumberTester(50, 50.1)).to.be.true;
|
|
229
|
-
});
|
|
230
|
-
});
|
|
231
|
-
|
|
232
|
-
describe('exclusiveMaxNumberTester()', () => {
|
|
233
|
-
it('logic test', () => {
|
|
234
|
-
expect(exclusiveMaxNumberTester(-11, -12)).to.be.false;
|
|
235
|
-
expect(exclusiveMaxNumberTester(-11, -11)).to.be.false;
|
|
236
|
-
expect(exclusiveMaxNumberTester(-11, -10)).to.be.true;
|
|
237
|
-
|
|
238
|
-
expect(exclusiveMaxNumberTester(0, -1)).to.be.false;
|
|
239
|
-
expect(exclusiveMaxNumberTester(0, 0)).to.be.false;
|
|
240
|
-
expect(exclusiveMaxNumberTester(0, 1)).to.be.true;
|
|
241
|
-
|
|
242
|
-
expect(exclusiveMaxNumberTester(50, 49.9)).to.be.false;
|
|
243
|
-
expect(exclusiveMaxNumberTester(50, 50)).to.be.false;
|
|
244
|
-
expect(exclusiveMaxNumberTester(50, 50.1)).to.be.true;
|
|
245
|
-
});
|
|
246
|
-
});
|
|
247
|
-
});
|
|
248
|
-
|
|
249
|
-
describe('string', () => {
|
|
250
|
-
describe('stringTester()', () => {
|
|
251
|
-
it('common test', () => {
|
|
252
|
-
expect(commonTestRunner(
|
|
253
|
-
stringTester,
|
|
254
|
-
false,
|
|
255
|
-
false,
|
|
256
|
-
false,
|
|
257
|
-
false,
|
|
258
|
-
true,
|
|
259
|
-
false,
|
|
260
|
-
false
|
|
261
|
-
)).to.be.true;
|
|
262
|
-
});
|
|
263
|
-
|
|
264
|
-
it('logic test', () => {
|
|
265
|
-
expect(stringTester('')).to.be.true;
|
|
266
|
-
expect(stringTester(' ')).to.be.true;
|
|
267
|
-
expect(stringTester('hello')).to.be.true;
|
|
268
|
-
});
|
|
269
|
-
});
|
|
270
|
-
|
|
271
|
-
describe('stringRegExpTester()', () => {
|
|
272
|
-
it('logic test', () => {
|
|
273
|
-
expect(stringRegExpTester('abc', /abc/)).to.be.true;
|
|
274
|
-
expect(stringRegExpTester('abc', /abcd/)).to.be.false;
|
|
275
|
-
|
|
276
|
-
expect(stringRegExpTester('abc', new RegExp('abc'))).to.be.true;
|
|
277
|
-
expect(stringRegExpTester('abc', new RegExp('abcd'))).to.be.false;
|
|
278
|
-
});
|
|
279
|
-
});
|
|
280
|
-
|
|
281
|
-
describe('emailTester()', () => {
|
|
282
|
-
it('logic test', () => {
|
|
283
|
-
expect(emailTester('')).to.be.false;
|
|
284
|
-
expect(emailTester(' ')).to.be.false;
|
|
285
|
-
expect(emailTester('hello')).to.be.false;
|
|
286
|
-
expect(emailTester('hello@')).to.be.false;
|
|
287
|
-
expect(emailTester('hello@domain')).to.be.true;
|
|
288
|
-
expect(emailTester('hello@domain.')).to.be.false;
|
|
289
|
-
expect(emailTester('hello@domain.com')).to.be.true;
|
|
290
|
-
expect(emailTester('hello@domain.com.')).to.be.false;
|
|
291
|
-
expect(emailTester('hello@domain.com.another')).to.be.true;
|
|
292
|
-
|
|
293
|
-
expect(emailTester('prettyandsimple@example.com')).to.be.true;
|
|
294
|
-
expect(emailTester('very.common@example.com')).to.be.true;
|
|
295
|
-
expect(emailTester('disposable.style.email.with+symbol@example.com')).to.be.true;
|
|
296
|
-
expect(emailTester('other.email-with-dash@example.com')).to.be.true;
|
|
297
|
-
expect(emailTester('x@example.com')).to.be.true;
|
|
298
|
-
expect(emailTester('"much.more unusual"@example.com')).to.be.true;
|
|
299
|
-
expect(emailTester('"very.unusual.@.unusual.com"@example.com')).to.be.true;
|
|
300
|
-
expect(emailTester('example-indeed@strange-example.com')).to.be.true;
|
|
301
|
-
expect(emailTester('admin@mailserver1')).to.be.true;
|
|
302
|
-
expect(emailTester('#!$%&\'*+-/=?^_`{}|~@example.org')).to.be.true;
|
|
303
|
-
expect(emailTester('"()<>[]:,;@\\\\\\"!#$%&\'-/=?^_`{}| ~.a"@example.org')).to.be.true;
|
|
304
|
-
expect(emailTester('" "@example.org')).to.be.true;
|
|
305
|
-
expect(emailTester('example@localhost')).to.be.true;
|
|
306
|
-
expect(emailTester('example@s.solutions')).to.be.true;
|
|
307
|
-
expect(emailTester('user@localserver')).to.be.true;
|
|
308
|
-
expect(emailTester('user@tt')).to.be.true;
|
|
309
|
-
expect(emailTester('user@[IPv6:2001:DB8::1]')).to.be.true;
|
|
310
|
-
|
|
311
|
-
expect(emailTester('Abc.example.com')).to.be.false;
|
|
312
|
-
expect(emailTester('A@b@c@example.com')).to.be.false;
|
|
313
|
-
expect(emailTester('"A@b@c"@example.com')).to.be.true;
|
|
314
|
-
|
|
315
|
-
expect(emailTester('a"b(c)d,e:f;g<h>i[j\\k]l@example.com')).to.be.false;
|
|
316
|
-
expect(emailTester('just"not"right@example.com')).to.be.false;
|
|
317
|
-
expect(emailTester('this is"notallowed@example.com')).to.be.false;
|
|
318
|
-
expect(emailTester('this still"not\\allowed@example.com')).to.be.false;
|
|
319
|
-
expect(emailTester('1234567890123456789012345678901234567890123456789012345678901234+x@example.com')).to.be.false;
|
|
320
|
-
expect(emailTester('john..doe@example.com')).to.be.false;
|
|
321
|
-
expect(emailTester('john.doe@example..com')).to.be.false;
|
|
322
|
-
|
|
323
|
-
expect(emailTester(' ejv@ejv.com')).to.be.false;
|
|
324
|
-
expect(emailTester('ejv@ejv.com ')).to.be.false;
|
|
325
|
-
});
|
|
326
|
-
});
|
|
327
|
-
|
|
328
|
-
describe('dateFormatTester()', () => {
|
|
329
|
-
it('logic test', () => {
|
|
330
|
-
//// ISO 8601
|
|
331
|
-
// year
|
|
332
|
-
expect(dateFormatTester('100')).to.be.false;
|
|
333
|
-
expect(dateFormatTester('1000')).to.be.true;
|
|
334
|
-
expect(dateFormatTester('+2000')).to.be.true;
|
|
335
|
-
expect(dateFormatTester('-2000')).to.be.true;
|
|
336
|
-
|
|
337
|
-
// calendar date
|
|
338
|
-
expect(dateFormatTester('2018-1-17')).to.be.false;
|
|
339
|
-
expect(dateFormatTester('2018-12-32')).to.be.false;
|
|
340
|
-
expect(dateFormatTester('2018-12-17')).to.be.true;
|
|
341
|
-
expect(dateFormatTester('2018-13-17')).to.be.false;
|
|
342
|
-
expect(dateFormatTester('2018-12-7')).to.be.false;
|
|
343
|
-
|
|
344
|
-
// expect(dateFormatTester('2018117')).to.be.false; // matching for ordinal dates
|
|
345
|
-
expect(dateFormatTester('20181217')).to.be.true;
|
|
346
|
-
expect(dateFormatTester('20181317')).to.be.false;
|
|
347
|
-
expect(dateFormatTester('20181232')).to.be.false;
|
|
348
|
-
|
|
349
|
-
expect(dateFormatTester('2018-1')).to.be.false;
|
|
350
|
-
expect(dateFormatTester('2018-12')).to.be.true;
|
|
351
|
-
expect(dateFormatTester('2018-13')).to.be.false;
|
|
352
|
-
|
|
353
|
-
expect(dateFormatTester('--1-17')).to.be.false;
|
|
354
|
-
expect(dateFormatTester('--12-1')).to.be.false;
|
|
355
|
-
expect(dateFormatTester('--12-17')).to.be.true;
|
|
356
|
-
expect(dateFormatTester('--13-17')).to.be.false;
|
|
357
|
-
expect(dateFormatTester('--12-32')).to.be.false;
|
|
358
|
-
|
|
359
|
-
expect(dateFormatTester('--117')).to.be.false;
|
|
360
|
-
expect(dateFormatTester('--1317')).to.be.false;
|
|
361
|
-
expect(dateFormatTester('--1232')).to.be.false;
|
|
362
|
-
expect(dateFormatTester('--1217')).to.be.true;
|
|
363
|
-
|
|
364
|
-
// week dates
|
|
365
|
-
expect(dateFormatTester('2018-W01')).to.be.true;
|
|
366
|
-
expect(dateFormatTester('2018-W53')).to.be.true;
|
|
367
|
-
|
|
368
|
-
expect(dateFormatTester('2018-W00')).to.be.false;
|
|
369
|
-
expect(dateFormatTester('2018-W54')).to.be.false;
|
|
370
|
-
|
|
371
|
-
expect(dateFormatTester('2018-W01-3')).to.be.true;
|
|
372
|
-
expect(dateFormatTester('2018-W53-7')).to.be.true;
|
|
373
|
-
|
|
374
|
-
expect(dateFormatTester('2018-W01-0')).to.be.false;
|
|
375
|
-
expect(dateFormatTester('2018-W53-8')).to.be.false;
|
|
376
|
-
|
|
377
|
-
expect(dateFormatTester('2018W01')).to.be.true;
|
|
378
|
-
expect(dateFormatTester('2018W53')).to.be.true;
|
|
379
|
-
|
|
380
|
-
expect(dateFormatTester('2018W00')).to.be.false;
|
|
381
|
-
expect(dateFormatTester('2018W54')).to.be.false;
|
|
382
|
-
|
|
383
|
-
expect(dateFormatTester('2018W010')).to.be.false;
|
|
384
|
-
expect(dateFormatTester('2018W538')).to.be.false;
|
|
385
|
-
|
|
386
|
-
// ordinal dates
|
|
387
|
-
expect(dateFormatTester('2018-052')).to.be.true;
|
|
388
|
-
|
|
389
|
-
expect(dateFormatTester('2018-000')).to.be.false;
|
|
390
|
-
expect(dateFormatTester('2018-367')).to.be.false;
|
|
391
|
-
|
|
392
|
-
expect(dateFormatTester('2018052')).to.be.true;
|
|
393
|
-
|
|
394
|
-
expect(dateFormatTester('2018000')).to.be.false;
|
|
395
|
-
expect(dateFormatTester('2018367')).to.be.false;
|
|
396
|
-
});
|
|
397
|
-
});
|
|
398
|
-
|
|
399
|
-
describe('timeFormatTester()', () => {
|
|
400
|
-
it('logic test', () => {
|
|
401
|
-
// hh:mm:ss.sss, hh:mm:ss
|
|
402
|
-
expect(timeFormatTester('23:35:12.123')).to.be.true;
|
|
403
|
-
expect(timeFormatTester('24:00:00')).to.be.true;
|
|
404
|
-
expect(timeFormatTester('24:00:00.000')).to.be.true;
|
|
405
|
-
|
|
406
|
-
expect(timeFormatTester('3:35:12.123')).to.be.false;
|
|
407
|
-
expect(timeFormatTester('24:35:12.123')).to.be.false;
|
|
408
|
-
expect(timeFormatTester('25:35:12.123')).to.be.false;
|
|
409
|
-
|
|
410
|
-
expect(timeFormatTester('23:0:12.123')).to.be.false;
|
|
411
|
-
expect(timeFormatTester('23:60:12.123')).to.be.false;
|
|
412
|
-
|
|
413
|
-
expect(timeFormatTester('23:35:2.123')).to.be.false;
|
|
414
|
-
expect(timeFormatTester('23:35:60.123')).to.be.true; // leap second
|
|
415
|
-
expect(timeFormatTester('23:35:61.123')).to.be.false;
|
|
416
|
-
|
|
417
|
-
expect(timeFormatTester('23:35:12')).to.be.true;
|
|
418
|
-
expect(timeFormatTester('23:35:12.1')).to.be.true;
|
|
419
|
-
expect(timeFormatTester('23:35:12.12')).to.be.true;
|
|
420
|
-
expect(timeFormatTester('23:35:12.123')).to.be.true;
|
|
421
|
-
expect(timeFormatTester('23:35:12.1234')).to.be.true;
|
|
422
|
-
expect(timeFormatTester('23:35:12.12356789')).to.be.true;
|
|
423
|
-
|
|
424
|
-
// hh:mm
|
|
425
|
-
expect(timeFormatTester('23:52')).to.be.true;
|
|
426
|
-
expect(timeFormatTester('24:00')).to.be.true;
|
|
427
|
-
|
|
428
|
-
expect(timeFormatTester('2:52')).to.be.false;
|
|
429
|
-
expect(timeFormatTester('24:52')).to.be.false;
|
|
430
|
-
|
|
431
|
-
expect(timeFormatTester('23:2')).to.be.false;
|
|
432
|
-
expect(timeFormatTester('23:60')).to.be.false;
|
|
433
|
-
|
|
434
|
-
// hhmmss.sss, hhmmss
|
|
435
|
-
expect(timeFormatTester('233512.123')).to.be.true;
|
|
436
|
-
expect(timeFormatTester('240000')).to.be.true;
|
|
437
|
-
expect(timeFormatTester('240000.000')).to.be.true;
|
|
438
|
-
|
|
439
|
-
expect(timeFormatTester('33512.123')).to.be.false;
|
|
440
|
-
expect(timeFormatTester('243512.123')).to.be.false;
|
|
441
|
-
expect(timeFormatTester('253512.123')).to.be.false;
|
|
442
|
-
|
|
443
|
-
expect(timeFormatTester('23012.123')).to.be.false;
|
|
444
|
-
expect(timeFormatTester('236012.123')).to.be.false;
|
|
445
|
-
|
|
446
|
-
expect(timeFormatTester('23352.123')).to.be.false;
|
|
447
|
-
expect(timeFormatTester('233560.123')).to.be.true; // leap second
|
|
448
|
-
expect(timeFormatTester('233561.123')).to.be.false;
|
|
449
|
-
|
|
450
|
-
expect(timeFormatTester('233512')).to.be.true;
|
|
451
|
-
expect(timeFormatTester('233512.1')).to.be.true;
|
|
452
|
-
expect(timeFormatTester('233512.12')).to.be.true;
|
|
453
|
-
expect(timeFormatTester('233512.123')).to.be.true;
|
|
454
|
-
expect(timeFormatTester('233512.1234')).to.be.true;
|
|
455
|
-
expect(timeFormatTester('233512.12356789')).to.be.true;
|
|
456
|
-
|
|
457
|
-
// hhmm
|
|
458
|
-
expect(timeFormatTester('2352')).to.be.true;
|
|
459
|
-
expect(timeFormatTester('2400')).to.be.true;
|
|
460
|
-
|
|
461
|
-
expect(timeFormatTester('252')).to.be.false;
|
|
462
|
-
expect(timeFormatTester('2452')).to.be.false;
|
|
463
|
-
|
|
464
|
-
expect(timeFormatTester('2360')).to.be.false;
|
|
465
|
-
|
|
466
|
-
// hh
|
|
467
|
-
expect(timeFormatTester('00')).to.be.true;
|
|
468
|
-
expect(timeFormatTester('05')).to.be.true;
|
|
469
|
-
expect(timeFormatTester('24')).to.be.true;
|
|
470
|
-
|
|
471
|
-
expect(timeFormatTester('25')).to.be.false;
|
|
472
|
-
});
|
|
473
|
-
});
|
|
474
|
-
|
|
475
|
-
describe('dateTimeFormatTester()', () => {
|
|
476
|
-
it('logic test', () => {
|
|
477
|
-
// RFC 3339
|
|
478
|
-
expect(dateTimeFormatTester('2018-12-16T05:04:05')).to.be.true;
|
|
479
|
-
expect(dateTimeFormatTester('2018-12-16T05:04:05.51')).to.be.true;
|
|
480
|
-
expect(dateTimeFormatTester('2018-12-16T05:04:05.51Z')).to.be.true;
|
|
481
|
-
expect(dateTimeFormatTester('2018-12-16T05:04:05+09:00')).to.be.true;
|
|
482
|
-
|
|
483
|
-
expect(dateTimeFormatTester('2018-12-16T03:34:21')).to.be.true;
|
|
484
|
-
expect(dateTimeFormatTester('2018-12-16T03:34:21Z')).to.be.true;
|
|
485
|
-
expect(dateTimeFormatTester('2018-12-16T03:34:21.000')).to.be.true;
|
|
486
|
-
expect(dateTimeFormatTester('2018-12-16T03:34:21.000Z')).to.be.true;
|
|
487
|
-
expect(dateTimeFormatTester('2018-12-16T03:34:21.000+09:00')).to.be.true;
|
|
488
|
-
expect(dateTimeFormatTester('2018-12-16T03:34:21.000-08:00')).to.be.true;
|
|
489
|
-
|
|
490
|
-
expect(dateTimeFormatTester('2018-00-16T03:34:21')).to.be.false;
|
|
491
|
-
expect(dateTimeFormatTester('2018-13-16T03:34:21')).to.be.false;
|
|
492
|
-
expect(dateTimeFormatTester('2018-1-16T03:34:21')).to.be.false;
|
|
493
|
-
expect(dateTimeFormatTester('2018-12-6T03:34:21')).to.be.false;
|
|
494
|
-
expect(dateTimeFormatTester('2018-12-32T03:34:21')).to.be.false;
|
|
495
|
-
expect(dateTimeFormatTester('2018-12-16T0:34:21')).to.be.false;
|
|
496
|
-
expect(dateTimeFormatTester('2018-12-16T24:34:21')).to.be.false;
|
|
497
|
-
expect(dateTimeFormatTester('2018-12-16T03:4:21')).to.be.false;
|
|
498
|
-
expect(dateTimeFormatTester('2018-12-16T03:60:21')).to.be.false;
|
|
499
|
-
expect(dateTimeFormatTester('2018-12-16T03:34:1')).to.be.false;
|
|
500
|
-
expect(dateTimeFormatTester('2018-12-16T03:34:60')).to.be.false;
|
|
501
|
-
expect(dateTimeFormatTester('2018-12-16T03:34:21.')).to.be.false;
|
|
502
|
-
|
|
503
|
-
// // leap second inserted
|
|
504
|
-
// expect(dateTimeFormatTester('1990-12-31T23:59:60Z')).to.be.true;
|
|
505
|
-
// expect(dateTimeFormatTester('1990-12-31T15:59:60-08:00')).to.be.true;
|
|
506
|
-
|
|
507
|
-
// ISO 8601
|
|
508
|
-
expect(dateTimeFormatTester('20181219T00:38:05Z')).to.be.true;
|
|
509
|
-
expect(dateTimeFormatTester('20181219T00:38:05+00:00')).to.be.true;
|
|
510
|
-
});
|
|
511
|
-
});
|
|
512
|
-
});
|
|
513
|
-
|
|
514
|
-
// describe('urlTester()', () => {
|
|
515
|
-
// it('common test', () => {
|
|
516
|
-
// expect(commonTestRunner(
|
|
517
|
-
// urlTester,
|
|
518
|
-
// false,
|
|
519
|
-
// false,
|
|
520
|
-
// false,
|
|
521
|
-
// false,
|
|
522
|
-
// false,
|
|
523
|
-
// false,
|
|
524
|
-
// false
|
|
525
|
-
// )).to.be.true;
|
|
526
|
-
// });
|
|
527
|
-
//
|
|
528
|
-
// it('logic test', () => {
|
|
529
|
-
// expect(urlTester('')).to.be.false;
|
|
530
|
-
// expect(urlTester(' ')).to.be.false;
|
|
531
|
-
// expect(urlTester('hello')).to.be.false;
|
|
532
|
-
// expect(urlTester('http://hello')).to.be.false;
|
|
533
|
-
// expect(urlTester('https://hello')).to.be.false;
|
|
534
|
-
// expect(urlTester('http://hello.com')).to.be.true;
|
|
535
|
-
// expect(urlTester('http://hello.com/')).to.be.true;
|
|
536
|
-
// expect(urlTester('http://hello.com/#1')).to.be.true;
|
|
537
|
-
// expect(urlTester('http://hello.com/child')).to.be.true;
|
|
538
|
-
// expect(urlTester('http://hello.com/child/grand')).to.be.true;
|
|
539
|
-
// expect(urlTester('http://hello.com/child/grand?query=some')).to.be.true;
|
|
540
|
-
// expect(urlTester('http://hello.com/child/grand(some:angular)')).to.be.true;
|
|
541
|
-
// });
|
|
542
|
-
// });
|
|
543
|
-
//
|
|
544
|
-
// describe('ipv4Tester()', () => {
|
|
545
|
-
// it('common test', () => {
|
|
546
|
-
// expect(commonTestRunner(
|
|
547
|
-
// ipv4Tester,
|
|
548
|
-
// false,
|
|
549
|
-
// false,
|
|
550
|
-
// false,
|
|
551
|
-
// false,
|
|
552
|
-
// false,
|
|
553
|
-
// false,
|
|
554
|
-
// false
|
|
555
|
-
// )).to.be.true;
|
|
556
|
-
// });
|
|
557
|
-
//
|
|
558
|
-
// it('logic test', () => {
|
|
559
|
-
// expect(ipv4Tester('')).to.be.false;
|
|
560
|
-
// expect(ipv4Tester(' ')).to.be.false;
|
|
561
|
-
// expect(ipv4Tester('127.0.0')).to.be.false;
|
|
562
|
-
// expect(ipv4Tester('127.0.0.1')).to.be.true;
|
|
563
|
-
// expect(ipv4Tester('256.0.0.1')).to.be.false;
|
|
564
|
-
// expect(ipv4Tester('255.-1.0.1')).to.be.false;
|
|
565
|
-
// expect(ipv4Tester('255.256.267.1')).to.be.false;
|
|
566
|
-
// expect(ipv4Tester('255.255.255.0')).to.be.true;
|
|
567
|
-
// expect(ipv4Tester('255.255.255.0.5')).to.be.false;
|
|
568
|
-
// });
|
|
569
|
-
// });
|
|
570
|
-
//
|
|
571
|
-
// describe('ipv6Tester()', () => {
|
|
572
|
-
// it('common test', () => {
|
|
573
|
-
// expect(commonTestRunner(
|
|
574
|
-
// ipv6Tester,
|
|
575
|
-
// false,
|
|
576
|
-
// false,
|
|
577
|
-
// false,
|
|
578
|
-
// false,
|
|
579
|
-
// false,
|
|
580
|
-
// false,
|
|
581
|
-
// false
|
|
582
|
-
// )).to.be.true;
|
|
583
|
-
// });
|
|
584
|
-
//
|
|
585
|
-
// it('logic test', () => {
|
|
586
|
-
// expect(ipv6Tester('')).to.be.false;
|
|
587
|
-
// expect(ipv6Tester(' ')).to.be.false;
|
|
588
|
-
// expect(ipv6Tester('127.0.0')).to.be.false;
|
|
589
|
-
// // expect(ipv6Tester('1762:0:0:0:0:B03:1:AF18')).to.be.true;
|
|
590
|
-
// // expect(ipv6Tester('fe80:0000:0000:0000:0204:61ff:fe9d:f156/1')).to.be.true;
|
|
591
|
-
// expect(ipv6Tester('1200:0000:AB00:1234:O000:2552:7777:1313')).to.be.false; // has invalid character
|
|
592
|
-
// });
|
|
593
|
-
// });
|
|
594
|
-
|
|
595
|
-
describe('object', () => {
|
|
596
|
-
describe('objectTester()', () => {
|
|
597
|
-
it('common test', () => {
|
|
598
|
-
expect(commonTestRunner(
|
|
599
|
-
objectTester,
|
|
600
|
-
true, // null is object
|
|
601
|
-
false,
|
|
602
|
-
false,
|
|
603
|
-
false,
|
|
604
|
-
false,
|
|
605
|
-
true, // array is object
|
|
606
|
-
true
|
|
607
|
-
)).to.be.true;
|
|
608
|
-
});
|
|
609
|
-
|
|
610
|
-
it('logic test', () => {
|
|
611
|
-
expect(objectTester(null)).to.be.true;
|
|
612
|
-
expect(objectTester({})).to.be.true;
|
|
613
|
-
expect(objectTester({ a: 1 })).to.be.true;
|
|
614
|
-
});
|
|
615
|
-
});
|
|
616
|
-
|
|
617
|
-
describe('hasPropertyTester()', () => {
|
|
618
|
-
it('logic test', () => {
|
|
619
|
-
expect(hasPropertyTester({})).to.be.false;
|
|
620
|
-
expect(hasPropertyTester({ a: 1 })).to.be.true;
|
|
621
|
-
});
|
|
622
|
-
});
|
|
623
|
-
});
|
|
624
|
-
|
|
625
|
-
describe('date', () => {
|
|
626
|
-
const now: Date = new Date();
|
|
627
|
-
|
|
628
|
-
const year: number = now.getFullYear();
|
|
629
|
-
const month: number = now.getMonth();
|
|
630
|
-
const date: number = now.getDate();
|
|
631
|
-
|
|
632
|
-
const hours: number = now.getHours();
|
|
633
|
-
const minutes: number = now.getMinutes();
|
|
634
|
-
const seconds: number = now.getSeconds();
|
|
635
|
-
const ms: number = now.getMilliseconds();
|
|
636
|
-
|
|
637
|
-
describe('dateTester()', () => {
|
|
638
|
-
it('common test', () => {
|
|
639
|
-
expect(commonTestRunner(
|
|
640
|
-
dateTester,
|
|
641
|
-
false,
|
|
642
|
-
false,
|
|
643
|
-
false,
|
|
644
|
-
false,
|
|
645
|
-
false,
|
|
646
|
-
false,
|
|
647
|
-
false
|
|
648
|
-
)).to.be.true;
|
|
649
|
-
});
|
|
650
|
-
|
|
651
|
-
it('logic test', () => {
|
|
652
|
-
expect(dateTester(new Date)).to.be.true;
|
|
653
|
-
expect(dateTester((new Date).toISOString())).to.be.false;
|
|
654
|
-
});
|
|
655
|
-
});
|
|
656
|
-
|
|
657
|
-
it('minDateTester()', () => {
|
|
658
|
-
expect(minDateTester(
|
|
659
|
-
new Date(year, month, date),
|
|
660
|
-
new Date(year, month, date - 1)
|
|
661
|
-
)).to.be.true;
|
|
662
|
-
expect(minDateTester(
|
|
663
|
-
new Date(year, month, date),
|
|
664
|
-
new Date(year, month, date)
|
|
665
|
-
)).to.be.true;
|
|
666
|
-
expect(minDateTester(
|
|
667
|
-
new Date(year, month, date),
|
|
668
|
-
new Date(year, month, date + 1)
|
|
669
|
-
)).to.be.false;
|
|
670
|
-
|
|
671
|
-
expect(minDateTester(
|
|
672
|
-
new Date(year, month, date, hours, minutes, seconds, ms),
|
|
673
|
-
new Date(year, month, date, hours, minutes, seconds, ms - 1)
|
|
674
|
-
)).to.be.true;
|
|
675
|
-
expect(minDateTester(
|
|
676
|
-
new Date(year, month, date, hours, minutes, seconds, ms),
|
|
677
|
-
new Date(year, month, date, hours, minutes, seconds, ms)
|
|
678
|
-
)).to.be.true;
|
|
679
|
-
expect(minDateTester(
|
|
680
|
-
new Date(year, month, date, hours, minutes, seconds, ms),
|
|
681
|
-
new Date(year, month, date, hours, minutes, seconds, ms + 1)
|
|
682
|
-
)).to.be.false;
|
|
683
|
-
});
|
|
684
|
-
|
|
685
|
-
it('exclusiveMinDateTester()', () => {
|
|
686
|
-
expect(exclusiveMinDateTester(
|
|
687
|
-
new Date(year, month, date),
|
|
688
|
-
new Date(year, month, date - 1)
|
|
689
|
-
)).to.be.true;
|
|
690
|
-
expect(exclusiveMinDateTester(
|
|
691
|
-
new Date(year, month, date),
|
|
692
|
-
new Date(year, month, date)
|
|
693
|
-
)).to.be.false;
|
|
694
|
-
expect(exclusiveMinDateTester(
|
|
695
|
-
new Date(year, month, date),
|
|
696
|
-
new Date(year, month, date + 1)
|
|
697
|
-
)).to.be.false;
|
|
698
|
-
|
|
699
|
-
expect(exclusiveMinDateTester(
|
|
700
|
-
new Date(year, month, date, hours, minutes, seconds, ms),
|
|
701
|
-
new Date(year, month, date, hours, minutes, seconds, ms - 1)
|
|
702
|
-
)).to.be.true;
|
|
703
|
-
expect(exclusiveMinDateTester(
|
|
704
|
-
new Date(year, month, date, hours, minutes, seconds, ms),
|
|
705
|
-
new Date(year, month, date, hours, minutes, seconds, ms)
|
|
706
|
-
)).to.be.false;
|
|
707
|
-
expect(exclusiveMinDateTester(
|
|
708
|
-
new Date(year, month, date, hours, minutes, seconds, ms),
|
|
709
|
-
new Date(year, month, date, hours, minutes, seconds, ms + 1)
|
|
710
|
-
)).to.be.false;
|
|
711
|
-
});
|
|
712
|
-
|
|
713
|
-
it('maxDateTester()', () => {
|
|
714
|
-
expect(maxDateTester(
|
|
715
|
-
new Date(year, month, date),
|
|
716
|
-
new Date(year, month, date - 1)
|
|
717
|
-
)).to.be.false;
|
|
718
|
-
expect(maxDateTester(
|
|
719
|
-
new Date(year, month, date),
|
|
720
|
-
new Date(year, month, date)
|
|
721
|
-
)).to.be.true;
|
|
722
|
-
expect(maxDateTester(
|
|
723
|
-
new Date(year, month, date),
|
|
724
|
-
new Date(year, month, date + 1)
|
|
725
|
-
)).to.be.true;
|
|
726
|
-
|
|
727
|
-
expect(maxDateTester(
|
|
728
|
-
new Date(year, month, date, hours, minutes, seconds, ms),
|
|
729
|
-
new Date(year, month, date, hours, minutes, seconds, ms - 1)
|
|
730
|
-
)).to.be.false;
|
|
731
|
-
expect(maxDateTester(
|
|
732
|
-
new Date(year, month, date, hours, minutes, seconds, ms),
|
|
733
|
-
new Date(year, month, date, hours, minutes, seconds, ms)
|
|
734
|
-
)).to.be.true;
|
|
735
|
-
expect(maxDateTester(
|
|
736
|
-
new Date(year, month, date, hours, minutes, seconds, ms),
|
|
737
|
-
new Date(year, month, date, hours, minutes, seconds, ms + 1)
|
|
738
|
-
)).to.be.true;
|
|
739
|
-
});
|
|
740
|
-
|
|
741
|
-
it('exclusiveMaxDateTester()', () => {
|
|
742
|
-
expect(exclusiveMaxDateTester(
|
|
743
|
-
new Date(year, month, date),
|
|
744
|
-
new Date(year, month, date - 1)
|
|
745
|
-
)).to.be.false;
|
|
746
|
-
expect(exclusiveMaxDateTester(
|
|
747
|
-
new Date(year, month, date),
|
|
748
|
-
new Date(year, month, date)
|
|
749
|
-
)).to.be.false;
|
|
750
|
-
expect(exclusiveMaxDateTester(
|
|
751
|
-
new Date(year, month, date),
|
|
752
|
-
new Date(year, month, date + 1)
|
|
753
|
-
)).to.be.true;
|
|
754
|
-
|
|
755
|
-
expect(exclusiveMaxDateTester(
|
|
756
|
-
new Date(year, month, date, hours, minutes, seconds, ms),
|
|
757
|
-
new Date(year, month, date, hours, minutes, seconds, ms - 1)
|
|
758
|
-
)).to.be.false;
|
|
759
|
-
expect(exclusiveMaxDateTester(
|
|
760
|
-
new Date(year, month, date, hours, minutes, seconds, ms),
|
|
761
|
-
new Date(year, month, date, hours, minutes, seconds, ms)
|
|
762
|
-
)).to.be.false;
|
|
763
|
-
expect(exclusiveMaxDateTester(
|
|
764
|
-
new Date(year, month, date, hours, minutes, seconds, ms),
|
|
765
|
-
new Date(year, month, date, hours, minutes, seconds, ms + 1)
|
|
766
|
-
)).to.be.true;
|
|
767
|
-
});
|
|
768
|
-
});
|
|
769
|
-
|
|
770
|
-
describe('array', () => {
|
|
771
|
-
describe('arrayTester()', () => {
|
|
772
|
-
it('common test', () => {
|
|
773
|
-
expect(commonTestRunner(
|
|
774
|
-
arrayTester,
|
|
775
|
-
false,
|
|
776
|
-
false,
|
|
777
|
-
false,
|
|
778
|
-
false,
|
|
779
|
-
false,
|
|
780
|
-
true,
|
|
781
|
-
false
|
|
782
|
-
)).to.be.true;
|
|
783
|
-
});
|
|
784
|
-
|
|
785
|
-
it('logic test', () => {
|
|
786
|
-
expect(arrayTester([])).to.be.true;
|
|
787
|
-
expect(arrayTester('not_array')).to.be.false;
|
|
788
|
-
});
|
|
789
|
-
});
|
|
790
|
-
|
|
791
|
-
describe('arrayTypeOfTester()', () => {
|
|
792
|
-
it('logic test', () => {
|
|
793
|
-
expect(arrayTypeOfTester([], DATA_TYPE.NUMBER)).to.be.true;
|
|
794
|
-
expect(arrayTypeOfTester([1, 2], DATA_TYPE.NUMBER)).to.be.true;
|
|
795
|
-
expect(arrayTypeOfTester([1, 2, '3'], DATA_TYPE.NUMBER)).to.be.false;
|
|
796
|
-
|
|
797
|
-
expect(arrayTypeOfTester([new Date(), new Date(), new Date()], DATA_TYPE.DATE)).to.be.true;
|
|
798
|
-
});
|
|
799
|
-
});
|
|
800
|
-
|
|
801
|
-
describe('uniqueItemsTester()', () => {
|
|
802
|
-
it('logic test', () => {
|
|
803
|
-
expect(uniqueItemsTester([])).to.be.true;
|
|
804
|
-
expect(uniqueItemsTester([1, 2])).to.be.true;
|
|
805
|
-
expect(uniqueItemsTester([1, 2, 2])).to.be.false;
|
|
806
|
-
});
|
|
807
|
-
});
|
|
808
|
-
});
|
|
809
|
-
|
|
810
|
-
describe('regexp', () => {
|
|
811
|
-
describe('regExpTester()', () => {
|
|
812
|
-
it('common test', () => {
|
|
813
|
-
expect(commonTestRunner(
|
|
814
|
-
regExpTester,
|
|
815
|
-
false,
|
|
816
|
-
false,
|
|
817
|
-
false,
|
|
818
|
-
false,
|
|
819
|
-
false,
|
|
820
|
-
false,
|
|
821
|
-
false
|
|
822
|
-
)).to.be.true;
|
|
823
|
-
});
|
|
824
|
-
|
|
825
|
-
it('logic test', () => {
|
|
826
|
-
expect(regExpTester(/\d/)).to.be.true;
|
|
827
|
-
expect(regExpTester(new RegExp('d'))).to.be.true;
|
|
828
|
-
|
|
829
|
-
expect(regExpTester('d')).to.be.false;
|
|
830
|
-
});
|
|
831
|
-
});
|
|
832
|
-
});
|
|
833
|
-
});
|
|
1
|
+
import { describe, it } from 'mocha';
|
|
2
|
+
import { expect } from 'chai';
|
|
3
|
+
|
|
4
|
+
import { commonTestRunner } from './common-test-util';
|
|
5
|
+
|
|
6
|
+
import {
|
|
7
|
+
arrayTester,
|
|
8
|
+
arrayTypeOfTester,
|
|
9
|
+
booleanTester,
|
|
10
|
+
dateFormatTester,
|
|
11
|
+
dateTester,
|
|
12
|
+
dateTimeFormatTester,
|
|
13
|
+
definedTester,
|
|
14
|
+
emailTester,
|
|
15
|
+
enumTester,
|
|
16
|
+
exclusiveMaxDateTester,
|
|
17
|
+
exclusiveMaxNumberTester,
|
|
18
|
+
exclusiveMinDateTester,
|
|
19
|
+
exclusiveMinNumberTester,
|
|
20
|
+
hasPropertyTester,
|
|
21
|
+
indexTester,
|
|
22
|
+
integerTester,
|
|
23
|
+
lengthTester,
|
|
24
|
+
maxDateTester,
|
|
25
|
+
maxLengthTester,
|
|
26
|
+
maxNumberTester,
|
|
27
|
+
minDateTester,
|
|
28
|
+
minLengthTester,
|
|
29
|
+
minNumberTester,
|
|
30
|
+
numberTester,
|
|
31
|
+
objectTester,
|
|
32
|
+
regExpTester,
|
|
33
|
+
stringRegExpTester,
|
|
34
|
+
stringTester,
|
|
35
|
+
timeFormatTester,
|
|
36
|
+
uniqueItemsTester
|
|
37
|
+
} from '../src/tester';
|
|
38
|
+
import { DATA_TYPE } from '../src/constants';
|
|
39
|
+
|
|
40
|
+
describe('testers', function () {
|
|
41
|
+
describe('common', () => {
|
|
42
|
+
describe('definedTester()', () => {
|
|
43
|
+
it('common test', () => {
|
|
44
|
+
expect(commonTestRunner(
|
|
45
|
+
definedTester,
|
|
46
|
+
true,
|
|
47
|
+
false,
|
|
48
|
+
true,
|
|
49
|
+
true,
|
|
50
|
+
true,
|
|
51
|
+
true,
|
|
52
|
+
true
|
|
53
|
+
)).to.be.true;
|
|
54
|
+
});
|
|
55
|
+
});
|
|
56
|
+
|
|
57
|
+
describe('enumTester()', () => {
|
|
58
|
+
it('logic test', () => {
|
|
59
|
+
expect(enumTester('a', ['a', 'b', 'c'])).to.be.true;
|
|
60
|
+
expect(enumTester('a', ['b', 'c'])).to.be.false;
|
|
61
|
+
|
|
62
|
+
expect(enumTester(1, [1, 2, 3])).to.be.true;
|
|
63
|
+
expect(enumTester(1, [2, 3])).to.be.false;
|
|
64
|
+
});
|
|
65
|
+
});
|
|
66
|
+
|
|
67
|
+
describe('lengthTester()', () => {
|
|
68
|
+
it('logic test', () => {
|
|
69
|
+
expect(lengthTester('abcd', 3)).to.be.false;
|
|
70
|
+
expect(lengthTester('abcd', 4)).to.be.true;
|
|
71
|
+
expect(lengthTester('abcd', 5)).to.be.false;
|
|
72
|
+
|
|
73
|
+
expect(lengthTester([1, 2, 3, 4], 3)).to.be.false;
|
|
74
|
+
expect(lengthTester([1, 2, 3, 4], 4)).to.be.true;
|
|
75
|
+
expect(lengthTester([1, 2, 3, 4], 5)).to.be.false;
|
|
76
|
+
});
|
|
77
|
+
});
|
|
78
|
+
|
|
79
|
+
describe('minLengthTester()', () => {
|
|
80
|
+
it('logic test', () => {
|
|
81
|
+
expect(minLengthTester('abcd', 3)).to.be.true;
|
|
82
|
+
expect(minLengthTester('abcd', 4)).to.be.true;
|
|
83
|
+
expect(minLengthTester('abcd', 5)).to.be.false;
|
|
84
|
+
|
|
85
|
+
expect(minLengthTester([1, 2, 3, 4], 3)).to.be.true;
|
|
86
|
+
expect(minLengthTester([1, 2, 3, 4], 4)).to.be.true;
|
|
87
|
+
expect(minLengthTester([1, 2, 3, 4], 5)).to.be.false;
|
|
88
|
+
});
|
|
89
|
+
});
|
|
90
|
+
|
|
91
|
+
describe('maxLengthTester()', () => {
|
|
92
|
+
it('logic test', () => {
|
|
93
|
+
expect(maxLengthTester('abcd', 3)).to.be.false;
|
|
94
|
+
expect(maxLengthTester('abcd', 4)).to.be.true;
|
|
95
|
+
expect(maxLengthTester('abcd', 5)).to.be.true;
|
|
96
|
+
|
|
97
|
+
expect(maxLengthTester([1, 2, 3, 4], 3)).to.be.false;
|
|
98
|
+
expect(maxLengthTester([1, 2, 3, 4], 4)).to.be.true;
|
|
99
|
+
expect(maxLengthTester([1, 2, 3, 4], 5)).to.be.true;
|
|
100
|
+
});
|
|
101
|
+
});
|
|
102
|
+
});
|
|
103
|
+
|
|
104
|
+
describe('boolean', () => {
|
|
105
|
+
describe('booleanTester()', () => {
|
|
106
|
+
it('common test', () => {
|
|
107
|
+
expect(commonTestRunner(
|
|
108
|
+
booleanTester,
|
|
109
|
+
false,
|
|
110
|
+
false,
|
|
111
|
+
true,
|
|
112
|
+
false,
|
|
113
|
+
false,
|
|
114
|
+
false,
|
|
115
|
+
false
|
|
116
|
+
)).to.be.true;
|
|
117
|
+
});
|
|
118
|
+
|
|
119
|
+
it('logic test', () => {
|
|
120
|
+
expect(booleanTester(true)).to.be.true;
|
|
121
|
+
expect(booleanTester(false)).to.be.true;
|
|
122
|
+
|
|
123
|
+
expect(booleanTester('true')).to.be.false;
|
|
124
|
+
expect(booleanTester('false')).to.be.false;
|
|
125
|
+
|
|
126
|
+
expect(booleanTester(1)).to.be.false;
|
|
127
|
+
expect(booleanTester(0)).to.be.false;
|
|
128
|
+
});
|
|
129
|
+
});
|
|
130
|
+
});
|
|
131
|
+
|
|
132
|
+
describe('number', () => {
|
|
133
|
+
describe('numberTester()', () => {
|
|
134
|
+
it('common test', () => {
|
|
135
|
+
expect(commonTestRunner(
|
|
136
|
+
numberTester,
|
|
137
|
+
false,
|
|
138
|
+
false,
|
|
139
|
+
false,
|
|
140
|
+
true,
|
|
141
|
+
false,
|
|
142
|
+
false,
|
|
143
|
+
false
|
|
144
|
+
)).to.be.true;
|
|
145
|
+
});
|
|
146
|
+
|
|
147
|
+
it('logic test', () => {
|
|
148
|
+
expect(numberTester(true)).to.be.false;
|
|
149
|
+
expect(numberTester(null)).to.be.false;
|
|
150
|
+
|
|
151
|
+
expect(numberTester(-10.6)).to.be.true;
|
|
152
|
+
expect(numberTester(-1)).to.be.true;
|
|
153
|
+
expect(numberTester(0)).to.be.true;
|
|
154
|
+
expect(numberTester(5)).to.be.true;
|
|
155
|
+
expect(numberTester(5.5)).to.be.true;
|
|
156
|
+
|
|
157
|
+
expect(numberTester('8')).to.be.false;
|
|
158
|
+
expect(numberTester('8.5')).to.be.false;
|
|
159
|
+
|
|
160
|
+
expect(numberTester(NaN)).to.be.false;
|
|
161
|
+
});
|
|
162
|
+
});
|
|
163
|
+
|
|
164
|
+
describe('integerTester()', () => {
|
|
165
|
+
it('logic test', () => {
|
|
166
|
+
expect(integerTester(-10.6)).to.be.false;
|
|
167
|
+
expect(integerTester(-1)).to.be.true;
|
|
168
|
+
expect(integerTester(0)).to.be.true;
|
|
169
|
+
expect(integerTester(5)).to.be.true;
|
|
170
|
+
expect(integerTester(5.5)).to.be.false;
|
|
171
|
+
});
|
|
172
|
+
});
|
|
173
|
+
|
|
174
|
+
describe('indexTester()', () => {
|
|
175
|
+
it('logic test', () => {
|
|
176
|
+
expect(indexTester(-10.6)).to.be.false;
|
|
177
|
+
expect(indexTester(-1)).to.be.false;
|
|
178
|
+
expect(indexTester(0)).to.be.true;
|
|
179
|
+
expect(indexTester(5)).to.be.true;
|
|
180
|
+
expect(indexTester(5.5)).to.be.false;
|
|
181
|
+
});
|
|
182
|
+
});
|
|
183
|
+
|
|
184
|
+
describe('minNumberTester()', () => {
|
|
185
|
+
it('logic test', () => {
|
|
186
|
+
expect(minNumberTester(-11, -12)).to.be.true;
|
|
187
|
+
expect(minNumberTester(-11, -11)).to.be.true;
|
|
188
|
+
expect(minNumberTester(-11, -10)).to.be.false;
|
|
189
|
+
|
|
190
|
+
expect(minNumberTester(0, -1)).to.be.true;
|
|
191
|
+
expect(minNumberTester(0, 0)).to.be.true;
|
|
192
|
+
expect(minNumberTester(0, 1)).to.be.false;
|
|
193
|
+
|
|
194
|
+
expect(minNumberTester(50, 49.9)).to.be.true;
|
|
195
|
+
expect(minNumberTester(50, 50)).to.be.true;
|
|
196
|
+
expect(minNumberTester(50, 50.1)).to.be.false;
|
|
197
|
+
});
|
|
198
|
+
});
|
|
199
|
+
|
|
200
|
+
describe('exclusiveMinNumberTester()', () => {
|
|
201
|
+
it('logic test', () => {
|
|
202
|
+
expect(exclusiveMinNumberTester(-11, -12)).to.be.true;
|
|
203
|
+
expect(exclusiveMinNumberTester(-11, -11)).to.be.false;
|
|
204
|
+
expect(exclusiveMinNumberTester(-11, -10)).to.be.false;
|
|
205
|
+
|
|
206
|
+
expect(exclusiveMinNumberTester(0, -1)).to.be.true;
|
|
207
|
+
expect(exclusiveMinNumberTester(0, 0)).to.be.false;
|
|
208
|
+
expect(exclusiveMinNumberTester(0, 1)).to.be.false;
|
|
209
|
+
|
|
210
|
+
expect(exclusiveMinNumberTester(50, 49.9)).to.be.true;
|
|
211
|
+
expect(exclusiveMinNumberTester(50, 50)).to.be.false;
|
|
212
|
+
expect(exclusiveMinNumberTester(50, 50.1)).to.be.false;
|
|
213
|
+
});
|
|
214
|
+
});
|
|
215
|
+
|
|
216
|
+
describe('maxNumberTester()', () => {
|
|
217
|
+
it('logic test', () => {
|
|
218
|
+
expect(maxNumberTester(-11, -12)).to.be.false;
|
|
219
|
+
expect(maxNumberTester(-11, -11)).to.be.true;
|
|
220
|
+
expect(maxNumberTester(-11, -10)).to.be.true;
|
|
221
|
+
|
|
222
|
+
expect(maxNumberTester(0, -1)).to.be.false;
|
|
223
|
+
expect(maxNumberTester(0, 0)).to.be.true;
|
|
224
|
+
expect(maxNumberTester(0, 1)).to.be.true;
|
|
225
|
+
|
|
226
|
+
expect(maxNumberTester(50, 49.9)).to.be.false;
|
|
227
|
+
expect(maxNumberTester(50, 50)).to.be.true;
|
|
228
|
+
expect(maxNumberTester(50, 50.1)).to.be.true;
|
|
229
|
+
});
|
|
230
|
+
});
|
|
231
|
+
|
|
232
|
+
describe('exclusiveMaxNumberTester()', () => {
|
|
233
|
+
it('logic test', () => {
|
|
234
|
+
expect(exclusiveMaxNumberTester(-11, -12)).to.be.false;
|
|
235
|
+
expect(exclusiveMaxNumberTester(-11, -11)).to.be.false;
|
|
236
|
+
expect(exclusiveMaxNumberTester(-11, -10)).to.be.true;
|
|
237
|
+
|
|
238
|
+
expect(exclusiveMaxNumberTester(0, -1)).to.be.false;
|
|
239
|
+
expect(exclusiveMaxNumberTester(0, 0)).to.be.false;
|
|
240
|
+
expect(exclusiveMaxNumberTester(0, 1)).to.be.true;
|
|
241
|
+
|
|
242
|
+
expect(exclusiveMaxNumberTester(50, 49.9)).to.be.false;
|
|
243
|
+
expect(exclusiveMaxNumberTester(50, 50)).to.be.false;
|
|
244
|
+
expect(exclusiveMaxNumberTester(50, 50.1)).to.be.true;
|
|
245
|
+
});
|
|
246
|
+
});
|
|
247
|
+
});
|
|
248
|
+
|
|
249
|
+
describe('string', () => {
|
|
250
|
+
describe('stringTester()', () => {
|
|
251
|
+
it('common test', () => {
|
|
252
|
+
expect(commonTestRunner(
|
|
253
|
+
stringTester,
|
|
254
|
+
false,
|
|
255
|
+
false,
|
|
256
|
+
false,
|
|
257
|
+
false,
|
|
258
|
+
true,
|
|
259
|
+
false,
|
|
260
|
+
false
|
|
261
|
+
)).to.be.true;
|
|
262
|
+
});
|
|
263
|
+
|
|
264
|
+
it('logic test', () => {
|
|
265
|
+
expect(stringTester('')).to.be.true;
|
|
266
|
+
expect(stringTester(' ')).to.be.true;
|
|
267
|
+
expect(stringTester('hello')).to.be.true;
|
|
268
|
+
});
|
|
269
|
+
});
|
|
270
|
+
|
|
271
|
+
describe('stringRegExpTester()', () => {
|
|
272
|
+
it('logic test', () => {
|
|
273
|
+
expect(stringRegExpTester('abc', /abc/)).to.be.true;
|
|
274
|
+
expect(stringRegExpTester('abc', /abcd/)).to.be.false;
|
|
275
|
+
|
|
276
|
+
expect(stringRegExpTester('abc', new RegExp('abc'))).to.be.true;
|
|
277
|
+
expect(stringRegExpTester('abc', new RegExp('abcd'))).to.be.false;
|
|
278
|
+
});
|
|
279
|
+
});
|
|
280
|
+
|
|
281
|
+
describe('emailTester()', () => {
|
|
282
|
+
it('logic test', () => {
|
|
283
|
+
expect(emailTester('')).to.be.false;
|
|
284
|
+
expect(emailTester(' ')).to.be.false;
|
|
285
|
+
expect(emailTester('hello')).to.be.false;
|
|
286
|
+
expect(emailTester('hello@')).to.be.false;
|
|
287
|
+
expect(emailTester('hello@domain')).to.be.true;
|
|
288
|
+
expect(emailTester('hello@domain.')).to.be.false;
|
|
289
|
+
expect(emailTester('hello@domain.com')).to.be.true;
|
|
290
|
+
expect(emailTester('hello@domain.com.')).to.be.false;
|
|
291
|
+
expect(emailTester('hello@domain.com.another')).to.be.true;
|
|
292
|
+
|
|
293
|
+
expect(emailTester('prettyandsimple@example.com')).to.be.true;
|
|
294
|
+
expect(emailTester('very.common@example.com')).to.be.true;
|
|
295
|
+
expect(emailTester('disposable.style.email.with+symbol@example.com')).to.be.true;
|
|
296
|
+
expect(emailTester('other.email-with-dash@example.com')).to.be.true;
|
|
297
|
+
expect(emailTester('x@example.com')).to.be.true;
|
|
298
|
+
expect(emailTester('"much.more unusual"@example.com')).to.be.true;
|
|
299
|
+
expect(emailTester('"very.unusual.@.unusual.com"@example.com')).to.be.true;
|
|
300
|
+
expect(emailTester('example-indeed@strange-example.com')).to.be.true;
|
|
301
|
+
expect(emailTester('admin@mailserver1')).to.be.true;
|
|
302
|
+
expect(emailTester('#!$%&\'*+-/=?^_`{}|~@example.org')).to.be.true;
|
|
303
|
+
expect(emailTester('"()<>[]:,;@\\\\\\"!#$%&\'-/=?^_`{}| ~.a"@example.org')).to.be.true;
|
|
304
|
+
expect(emailTester('" "@example.org')).to.be.true;
|
|
305
|
+
expect(emailTester('example@localhost')).to.be.true;
|
|
306
|
+
expect(emailTester('example@s.solutions')).to.be.true;
|
|
307
|
+
expect(emailTester('user@localserver')).to.be.true;
|
|
308
|
+
expect(emailTester('user@tt')).to.be.true;
|
|
309
|
+
expect(emailTester('user@[IPv6:2001:DB8::1]')).to.be.true;
|
|
310
|
+
|
|
311
|
+
expect(emailTester('Abc.example.com')).to.be.false;
|
|
312
|
+
expect(emailTester('A@b@c@example.com')).to.be.false;
|
|
313
|
+
expect(emailTester('"A@b@c"@example.com')).to.be.true;
|
|
314
|
+
|
|
315
|
+
expect(emailTester('a"b(c)d,e:f;g<h>i[j\\k]l@example.com')).to.be.false;
|
|
316
|
+
expect(emailTester('just"not"right@example.com')).to.be.false;
|
|
317
|
+
expect(emailTester('this is"notallowed@example.com')).to.be.false;
|
|
318
|
+
expect(emailTester('this still"not\\allowed@example.com')).to.be.false;
|
|
319
|
+
expect(emailTester('1234567890123456789012345678901234567890123456789012345678901234+x@example.com')).to.be.false;
|
|
320
|
+
expect(emailTester('john..doe@example.com')).to.be.false;
|
|
321
|
+
expect(emailTester('john.doe@example..com')).to.be.false;
|
|
322
|
+
|
|
323
|
+
expect(emailTester(' ejv@ejv.com')).to.be.false;
|
|
324
|
+
expect(emailTester('ejv@ejv.com ')).to.be.false;
|
|
325
|
+
});
|
|
326
|
+
});
|
|
327
|
+
|
|
328
|
+
describe('dateFormatTester()', () => {
|
|
329
|
+
it('logic test', () => {
|
|
330
|
+
//// ISO 8601
|
|
331
|
+
// year
|
|
332
|
+
expect(dateFormatTester('100')).to.be.false;
|
|
333
|
+
expect(dateFormatTester('1000')).to.be.true;
|
|
334
|
+
expect(dateFormatTester('+2000')).to.be.true;
|
|
335
|
+
expect(dateFormatTester('-2000')).to.be.true;
|
|
336
|
+
|
|
337
|
+
// calendar date
|
|
338
|
+
expect(dateFormatTester('2018-1-17')).to.be.false;
|
|
339
|
+
expect(dateFormatTester('2018-12-32')).to.be.false;
|
|
340
|
+
expect(dateFormatTester('2018-12-17')).to.be.true;
|
|
341
|
+
expect(dateFormatTester('2018-13-17')).to.be.false;
|
|
342
|
+
expect(dateFormatTester('2018-12-7')).to.be.false;
|
|
343
|
+
|
|
344
|
+
// expect(dateFormatTester('2018117')).to.be.false; // matching for ordinal dates
|
|
345
|
+
expect(dateFormatTester('20181217')).to.be.true;
|
|
346
|
+
expect(dateFormatTester('20181317')).to.be.false;
|
|
347
|
+
expect(dateFormatTester('20181232')).to.be.false;
|
|
348
|
+
|
|
349
|
+
expect(dateFormatTester('2018-1')).to.be.false;
|
|
350
|
+
expect(dateFormatTester('2018-12')).to.be.true;
|
|
351
|
+
expect(dateFormatTester('2018-13')).to.be.false;
|
|
352
|
+
|
|
353
|
+
expect(dateFormatTester('--1-17')).to.be.false;
|
|
354
|
+
expect(dateFormatTester('--12-1')).to.be.false;
|
|
355
|
+
expect(dateFormatTester('--12-17')).to.be.true;
|
|
356
|
+
expect(dateFormatTester('--13-17')).to.be.false;
|
|
357
|
+
expect(dateFormatTester('--12-32')).to.be.false;
|
|
358
|
+
|
|
359
|
+
expect(dateFormatTester('--117')).to.be.false;
|
|
360
|
+
expect(dateFormatTester('--1317')).to.be.false;
|
|
361
|
+
expect(dateFormatTester('--1232')).to.be.false;
|
|
362
|
+
expect(dateFormatTester('--1217')).to.be.true;
|
|
363
|
+
|
|
364
|
+
// week dates
|
|
365
|
+
expect(dateFormatTester('2018-W01')).to.be.true;
|
|
366
|
+
expect(dateFormatTester('2018-W53')).to.be.true;
|
|
367
|
+
|
|
368
|
+
expect(dateFormatTester('2018-W00')).to.be.false;
|
|
369
|
+
expect(dateFormatTester('2018-W54')).to.be.false;
|
|
370
|
+
|
|
371
|
+
expect(dateFormatTester('2018-W01-3')).to.be.true;
|
|
372
|
+
expect(dateFormatTester('2018-W53-7')).to.be.true;
|
|
373
|
+
|
|
374
|
+
expect(dateFormatTester('2018-W01-0')).to.be.false;
|
|
375
|
+
expect(dateFormatTester('2018-W53-8')).to.be.false;
|
|
376
|
+
|
|
377
|
+
expect(dateFormatTester('2018W01')).to.be.true;
|
|
378
|
+
expect(dateFormatTester('2018W53')).to.be.true;
|
|
379
|
+
|
|
380
|
+
expect(dateFormatTester('2018W00')).to.be.false;
|
|
381
|
+
expect(dateFormatTester('2018W54')).to.be.false;
|
|
382
|
+
|
|
383
|
+
expect(dateFormatTester('2018W010')).to.be.false;
|
|
384
|
+
expect(dateFormatTester('2018W538')).to.be.false;
|
|
385
|
+
|
|
386
|
+
// ordinal dates
|
|
387
|
+
expect(dateFormatTester('2018-052')).to.be.true;
|
|
388
|
+
|
|
389
|
+
expect(dateFormatTester('2018-000')).to.be.false;
|
|
390
|
+
expect(dateFormatTester('2018-367')).to.be.false;
|
|
391
|
+
|
|
392
|
+
expect(dateFormatTester('2018052')).to.be.true;
|
|
393
|
+
|
|
394
|
+
expect(dateFormatTester('2018000')).to.be.false;
|
|
395
|
+
expect(dateFormatTester('2018367')).to.be.false;
|
|
396
|
+
});
|
|
397
|
+
});
|
|
398
|
+
|
|
399
|
+
describe('timeFormatTester()', () => {
|
|
400
|
+
it('logic test', () => {
|
|
401
|
+
// hh:mm:ss.sss, hh:mm:ss
|
|
402
|
+
expect(timeFormatTester('23:35:12.123')).to.be.true;
|
|
403
|
+
expect(timeFormatTester('24:00:00')).to.be.true;
|
|
404
|
+
expect(timeFormatTester('24:00:00.000')).to.be.true;
|
|
405
|
+
|
|
406
|
+
expect(timeFormatTester('3:35:12.123')).to.be.false;
|
|
407
|
+
expect(timeFormatTester('24:35:12.123')).to.be.false;
|
|
408
|
+
expect(timeFormatTester('25:35:12.123')).to.be.false;
|
|
409
|
+
|
|
410
|
+
expect(timeFormatTester('23:0:12.123')).to.be.false;
|
|
411
|
+
expect(timeFormatTester('23:60:12.123')).to.be.false;
|
|
412
|
+
|
|
413
|
+
expect(timeFormatTester('23:35:2.123')).to.be.false;
|
|
414
|
+
expect(timeFormatTester('23:35:60.123')).to.be.true; // leap second
|
|
415
|
+
expect(timeFormatTester('23:35:61.123')).to.be.false;
|
|
416
|
+
|
|
417
|
+
expect(timeFormatTester('23:35:12')).to.be.true;
|
|
418
|
+
expect(timeFormatTester('23:35:12.1')).to.be.true;
|
|
419
|
+
expect(timeFormatTester('23:35:12.12')).to.be.true;
|
|
420
|
+
expect(timeFormatTester('23:35:12.123')).to.be.true;
|
|
421
|
+
expect(timeFormatTester('23:35:12.1234')).to.be.true;
|
|
422
|
+
expect(timeFormatTester('23:35:12.12356789')).to.be.true;
|
|
423
|
+
|
|
424
|
+
// hh:mm
|
|
425
|
+
expect(timeFormatTester('23:52')).to.be.true;
|
|
426
|
+
expect(timeFormatTester('24:00')).to.be.true;
|
|
427
|
+
|
|
428
|
+
expect(timeFormatTester('2:52')).to.be.false;
|
|
429
|
+
expect(timeFormatTester('24:52')).to.be.false;
|
|
430
|
+
|
|
431
|
+
expect(timeFormatTester('23:2')).to.be.false;
|
|
432
|
+
expect(timeFormatTester('23:60')).to.be.false;
|
|
433
|
+
|
|
434
|
+
// hhmmss.sss, hhmmss
|
|
435
|
+
expect(timeFormatTester('233512.123')).to.be.true;
|
|
436
|
+
expect(timeFormatTester('240000')).to.be.true;
|
|
437
|
+
expect(timeFormatTester('240000.000')).to.be.true;
|
|
438
|
+
|
|
439
|
+
expect(timeFormatTester('33512.123')).to.be.false;
|
|
440
|
+
expect(timeFormatTester('243512.123')).to.be.false;
|
|
441
|
+
expect(timeFormatTester('253512.123')).to.be.false;
|
|
442
|
+
|
|
443
|
+
expect(timeFormatTester('23012.123')).to.be.false;
|
|
444
|
+
expect(timeFormatTester('236012.123')).to.be.false;
|
|
445
|
+
|
|
446
|
+
expect(timeFormatTester('23352.123')).to.be.false;
|
|
447
|
+
expect(timeFormatTester('233560.123')).to.be.true; // leap second
|
|
448
|
+
expect(timeFormatTester('233561.123')).to.be.false;
|
|
449
|
+
|
|
450
|
+
expect(timeFormatTester('233512')).to.be.true;
|
|
451
|
+
expect(timeFormatTester('233512.1')).to.be.true;
|
|
452
|
+
expect(timeFormatTester('233512.12')).to.be.true;
|
|
453
|
+
expect(timeFormatTester('233512.123')).to.be.true;
|
|
454
|
+
expect(timeFormatTester('233512.1234')).to.be.true;
|
|
455
|
+
expect(timeFormatTester('233512.12356789')).to.be.true;
|
|
456
|
+
|
|
457
|
+
// hhmm
|
|
458
|
+
expect(timeFormatTester('2352')).to.be.true;
|
|
459
|
+
expect(timeFormatTester('2400')).to.be.true;
|
|
460
|
+
|
|
461
|
+
expect(timeFormatTester('252')).to.be.false;
|
|
462
|
+
expect(timeFormatTester('2452')).to.be.false;
|
|
463
|
+
|
|
464
|
+
expect(timeFormatTester('2360')).to.be.false;
|
|
465
|
+
|
|
466
|
+
// hh
|
|
467
|
+
expect(timeFormatTester('00')).to.be.true;
|
|
468
|
+
expect(timeFormatTester('05')).to.be.true;
|
|
469
|
+
expect(timeFormatTester('24')).to.be.true;
|
|
470
|
+
|
|
471
|
+
expect(timeFormatTester('25')).to.be.false;
|
|
472
|
+
});
|
|
473
|
+
});
|
|
474
|
+
|
|
475
|
+
describe('dateTimeFormatTester()', () => {
|
|
476
|
+
it('logic test', () => {
|
|
477
|
+
// RFC 3339
|
|
478
|
+
expect(dateTimeFormatTester('2018-12-16T05:04:05')).to.be.true;
|
|
479
|
+
expect(dateTimeFormatTester('2018-12-16T05:04:05.51')).to.be.true;
|
|
480
|
+
expect(dateTimeFormatTester('2018-12-16T05:04:05.51Z')).to.be.true;
|
|
481
|
+
expect(dateTimeFormatTester('2018-12-16T05:04:05+09:00')).to.be.true;
|
|
482
|
+
|
|
483
|
+
expect(dateTimeFormatTester('2018-12-16T03:34:21')).to.be.true;
|
|
484
|
+
expect(dateTimeFormatTester('2018-12-16T03:34:21Z')).to.be.true;
|
|
485
|
+
expect(dateTimeFormatTester('2018-12-16T03:34:21.000')).to.be.true;
|
|
486
|
+
expect(dateTimeFormatTester('2018-12-16T03:34:21.000Z')).to.be.true;
|
|
487
|
+
expect(dateTimeFormatTester('2018-12-16T03:34:21.000+09:00')).to.be.true;
|
|
488
|
+
expect(dateTimeFormatTester('2018-12-16T03:34:21.000-08:00')).to.be.true;
|
|
489
|
+
|
|
490
|
+
expect(dateTimeFormatTester('2018-00-16T03:34:21')).to.be.false;
|
|
491
|
+
expect(dateTimeFormatTester('2018-13-16T03:34:21')).to.be.false;
|
|
492
|
+
expect(dateTimeFormatTester('2018-1-16T03:34:21')).to.be.false;
|
|
493
|
+
expect(dateTimeFormatTester('2018-12-6T03:34:21')).to.be.false;
|
|
494
|
+
expect(dateTimeFormatTester('2018-12-32T03:34:21')).to.be.false;
|
|
495
|
+
expect(dateTimeFormatTester('2018-12-16T0:34:21')).to.be.false;
|
|
496
|
+
expect(dateTimeFormatTester('2018-12-16T24:34:21')).to.be.false;
|
|
497
|
+
expect(dateTimeFormatTester('2018-12-16T03:4:21')).to.be.false;
|
|
498
|
+
expect(dateTimeFormatTester('2018-12-16T03:60:21')).to.be.false;
|
|
499
|
+
expect(dateTimeFormatTester('2018-12-16T03:34:1')).to.be.false;
|
|
500
|
+
expect(dateTimeFormatTester('2018-12-16T03:34:60')).to.be.false;
|
|
501
|
+
expect(dateTimeFormatTester('2018-12-16T03:34:21.')).to.be.false;
|
|
502
|
+
|
|
503
|
+
// // leap second inserted
|
|
504
|
+
// expect(dateTimeFormatTester('1990-12-31T23:59:60Z')).to.be.true;
|
|
505
|
+
// expect(dateTimeFormatTester('1990-12-31T15:59:60-08:00')).to.be.true;
|
|
506
|
+
|
|
507
|
+
// ISO 8601
|
|
508
|
+
expect(dateTimeFormatTester('20181219T00:38:05Z')).to.be.true;
|
|
509
|
+
expect(dateTimeFormatTester('20181219T00:38:05+00:00')).to.be.true;
|
|
510
|
+
});
|
|
511
|
+
});
|
|
512
|
+
});
|
|
513
|
+
|
|
514
|
+
// describe('urlTester()', () => {
|
|
515
|
+
// it('common test', () => {
|
|
516
|
+
// expect(commonTestRunner(
|
|
517
|
+
// urlTester,
|
|
518
|
+
// false,
|
|
519
|
+
// false,
|
|
520
|
+
// false,
|
|
521
|
+
// false,
|
|
522
|
+
// false,
|
|
523
|
+
// false,
|
|
524
|
+
// false
|
|
525
|
+
// )).to.be.true;
|
|
526
|
+
// });
|
|
527
|
+
//
|
|
528
|
+
// it('logic test', () => {
|
|
529
|
+
// expect(urlTester('')).to.be.false;
|
|
530
|
+
// expect(urlTester(' ')).to.be.false;
|
|
531
|
+
// expect(urlTester('hello')).to.be.false;
|
|
532
|
+
// expect(urlTester('http://hello')).to.be.false;
|
|
533
|
+
// expect(urlTester('https://hello')).to.be.false;
|
|
534
|
+
// expect(urlTester('http://hello.com')).to.be.true;
|
|
535
|
+
// expect(urlTester('http://hello.com/')).to.be.true;
|
|
536
|
+
// expect(urlTester('http://hello.com/#1')).to.be.true;
|
|
537
|
+
// expect(urlTester('http://hello.com/child')).to.be.true;
|
|
538
|
+
// expect(urlTester('http://hello.com/child/grand')).to.be.true;
|
|
539
|
+
// expect(urlTester('http://hello.com/child/grand?query=some')).to.be.true;
|
|
540
|
+
// expect(urlTester('http://hello.com/child/grand(some:angular)')).to.be.true;
|
|
541
|
+
// });
|
|
542
|
+
// });
|
|
543
|
+
//
|
|
544
|
+
// describe('ipv4Tester()', () => {
|
|
545
|
+
// it('common test', () => {
|
|
546
|
+
// expect(commonTestRunner(
|
|
547
|
+
// ipv4Tester,
|
|
548
|
+
// false,
|
|
549
|
+
// false,
|
|
550
|
+
// false,
|
|
551
|
+
// false,
|
|
552
|
+
// false,
|
|
553
|
+
// false,
|
|
554
|
+
// false
|
|
555
|
+
// )).to.be.true;
|
|
556
|
+
// });
|
|
557
|
+
//
|
|
558
|
+
// it('logic test', () => {
|
|
559
|
+
// expect(ipv4Tester('')).to.be.false;
|
|
560
|
+
// expect(ipv4Tester(' ')).to.be.false;
|
|
561
|
+
// expect(ipv4Tester('127.0.0')).to.be.false;
|
|
562
|
+
// expect(ipv4Tester('127.0.0.1')).to.be.true;
|
|
563
|
+
// expect(ipv4Tester('256.0.0.1')).to.be.false;
|
|
564
|
+
// expect(ipv4Tester('255.-1.0.1')).to.be.false;
|
|
565
|
+
// expect(ipv4Tester('255.256.267.1')).to.be.false;
|
|
566
|
+
// expect(ipv4Tester('255.255.255.0')).to.be.true;
|
|
567
|
+
// expect(ipv4Tester('255.255.255.0.5')).to.be.false;
|
|
568
|
+
// });
|
|
569
|
+
// });
|
|
570
|
+
//
|
|
571
|
+
// describe('ipv6Tester()', () => {
|
|
572
|
+
// it('common test', () => {
|
|
573
|
+
// expect(commonTestRunner(
|
|
574
|
+
// ipv6Tester,
|
|
575
|
+
// false,
|
|
576
|
+
// false,
|
|
577
|
+
// false,
|
|
578
|
+
// false,
|
|
579
|
+
// false,
|
|
580
|
+
// false,
|
|
581
|
+
// false
|
|
582
|
+
// )).to.be.true;
|
|
583
|
+
// });
|
|
584
|
+
//
|
|
585
|
+
// it('logic test', () => {
|
|
586
|
+
// expect(ipv6Tester('')).to.be.false;
|
|
587
|
+
// expect(ipv6Tester(' ')).to.be.false;
|
|
588
|
+
// expect(ipv6Tester('127.0.0')).to.be.false;
|
|
589
|
+
// // expect(ipv6Tester('1762:0:0:0:0:B03:1:AF18')).to.be.true;
|
|
590
|
+
// // expect(ipv6Tester('fe80:0000:0000:0000:0204:61ff:fe9d:f156/1')).to.be.true;
|
|
591
|
+
// expect(ipv6Tester('1200:0000:AB00:1234:O000:2552:7777:1313')).to.be.false; // has invalid character
|
|
592
|
+
// });
|
|
593
|
+
// });
|
|
594
|
+
|
|
595
|
+
describe('object', () => {
|
|
596
|
+
describe('objectTester()', () => {
|
|
597
|
+
it('common test', () => {
|
|
598
|
+
expect(commonTestRunner(
|
|
599
|
+
objectTester,
|
|
600
|
+
true, // null is object
|
|
601
|
+
false,
|
|
602
|
+
false,
|
|
603
|
+
false,
|
|
604
|
+
false,
|
|
605
|
+
true, // array is object
|
|
606
|
+
true
|
|
607
|
+
)).to.be.true;
|
|
608
|
+
});
|
|
609
|
+
|
|
610
|
+
it('logic test', () => {
|
|
611
|
+
expect(objectTester(null)).to.be.true;
|
|
612
|
+
expect(objectTester({})).to.be.true;
|
|
613
|
+
expect(objectTester({ a: 1 })).to.be.true;
|
|
614
|
+
});
|
|
615
|
+
});
|
|
616
|
+
|
|
617
|
+
describe('hasPropertyTester()', () => {
|
|
618
|
+
it('logic test', () => {
|
|
619
|
+
expect(hasPropertyTester({})).to.be.false;
|
|
620
|
+
expect(hasPropertyTester({ a: 1 })).to.be.true;
|
|
621
|
+
});
|
|
622
|
+
});
|
|
623
|
+
});
|
|
624
|
+
|
|
625
|
+
describe('date', () => {
|
|
626
|
+
const now: Date = new Date();
|
|
627
|
+
|
|
628
|
+
const year: number = now.getFullYear();
|
|
629
|
+
const month: number = now.getMonth();
|
|
630
|
+
const date: number = now.getDate();
|
|
631
|
+
|
|
632
|
+
const hours: number = now.getHours();
|
|
633
|
+
const minutes: number = now.getMinutes();
|
|
634
|
+
const seconds: number = now.getSeconds();
|
|
635
|
+
const ms: number = now.getMilliseconds();
|
|
636
|
+
|
|
637
|
+
describe('dateTester()', () => {
|
|
638
|
+
it('common test', () => {
|
|
639
|
+
expect(commonTestRunner(
|
|
640
|
+
dateTester,
|
|
641
|
+
false,
|
|
642
|
+
false,
|
|
643
|
+
false,
|
|
644
|
+
false,
|
|
645
|
+
false,
|
|
646
|
+
false,
|
|
647
|
+
false
|
|
648
|
+
)).to.be.true;
|
|
649
|
+
});
|
|
650
|
+
|
|
651
|
+
it('logic test', () => {
|
|
652
|
+
expect(dateTester(new Date)).to.be.true;
|
|
653
|
+
expect(dateTester((new Date).toISOString())).to.be.false;
|
|
654
|
+
});
|
|
655
|
+
});
|
|
656
|
+
|
|
657
|
+
it('minDateTester()', () => {
|
|
658
|
+
expect(minDateTester(
|
|
659
|
+
new Date(year, month, date),
|
|
660
|
+
new Date(year, month, date - 1)
|
|
661
|
+
)).to.be.true;
|
|
662
|
+
expect(minDateTester(
|
|
663
|
+
new Date(year, month, date),
|
|
664
|
+
new Date(year, month, date)
|
|
665
|
+
)).to.be.true;
|
|
666
|
+
expect(minDateTester(
|
|
667
|
+
new Date(year, month, date),
|
|
668
|
+
new Date(year, month, date + 1)
|
|
669
|
+
)).to.be.false;
|
|
670
|
+
|
|
671
|
+
expect(minDateTester(
|
|
672
|
+
new Date(year, month, date, hours, minutes, seconds, ms),
|
|
673
|
+
new Date(year, month, date, hours, minutes, seconds, ms - 1)
|
|
674
|
+
)).to.be.true;
|
|
675
|
+
expect(minDateTester(
|
|
676
|
+
new Date(year, month, date, hours, minutes, seconds, ms),
|
|
677
|
+
new Date(year, month, date, hours, minutes, seconds, ms)
|
|
678
|
+
)).to.be.true;
|
|
679
|
+
expect(minDateTester(
|
|
680
|
+
new Date(year, month, date, hours, minutes, seconds, ms),
|
|
681
|
+
new Date(year, month, date, hours, minutes, seconds, ms + 1)
|
|
682
|
+
)).to.be.false;
|
|
683
|
+
});
|
|
684
|
+
|
|
685
|
+
it('exclusiveMinDateTester()', () => {
|
|
686
|
+
expect(exclusiveMinDateTester(
|
|
687
|
+
new Date(year, month, date),
|
|
688
|
+
new Date(year, month, date - 1)
|
|
689
|
+
)).to.be.true;
|
|
690
|
+
expect(exclusiveMinDateTester(
|
|
691
|
+
new Date(year, month, date),
|
|
692
|
+
new Date(year, month, date)
|
|
693
|
+
)).to.be.false;
|
|
694
|
+
expect(exclusiveMinDateTester(
|
|
695
|
+
new Date(year, month, date),
|
|
696
|
+
new Date(year, month, date + 1)
|
|
697
|
+
)).to.be.false;
|
|
698
|
+
|
|
699
|
+
expect(exclusiveMinDateTester(
|
|
700
|
+
new Date(year, month, date, hours, minutes, seconds, ms),
|
|
701
|
+
new Date(year, month, date, hours, minutes, seconds, ms - 1)
|
|
702
|
+
)).to.be.true;
|
|
703
|
+
expect(exclusiveMinDateTester(
|
|
704
|
+
new Date(year, month, date, hours, minutes, seconds, ms),
|
|
705
|
+
new Date(year, month, date, hours, minutes, seconds, ms)
|
|
706
|
+
)).to.be.false;
|
|
707
|
+
expect(exclusiveMinDateTester(
|
|
708
|
+
new Date(year, month, date, hours, minutes, seconds, ms),
|
|
709
|
+
new Date(year, month, date, hours, minutes, seconds, ms + 1)
|
|
710
|
+
)).to.be.false;
|
|
711
|
+
});
|
|
712
|
+
|
|
713
|
+
it('maxDateTester()', () => {
|
|
714
|
+
expect(maxDateTester(
|
|
715
|
+
new Date(year, month, date),
|
|
716
|
+
new Date(year, month, date - 1)
|
|
717
|
+
)).to.be.false;
|
|
718
|
+
expect(maxDateTester(
|
|
719
|
+
new Date(year, month, date),
|
|
720
|
+
new Date(year, month, date)
|
|
721
|
+
)).to.be.true;
|
|
722
|
+
expect(maxDateTester(
|
|
723
|
+
new Date(year, month, date),
|
|
724
|
+
new Date(year, month, date + 1)
|
|
725
|
+
)).to.be.true;
|
|
726
|
+
|
|
727
|
+
expect(maxDateTester(
|
|
728
|
+
new Date(year, month, date, hours, minutes, seconds, ms),
|
|
729
|
+
new Date(year, month, date, hours, minutes, seconds, ms - 1)
|
|
730
|
+
)).to.be.false;
|
|
731
|
+
expect(maxDateTester(
|
|
732
|
+
new Date(year, month, date, hours, minutes, seconds, ms),
|
|
733
|
+
new Date(year, month, date, hours, minutes, seconds, ms)
|
|
734
|
+
)).to.be.true;
|
|
735
|
+
expect(maxDateTester(
|
|
736
|
+
new Date(year, month, date, hours, minutes, seconds, ms),
|
|
737
|
+
new Date(year, month, date, hours, minutes, seconds, ms + 1)
|
|
738
|
+
)).to.be.true;
|
|
739
|
+
});
|
|
740
|
+
|
|
741
|
+
it('exclusiveMaxDateTester()', () => {
|
|
742
|
+
expect(exclusiveMaxDateTester(
|
|
743
|
+
new Date(year, month, date),
|
|
744
|
+
new Date(year, month, date - 1)
|
|
745
|
+
)).to.be.false;
|
|
746
|
+
expect(exclusiveMaxDateTester(
|
|
747
|
+
new Date(year, month, date),
|
|
748
|
+
new Date(year, month, date)
|
|
749
|
+
)).to.be.false;
|
|
750
|
+
expect(exclusiveMaxDateTester(
|
|
751
|
+
new Date(year, month, date),
|
|
752
|
+
new Date(year, month, date + 1)
|
|
753
|
+
)).to.be.true;
|
|
754
|
+
|
|
755
|
+
expect(exclusiveMaxDateTester(
|
|
756
|
+
new Date(year, month, date, hours, minutes, seconds, ms),
|
|
757
|
+
new Date(year, month, date, hours, minutes, seconds, ms - 1)
|
|
758
|
+
)).to.be.false;
|
|
759
|
+
expect(exclusiveMaxDateTester(
|
|
760
|
+
new Date(year, month, date, hours, minutes, seconds, ms),
|
|
761
|
+
new Date(year, month, date, hours, minutes, seconds, ms)
|
|
762
|
+
)).to.be.false;
|
|
763
|
+
expect(exclusiveMaxDateTester(
|
|
764
|
+
new Date(year, month, date, hours, minutes, seconds, ms),
|
|
765
|
+
new Date(year, month, date, hours, minutes, seconds, ms + 1)
|
|
766
|
+
)).to.be.true;
|
|
767
|
+
});
|
|
768
|
+
});
|
|
769
|
+
|
|
770
|
+
describe('array', () => {
|
|
771
|
+
describe('arrayTester()', () => {
|
|
772
|
+
it('common test', () => {
|
|
773
|
+
expect(commonTestRunner(
|
|
774
|
+
arrayTester,
|
|
775
|
+
false,
|
|
776
|
+
false,
|
|
777
|
+
false,
|
|
778
|
+
false,
|
|
779
|
+
false,
|
|
780
|
+
true,
|
|
781
|
+
false
|
|
782
|
+
)).to.be.true;
|
|
783
|
+
});
|
|
784
|
+
|
|
785
|
+
it('logic test', () => {
|
|
786
|
+
expect(arrayTester([])).to.be.true;
|
|
787
|
+
expect(arrayTester('not_array')).to.be.false;
|
|
788
|
+
});
|
|
789
|
+
});
|
|
790
|
+
|
|
791
|
+
describe('arrayTypeOfTester()', () => {
|
|
792
|
+
it('logic test', () => {
|
|
793
|
+
expect(arrayTypeOfTester([], DATA_TYPE.NUMBER)).to.be.true;
|
|
794
|
+
expect(arrayTypeOfTester([1, 2], DATA_TYPE.NUMBER)).to.be.true;
|
|
795
|
+
expect(arrayTypeOfTester([1, 2, '3'], DATA_TYPE.NUMBER)).to.be.false;
|
|
796
|
+
|
|
797
|
+
expect(arrayTypeOfTester([new Date(), new Date(), new Date()], DATA_TYPE.DATE)).to.be.true;
|
|
798
|
+
});
|
|
799
|
+
});
|
|
800
|
+
|
|
801
|
+
describe('uniqueItemsTester()', () => {
|
|
802
|
+
it('logic test', () => {
|
|
803
|
+
expect(uniqueItemsTester([])).to.be.true;
|
|
804
|
+
expect(uniqueItemsTester([1, 2])).to.be.true;
|
|
805
|
+
expect(uniqueItemsTester([1, 2, 2])).to.be.false;
|
|
806
|
+
});
|
|
807
|
+
});
|
|
808
|
+
});
|
|
809
|
+
|
|
810
|
+
describe('regexp', () => {
|
|
811
|
+
describe('regExpTester()', () => {
|
|
812
|
+
it('common test', () => {
|
|
813
|
+
expect(commonTestRunner(
|
|
814
|
+
regExpTester,
|
|
815
|
+
false,
|
|
816
|
+
false,
|
|
817
|
+
false,
|
|
818
|
+
false,
|
|
819
|
+
false,
|
|
820
|
+
false,
|
|
821
|
+
false
|
|
822
|
+
)).to.be.true;
|
|
823
|
+
});
|
|
824
|
+
|
|
825
|
+
it('logic test', () => {
|
|
826
|
+
expect(regExpTester(/\d/)).to.be.true;
|
|
827
|
+
expect(regExpTester(new RegExp('d'))).to.be.true;
|
|
828
|
+
|
|
829
|
+
expect(regExpTester('d')).to.be.false;
|
|
830
|
+
});
|
|
831
|
+
});
|
|
832
|
+
});
|
|
833
|
+
});
|