| b69ab31 | | | 1 | /** |
| b69ab31 | | | 2 | * Copyright (c) Meta Platforms, Inc. and affiliates. |
| b69ab31 | | | 3 | * |
| b69ab31 | | | 4 | * This source code is licensed under the MIT license found in the |
| b69ab31 | | | 5 | * LICENSE file in the root directory of this source tree. |
| b69ab31 | | | 6 | */ |
| b69ab31 | | | 7 | |
| b69ab31 | | | 8 | import {compareVersions, parseVersionParts} from '../versionNumbers'; |
| b69ab31 | | | 9 | |
| b69ab31 | | | 10 | describe('version numbers', () => { |
| b69ab31 | | | 11 | describe('parseVersionParts', () => { |
| b69ab31 | | | 12 | it('parses version parts', () => { |
| b69ab31 | | | 13 | expect(parseVersionParts('1.2.3')).toEqual([1, 2, 3]); |
| b69ab31 | | | 14 | expect(parseVersionParts('1.2')).toEqual([1, 2]); |
| b69ab31 | | | 15 | expect(parseVersionParts('V0.10')).toEqual([0, 10]); |
| b69ab31 | | | 16 | }); |
| b69ab31 | | | 17 | |
| b69ab31 | | | 18 | it('ignores extra non-numerics', () => { |
| b69ab31 | | | 19 | expect(parseVersionParts('V1')).toEqual([1]); |
| b69ab31 | | | 20 | expect(parseVersionParts('V1.1-alpha')).toEqual([1, 1]); |
| b69ab31 | | | 21 | }); |
| b69ab31 | | | 22 | }); |
| b69ab31 | | | 23 | |
| b69ab31 | | | 24 | describe('compareVersions', () => { |
| b69ab31 | | | 25 | it('compares version parts', () => { |
| b69ab31 | | | 26 | expect(compareVersions(parseVersionParts('1.2'), parseVersionParts('1.3'))).toEqual(-1); |
| b69ab31 | | | 27 | expect(compareVersions(parseVersionParts('1.3'), parseVersionParts('1.2'))).toEqual(1); |
| b69ab31 | | | 28 | expect(compareVersions(parseVersionParts('1.2'), parseVersionParts('1.2'))).toEqual(0); |
| b69ab31 | | | 29 | }); |
| b69ab31 | | | 30 | |
| b69ab31 | | | 31 | it('compares in order', () => { |
| b69ab31 | | | 32 | expect(compareVersions(parseVersionParts('3.0.0'), parseVersionParts('2.99.999'))).toEqual(1); |
| b69ab31 | | | 33 | expect(compareVersions(parseVersionParts('3.2.0'), parseVersionParts('3.1.999'))).toEqual(1); |
| b69ab31 | | | 34 | }); |
| b69ab31 | | | 35 | |
| b69ab31 | | | 36 | it('uses integer comparison', () => { |
| b69ab31 | | | 37 | expect(compareVersions(parseVersionParts('1.10'), parseVersionParts('1.2'))).toEqual(1); |
| b69ab31 | | | 38 | }); |
| b69ab31 | | | 39 | |
| b69ab31 | | | 40 | it('handles different lengths', () => { |
| b69ab31 | | | 41 | expect(compareVersions(parseVersionParts('1.3.1'), parseVersionParts('1.3'))).toEqual(1); |
| b69ab31 | | | 42 | expect(compareVersions(parseVersionParts('1.2.1'), parseVersionParts('1.3'))).toEqual(-1); |
| b69ab31 | | | 43 | }); |
| b69ab31 | | | 44 | |
| b69ab31 | | | 45 | it('1 is less than 1.0', () => { |
| b69ab31 | | | 46 | expect(compareVersions(parseVersionParts('3'), parseVersionParts('3.0'))).toEqual(-1); |
| b69ab31 | | | 47 | }); |
| b69ab31 | | | 48 | |
| b69ab31 | | | 49 | it("extra non-numerics don't affect it", () => { |
| b69ab31 | | | 50 | expect(compareVersions(parseVersionParts('v3.1-alpha'), parseVersionParts('3.0'))).toEqual(1); |
| b69ab31 | | | 51 | expect(compareVersions(parseVersionParts('v3.1-alpha'), parseVersionParts('3.1'))).toEqual(0); |
| b69ab31 | | | 52 | }); |
| b69ab31 | | | 53 | }); |
| b69ab31 | | | 54 | }); |