-
Notifications
You must be signed in to change notification settings - Fork 6
/
Copy pathversion-utils.test.ts
82 lines (76 loc) · 2.46 KB
/
version-utils.test.ts
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
import { VersionUtils } from "../src/version-utils";
describe("VersionUtils", () => {
describe("validVersion", () => {
it.each([
["5", true],
["5.2", true],
["5.2.3", true],
["5.2.3.1", true],
["5.2.3.1.6", false],
["invalid_version_format", false],
["", false]
])("'%s' -> %s", (version: string, expected: boolean) => {
expect(VersionUtils.isValidVersion(version)).toBe(expected);
});
});
it("sortVersions", () => {
const actual = VersionUtils.sortVersions([
"11.2",
"11.4",
"10.1",
"11.2.1",
"10.2"
]);
expect(actual).toEqual([
"11.4",
"11.2.1",
"11.2",
"10.2",
"10.1"
]);
});
describe("isVersionsEqual", () => {
it.each([
["11.2", "11.2", true],
["11.x", "11.2", true],
["11.x.x", "11.2", true],
["11.x.x", "11.2.1", true],
["11", "11.2", false],
["11", "11.2.1", false],
["10", "11.2", false]
])("'%s', '%s' -> %s", (firstVersion: string, secondVersion: string, expected: boolean) => {
const actual = VersionUtils.isVersionsEqual(firstVersion, secondVersion);
expect(actual).toBe(expected);
});
});
describe("normalizeVersion", () => {
it.each([
["5", "5.x.x.x"],
["5.2", "5.2.x.x"],
["5.2.3", "5.2.3.x"],
["5.2.3.1", "5.2.3.1"]
])("'%s' -> '%s'", (version: string, expected: string) => {
expect(VersionUtils.normalizeVersion(version)).toBe(expected);
});
});
describe("countVersionLength", () => {
it.each([
["5", 1],
["5.2", 2],
["5.2.3", 3],
["5.2.3.1", 4]
])("'%s' -> %d", (version: string, expected: number) => {
expect(VersionUtils.countVersionLength(version)).toBe(expected);
});
});
describe("cutVersionLength", () => {
it.each([
["5.2.3.1", 4, "5.2.3.1"],
["5.2.3.1", 3, "5.2.3"],
["5.2.3.1", 2, "5.2"],
["5.2.3.1", 1, "5"]
])("'%s', %d -> '%s'", (version: string, newLength: number, expected: string) => {
expect(VersionUtils.cutVersionLength(version, newLength)).toBe(expected);
});
});
});