-
Notifications
You must be signed in to change notification settings - Fork 229
/
Copy pathutil_test.js
392 lines (282 loc) · 8.83 KB
/
util_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
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
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
import { expect } from 'chai';
import * as util from '../src/util';
describe('util', () => {
describe('#isPrivateTag', () => {
it('should return `true` for a private tag', () => {
const isPrivateTag = util.isPrivateTag('x001d0010');
expect(isPrivateTag).to.equal(true);
})
it('should return `false` for a non-private tag', () => {
const isPrivateTag = util.isPrivateTag('x00100010');
expect(isPrivateTag).to.equal(false);
})
it('should throw an exception', () => {
// Arrange
const tag = 'x100z0010';
const invoker = () => util.isPrivateTag(tag);
// Act / Assert
expect(invoker).to.throw();
});
});
describe('#parsePN', () => {
describe('when parsing a full PN', () => {
let val;
beforeEach(() => {
// Arrange
const pnString = 'F^G^M^P^S';
// Act
val = util.parsePN(pnString);
});
it('should return the right family name', () => {
// Assert
expect(val.familyName).to.equal('F');
});
it('should return the right given name', () => {
// Assert
expect(val.givenName).to.equal('G');
});
it('should return the right middle name', () => {
// Assert
expect(val.middleName).to.equal('M');
});
it('should return the right prefix', () => {
// Assert
expect(val.prefix).to.equal('P');
});
it('should return the right suffix', () => {
// Assert
expect(val.suffix).to.equal('S');
});
});
describe('when parsing a partial PN', () => {
let val;
beforeEach(() => {
// Arrange
const pnString = 'F';
// Act
val = util.parsePN(pnString);
});
it('should return the right family name', () => {
// Assert
expect(val.familyName).to.equal('F');
});
it('should return the right given name', () => {
// Assert
expect(val.givenName).to.be.undefined;
});
it('should return the right middle name', () => {
// Assert
expect(val.middleName).to.be.undefined;
});
it('should return the right prefix', () => {
// Assert
expect(val.prefix).to.be.undefined;
});
it('should return the right suffix', () => {
// Assert
expect(val.suffix).to.be.undefined;
});
});
});
describe('#parseTM', () => {
describe('when parsing a full TM', () => {
let val;
beforeEach(() => {
// Arrange
const tmString = '081236.531000';
// Act
val = util.parseTM(tmString);
});
it('should return the right hours', () => {
// Assert
expect(val.hours).to.equal(8);
});
it('should return the right minutes', () => {
// Assert
expect(val.minutes).to.equal(12);
});
it('should return the right seconds', () => {
// Assert
expect(val.seconds).to.equal(36);
});
it('should return the right fractionalSeconds', () => {
// Assert
expect(val.fractionalSeconds).to.equal(531000);
});
});
describe('when parsing a partial TM', () => {
let val;
beforeEach(() => {
// Arrange
const tmString = '08';
// Act
val = util.parseTM(tmString);
});
it('should return the right hours', () => {
// Assert
expect(val.hours).to.equal(8);
});
it('should return the right minutes', () => {
// Assert
expect(val.minutes).to.be.undefined;
});
it('should return the right seconds', () => {
// Assert
expect(val.seconds).to.be.undefined;
});
it('should return the right fractionalSeconds', () => {
// Assert
expect(val.fractionalSeconds).to.be.undefined;
});
});
describe('when parsing a partial fractional TM', () => {
it('should return the expected value for no zeros', () => {
// Arrange
const tmString = '081236.5';
// Act
const val = util.parseTM(tmString);
// Assert
expect(val.hours).to.equal(8);
expect(val.minutes).to.equal(12);
expect(val.seconds).to.equal(36);
expect(val.fractionalSeconds).to.equal(500000);
});
it('should return the expected value for leading and following zeros', () => {
// Arrange
const tmString = '081236.00500';
// Act
const val = util.parseTM(tmString);
// Assert
expect(val.hours).to.equal(8);
expect(val.minutes).to.equal(12);
expect(val.seconds).to.equal(36);
expect(val.fractionalSeconds).to.equal(5000);
});
});
describe('when parsing a invalid TM', () => {
it('should throw an exception', () => {
// Arrange
const tmString = '241236.531000';
const invoker = () => util.parseTM(tmString, true);
// Act / Asset
expect(invoker).to.throw();
});
});
describe('when parsing a TM with bad seconds', () => {
it('shoud throw an exception', () => {
// Arrange
const tmString = '236036.531000';
const invoker = () => util.parseTM(tmString, true);
// Act / Asset
expect(invoker).to.throw();
});
});
describe('when parsing a TM with bad seconds', () => {
it('should throw an exception', () => {
// Arrange
const tmString = '232260.531000';
const invoker = () => util.parseTM(tmString, true);
// Act
expect(invoker).to.throw();
});
});
describe('when parsing a TM with bad fractional', () => {
it('should throw an exception', () => {
// Arrange
const tmString = '232259.AA';
const invoker = () => util.parseTM(tmString, true);
// Act / Asset
expect(invoker).to.throw();
});
});
});
describe('#parseDA', () => {
describe('when parsing a valid DA', () => {
it('should return the expected value', () => {
// Arrange
const daString = '20140329';
// Act
const val = util.parseDA(daString);
// Assert
expect(val.year).to.equal(2014);
expect(val.month).to.equal(3);
expect(val.day).to.equal(29);
});
});
describe('when parsing a DA with a bad month', () => {
it('should throw an exception', () => {
// Arrange
const daString = '20150001';
const invoker = () => util.parseDA(daString, true);
// Act / Asset
expect(invoker).to.throw();
});
});
describe('when parsing a DA with a bad day', () => {
it('should throw an exception', () => {
// Arrange
const daString = '20150100';
const invoker = () => util.parseDA(daString, true);
// Act
expect(invoker).to.throw();
});
});
describe('when parsing a DA that is not a leap year', () => {
it('should throw an exception', () => {
// Arrange
const daString = '20150229';
const invoker = () => util.parseDA(daString, true);
// Act / Asset
expect(invoker).to.throw();
});
});
describe('when parsing DA that is a leap year', () => {
it('should return the expected value', () => {
// Arrange
const daString = '20160229';
// Act
const val = util.parseDA(daString, true);
// Assert
expect(val.year).to.equal(2016);
expect(val.month).to.equal(2);
expect(val.day).to.equal(29);
});
});
describe('when parsing a DA with non-number characters on "day" positions', () => {
it('should throw an exception', () => {
// Arrange
const daString = '201500AA';
const invoker = () => util.parseDA(daString, true);
// Act / Assert
expect(invoker).to.throw();
});
});
describe('when parsing a DA with non-number characters on "year" positions', () => {
it('should throw an exception', () => {
// Arrange
const daString = 'AAAA0102';
const invoker = () => util.parseDA(daString, true);
// Act / Assert
expect(invoker).to.throw();
});
});
describe('when parsing a DA with non-number characters on "month" positions', () => {
it('parseDA month not number', () => {
// Arrange
const daString = '2015AA02';
const invoker = () => util.parseDA(daString, true);
// Act / Assert
expect(invoker).to.throw();
});
});
describe('when parsing a date with invalid length', () => {
it('should throw an exception', () => {
// Arrange
const daString = '201501';
const invoker = () => util.parseDA(daString, true);
// Act / Assert
expect(invoker).to.throw();
});
});
});
});