[DRVWEB-4373] Add Suggestion Mode spotlight onboarding modal for docs on drive
[ProtonMail-WebClient.git] / packages / pass / utils / string / semver.spec.ts
blob50c9444a85b7112eddf96ce361b13ad73ebdf14c
1 import { semver } from './semver';
3 describe('semver', () => {
4     test('should parse `major` format', () => {
5         expect(semver('1')).toEqual(1000000000);
6         expect(semver('2')).toEqual(2000000000);
7         expect(semver('22')).toEqual(22000000000);
8         expect(semver('9999')).toEqual(9999000000000);
9     });
11     test('should parse `major.minor` format', () => {
12         expect(semver('1.0')).toEqual(1000000000);
13         expect(semver('1.1')).toEqual(1001000000);
14         expect(semver('1.1')).toEqual(1001000000);
15         expect(semver('2.2')).toEqual(2002000000);
16         expect(semver('22.0')).toEqual(22000000000);
17         expect(semver('9999.0')).toEqual(9999000000000);
18     });
20     test('should parse `major.minor.patch` format', () => {
21         expect(semver('1.0.0')).toEqual(1000000000);
22         expect(semver('1.1.0')).toEqual(1001000000);
23         expect(semver('1.1.1')).toEqual(1001001000);
24         expect(semver('2.2.2')).toEqual(2002002000);
25         expect(semver('22.0.0')).toEqual(22000000000);
26         expect(semver('9999.0.1')).toEqual(9999000001000);
27     });
29     test('should parse `major.minor.patch.build` format', () => {
30         expect(semver('1.0.0.0')).toEqual(1000000000);
31         expect(semver('1.1.0.1')).toEqual(1001000001);
32         expect(semver('1.1.1.2')).toEqual(1001001002);
33         expect(semver('2.2.2.99')).toEqual(2002002099);
34         expect(semver('22.0.0.9')).toEqual(22000000009);
35         expect(semver('9999.0.1.999')).toEqual(9999000001999);
36     });
38     test('should parse `major.minor.patch-rc` format', () => {
39         expect(semver('1.0.0-rc1')).toEqual(1000000000);
40         expect(semver('1.1.0-beta')).toEqual(1001000000);
41         expect(semver('11.1.100-rc2')).toEqual(11001100000);
42     });
44     test('comparing should work', () => {
45         expect(semver('1.0.0') > semver('0.0.2')).toBe(true);
46         expect(semver('1.0.0') < semver('1.0.1')).toBe(true);
47         expect(semver('1.0.0.1') > semver('1.0.0')).toBe(true);
48         expect(semver('1.0.0') === semver('1.0.0')).toBe(true);
49         expect(semver('1.2.3') > semver('1.2.2')).toBe(true);
50         expect(semver('1.2.3.4') > semver('1.2.3')).toBe(true);
51         expect(semver('1.2.3.999') > semver('1.2.3')).toBe(true);
52         expect(semver('999.2.3.999') > semver('1.2.3')).toBe(true);
53     });
55     test('should handle invalid input', () => {
56         expect(semver('invalid')).toBe(0);
57         expect(semver('1.2.invalid')).toBe(1002000000);
58     });
59 });