-
Notifications
You must be signed in to change notification settings - Fork 15
Expand file tree
/
Copy pathVersionTest.js
More file actions
466 lines (388 loc) · 14.4 KB
/
VersionTest.js
File metadata and controls
466 lines (388 loc) · 14.4 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
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
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
const { describe, it } = (exports.lab = require('@hapi/lab').script());
const expect = require('@hapi/code').expect;
const Version = require('../../src/model/Version');
describe('Version Class', () => {
describe("'is' method", () => {
describe('with zero or one parameter', () => {
it('should work as expected', () => {
const version = new Version({ value: '40.0.2214' });
expect(version.is()).to.be.false();
expect(version.is('39')).to.be.false();
expect(version.is('40')).to.be.true();
});
});
describe('with operator and major version compare', () => {
it('should work as expected', () => {
const version = new Version({ value: '40.0.2214' });
expect(version.is('=', '40')).to.be.true();
expect(version.is('>=', '40')).to.be.true();
expect(version.is('<=', '40')).to.be.true();
expect(version.is('>', '39')).to.be.true();
expect(version.is('<', '41')).to.be.true();
expect(version.is('=', '39')).to.be.false();
expect(version.is('>=', '41')).to.be.false();
expect(version.is('<=', '39')).to.be.false();
expect(version.is('>', '40')).to.be.false();
expect(version.is('<', '40')).to.be.false();
});
});
describe('with operator and major, minor and patch version compare', () => {
it('should work as expected', () => {
const version = new Version({ value: '10.11.1' });
expect(version.is('=', '10')).to.be.true();
expect(version.is('=', '10.11')).to.be.true();
expect(version.is('=', '10.11.1')).to.be.true();
expect(version.is('=', '10.11.01')).to.be.true();
expect(version.is('=', 10)).to.be.true();
expect(version.is('=', 10.11)).to.be.true();
expect(version.is('>', '10.1')).to.be.true();
expect(version.is('>', '10.01')).to.be.true();
expect(version.is('>', '10.10')).to.be.true();
expect(version.is('>', '10')).to.be.false();
expect(version.is('>', '10.11')).to.be.false();
});
});
describe('with operator and major, minor as float', () => {
it('should work as expected', () => {
const version = new Version({ value: 10.11 });
expect(version.is('=', '10')).to.be.true();
expect(version.is('=', '10.11')).to.be.true();
expect(version.is('=', '10.11.1')).to.be.true();
expect(version.is('=', '10.11.01')).to.be.true();
expect(version.is('=', 10)).to.be.true();
expect(version.is('=', 10.11)).to.be.true();
expect(version.is('>', '10.1')).to.be.true();
expect(version.is('>', '10.01')).to.be.true();
expect(version.is('>', '10.10')).to.be.true();
expect(version.is('>', '10')).to.be.false();
expect(version.is('>', '10.11')).to.be.false();
});
});
});
describe('getParts method', () => {
describe('with no version', () => {
it('should return 0, 0, 0 object', () => {
const version = new Version();
version.value = '';
expect(version.getParts()).to.equal({ major: 0, minor: 0, patch: 0 });
});
});
describe('with major version', () => {
it('should return major, 0, 0 object', () => {
const version = new Version();
version.value = '4';
expect(version.getParts()).to.equal({ major: 4, minor: 0, patch: 0 });
});
});
describe('with major and minor version', () => {
it('should return major, minor, 0 object', () => {
const version = new Version();
version.value = '4.1';
expect(version.getParts()).to.equal({ major: 4, minor: 1, patch: 0 });
});
});
describe('with major minor and patch version', () => {
it('should return major, minor, patch object', () => {
const version = new Version();
version.value = '4.1.2';
expect(version.getParts()).to.equal({ major: 4, minor: 1, patch: 2 });
});
});
});
describe('getMajor method', () => {
describe('with no version', () => {
it('should return 0', () => {
const version = new Version();
version.value = '';
expect(version.getMajor()).to.equal(0);
});
});
describe('with major version', () => {
it('should return the major version', () => {
const version = new Version();
version.value = '4';
expect(version.getMajor()).to.equal(4);
});
});
describe('with major and minor version', () => {
it('should return the major version', () => {
const version = new Version();
version.value = '4.1';
expect(version.getMajor()).to.equal(4);
});
});
describe('with major minor and patch version', () => {
it('should return the major version', () => {
const version = new Version();
version.value = '4.1.2';
expect(version.getMajor()).to.be.equal(4);
});
});
});
describe('getMinor method', () => {
describe('with no version', () => {
it('should return 0', () => {
const version = new Version();
version.value = '';
expect(version.getMinor()).to.equal(0);
});
});
describe('with major version', () => {
it('should return 0', () => {
const version = new Version();
version.value = '4';
expect(version.getMinor()).to.equal(0);
});
});
describe('with major and minor version', () => {
it('should return the minor version', () => {
const version = new Version();
version.value = '4.1';
expect(version.getMinor()).to.equal(1);
});
});
describe('with major minor and patch version', () => {
it('should return the minor version', () => {
const version = new Version();
version.value = '4.1.2';
expect(version.getMinor()).to.be.equal(1);
});
});
});
describe('getPatch method', () => {
describe('with no version', () => {
it('should return 0', () => {
const version = new Version();
version.value = '';
expect(version.getPatch()).to.equal(0);
});
});
describe('with major version', () => {
it('should return 0', () => {
const version = new Version();
version.value = '4';
expect(version.getPatch()).to.equal(0);
});
});
describe('with major and minor version', () => {
it('should return 0', () => {
const version = new Version();
version.value = '4.1';
expect(version.getPatch()).to.equal(0);
});
});
describe('with major minor and patch version', () => {
it('should return the patch version', () => {
const version = new Version();
version.value = '4.1.2';
expect(version.getPatch()).to.be.equal(2);
});
});
});
describe('toValue method', () => {
describe('with only major', () => {
it('should work', () => {
const version = new Version();
version.value = '4';
expect(version.toValue()).to.equal(4);
});
});
describe('with major and minor version', () => {
it('should work', () => {
const version = new Version();
version.value = '4.1';
expect(version.toValue()).to.equal(4.0001);
});
});
describe('with major, minor and patch version', () => {
it('should work', () => {
const version = new Version();
version.value = '4.1.1';
expect(version.toValue()).to.equal(4.00010001);
});
});
describe('with major minor version with two digit and patch version with one digit', () => {
it('should work', () => {
const version = new Version();
version.value = '10.10.3';
expect(version.toValue()).to.be.equal(10.00100003);
});
});
});
describe('toFloat method', () => {
describe('with only major', () => {
it('should work', () => {
const version = new Version();
version.value = '4';
expect(version.toFloat()).to.equal(4);
});
});
describe('with major and minor version', () => {
it('should work', () => {
const version = new Version();
version.value = '4.1';
expect(version.toFloat()).to.equal(4.1);
});
});
describe('with major, minor and patch version', () => {
it('should work', () => {
const version = new Version();
version.value = '4.1.1';
expect(version.toFloat()).to.equal(4.1);
});
});
describe('with major minor version with two digit and patch version with one digit', () => {
it('should work', () => {
const version = new Version();
version.value = '10.10.3';
expect(version.toFloat()).to.be.equal(10.1);
});
});
});
describe('toNumber method', () => {
describe('with only major', () => {
it('should work', () => {
const version = new Version();
version.value = '4';
expect(version.toNumber()).to.equal(4);
});
});
describe('with major and minor version', () => {
it('should work', () => {
const version = new Version();
version.value = '4.1';
expect(version.toNumber()).to.equal(4);
});
});
describe('with major, minor and patch version', () => {
it('should work', () => {
const version = new Version();
version.value = '4.1.1';
expect(version.toNumber()).to.equal(4);
});
});
describe('with major minor version with two digit and patch version with one digit', () => {
it('should work', () => {
const version = new Version();
version.value = '10.10.3';
expect(version.toNumber()).to.be.equal(10);
});
});
});
describe('toString method', () => {
describe('with no details or builds', () => {
it('should work as expected', () => {
const version = new Version();
version.value = '4.1.1';
expect(version.toString()).to.equal('4.1.1');
version.value = '4.1';
expect(version.toString()).to.equal('4.1');
version.value = '4.0a4';
expect(version.toString()).to.equal('4.0a4');
version.value = '4.0b2';
expect(version.toString()).to.equal('4.0b2');
});
});
describe('with details but not builds', () => {
it('should work as expected', () => {
const version = new Version();
version.set({ value: '4.1.1', details: 0 });
expect(version.toString()).to.equal('4.1.1');
version.set({ value: '4.1.1', details: 1 });
expect(version.toString()).to.equal('4');
version.set({ value: '4.1.1', details: 2 });
expect(version.toString()).to.equal('4.1');
version.set({ value: '4.1.1', details: 3 });
expect(version.toString()).to.equal('4.1.1');
version.set({ value: '4.1.1', details: 4 });
expect(version.toString()).to.equal('4.1.1');
version.set({ value: '4.1', details: 3 });
expect(version.toString()).to.equal('4.1');
version.set({ value: '4.1.1', details: -1 });
expect(version.toString()).to.equal('4.1');
version.set({ value: '4.1.1', details: -2 });
expect(version.toString()).to.equal('4');
version.set({ value: '4.1.1', details: -3 });
expect(version.toString()).to.equal('');
version.set({ value: '4.1.1', details: -4 });
expect(version.toString()).to.equal('');
});
});
describe('with builds but not details', () => {
it('should work as expected', () => {
const version = new Version();
version.set({ value: '5.0.2.999', builds: false });
expect(version.toString()).to.equal('5.0.2.999');
version.set({ value: '5.0.2.1000', builds: false });
expect(version.toString()).to.equal('5.0.2');
version.set({ value: '5.0.2.4428', builds: false });
expect(version.toString()).to.equal('5.0.2');
version.set({ value: '5.0.4428', builds: false });
expect(version.toString()).to.equal('5.0');
version.set({ value: '5.4428', builds: false });
expect(version.toString()).to.equal('5');
version.set({ value: '4428', builds: false });
expect(version.toString()).to.equal('');
});
});
describe('with alias', () => {
it('should return alias', () => {
const version = new Version();
version.set({ value: '5.1', alias: 'XP' });
expect(version.toString()).to.be.equal('XP');
});
});
describe('with nickname', () => {
it('should return nickaname and version', () => {
const version = new Version();
version.set({ value: '10.11', nickname: 'El Captain' });
expect(version.toString()).to.be.equal('El Captain 10.11');
});
});
describe('with nickname and details', () => {
it('should return nickname and a subset of verson', () => {
const version = new Version();
version.set({ value: '10.11.2', nickname: 'El Captain', details: 2 });
expect(version.toString()).to.be.equal('El Captain 10.11');
});
});
});
describe('toObject method', () => {
describe('with all properties empty', () => {
it('should return an empty object', () => {
const version = new Version();
expect(version.toObject()).equal({});
});
});
describe('with value filled', () => {
it('should return the only value', () => {
const version = new Version();
version.set({ value: '4.1.1' });
expect(version.toObject()).to.equal('4.1.1');
});
});
describe('with value and details filled', () => {
it('should return the with value according to details level', () => {
const version = new Version();
version.set({ value: '4.1.1', details: 2 });
expect(version.toObject()).to.equal('4.1');
});
});
describe('with value and alias filled', () => {
it('should return an object with value and alias properties', () => {
const version = new Version();
const properties = { value: '5.1', alias: 'XP' };
version.set(properties);
expect(version.toObject()).to.equal(properties);
});
});
describe('with value and nickname filled', () => {
it('should return an object with value and nickname properties', () => {
const version = new Version();
const properties = { value: '10.11', nickname: 'El Captain' };
version.set(properties);
expect(version.toObject()).to.equal(properties);
});
});
});
});