]>
Commit | Line | Data |
---|---|---|
1 | /* tslint:disable:no-unused-expression */ | |
2 | ||
3 | import * as chai from 'chai' | |
4 | import 'mocha' | |
5 | import { | |
6 | parseBytes | |
7 | } from '../../helpers/core-utils' | |
8 | ||
9 | const expect = chai.expect | |
10 | ||
11 | describe('Parse Bytes', function () { | |
12 | it('Should pass when given valid value', async function () { | |
13 | // just return it | |
14 | expect(parseBytes(1024)).to.be.eq(1024) | |
15 | expect(parseBytes(1048576)).to.be.eq(1048576) | |
16 | expect(parseBytes('1024')).to.be.eq(1024) | |
17 | expect(parseBytes('1048576')).to.be.eq(1048576) | |
18 | ||
19 | // sizes | |
20 | expect(parseBytes('1B')).to.be.eq(1024) | |
21 | expect(parseBytes('1MB')).to.be.eq(1048576) | |
22 | expect(parseBytes('1GB')).to.be.eq(1073741824) | |
23 | expect(parseBytes('1TB')).to.be.eq(1099511627776) | |
24 | ||
25 | expect(parseBytes('5GB')).to.be.eq(5368709120) | |
26 | expect(parseBytes('5TB')).to.be.eq(5497558138880) | |
27 | ||
28 | expect(parseBytes('1024B')).to.be.eq(1048576) | |
29 | expect(parseBytes('1024MB')).to.be.eq(1073741824) | |
30 | expect(parseBytes('1024GB')).to.be.eq(1099511627776) | |
31 | expect(parseBytes('1024TB')).to.be.eq(1125899906842624) | |
32 | ||
33 | // with whitespace | |
34 | expect(parseBytes('1 GB')).to.be.eq(1073741824) | |
35 | expect(parseBytes('1\tGB')).to.be.eq(1073741824) | |
36 | ||
37 | // sum value | |
38 | expect(parseBytes('1TB 1024MB')).to.be.eq(1100585369600) | |
39 | expect(parseBytes('4GB 1024MB')).to.be.eq(5368709120) | |
40 | expect(parseBytes('4TB 1024GB')).to.be.eq(5497558138880) | |
41 | expect(parseBytes('4TB 1024GB 0MB')).to.be.eq(5497558138880) | |
42 | expect(parseBytes('1024TB 1024GB 1024MB')).to.be.eq(1127000492212224) | |
43 | }) | |
44 | ||
45 | it('Should be invalid when given invalid value', async function () { | |
46 | expect(parseBytes('6GB 1GB')).to.be.eq(6) | |
47 | }) | |
48 | }) |