-
Notifications
You must be signed in to change notification settings - Fork 47
/
Copy pathsemantic-versioning.js
144 lines (136 loc) · 8.57 KB
/
semantic-versioning.js
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
/* global
compareVersions,
satisfiesVersionRequirement,
*/
describe('semantic versioning utilities', function()
{
it('should compare semantic versions as specified', function()
{
expect(compareVersions('9', '10')).toEqual(-1);
expect(compareVersions('0.9', '0.10')).toEqual(-1);
expect(compareVersions('9.3', '10.2')).toEqual(-1);
expect(compareVersions('0.0.9', '0.0.10')).toEqual(-1);
expect(compareVersions('0.9.4', '0.10.3')).toEqual(-1);
expect(compareVersions('9.4.5', '10.3.4')).toEqual(-1);
expect(compareVersions('0.0.0.9', '0.0.0.10')).toEqual(-1);
expect(compareVersions('0.0.9.8', '0.0.10.7')).toEqual(-1);
expect(compareVersions('0.9.8.7', '0.10.7.6')).toEqual(-1);
expect(compareVersions('9.8.7.6', '10.7.6.5')).toEqual(-1);
expect(compareVersions('10', '9')).toEqual(1);
expect(compareVersions('0.10', '0.9')).toEqual(1);
expect(compareVersions('10.2', '9.3')).toEqual(1);
expect(compareVersions('0.0.10', '0.0.9')).toEqual(1);
expect(compareVersions('0.10.3', '0.9.4')).toEqual(1);
expect(compareVersions('10.3.4', '9.4.5')).toEqual(1);
expect(compareVersions('0.0.0.10', '0.0.0.9')).toEqual(1);
expect(compareVersions('0.0.10.7', '0.0.9.8')).toEqual(1);
expect(compareVersions('0.10.7.6', '0.9.8.7')).toEqual(1);
expect(compareVersions('10.7.6.5', '9.8.7.6')).toEqual(1);
expect(compareVersions('0.1.2.3', '0.1.2.3')).toEqual(0);
expect(compareVersions('10.9.8.7', '10.9.8.7')).toEqual(0);
expect(compareVersions('9', '8')).toEqual(1);
expect(compareVersions('9', '9')).toEqual(0);
expect(compareVersions('9', '10')).toEqual(-1);
expect(compareVersions('9', '8.10')).toEqual(1);
expect(compareVersions('9', '9.5')).toEqual(0);
expect(compareVersions('9', '10.0')).toEqual(-1);
expect(compareVersions('9', '8.10.11')).toEqual(1);
expect(compareVersions('9', '9.4.5')).toEqual(0);
expect(compareVersions('9', '10.2.3')).toEqual(-1);
expect(compareVersions('9.5', '8')).toEqual(1);
expect(compareVersions('9.5', '9')).toEqual(0);
expect(compareVersions('9.5', '10')).toEqual(-1);
expect(compareVersions('9.5', '8.10')).toEqual(1);
expect(compareVersions('9.5', '9.4')).toEqual(1);
expect(compareVersions('9.5', '9.5')).toEqual(0);
expect(compareVersions('9.5', '9.6')).toEqual(-1);
expect(compareVersions('9.5', '10.4')).toEqual(-1);
expect(compareVersions('9.5', '8.4.5')).toEqual(1);
expect(compareVersions('9.5', '9.4.5')).toEqual(1);
expect(compareVersions('9.5', '9.5.3')).toEqual(0);
expect(compareVersions('9.5', '9.6.5')).toEqual(-1);
expect(compareVersions('9.5', '10.4.5')).toEqual(-1);
expect(compareVersions('9.5.5', '8')).toEqual(1);
expect(compareVersions('9.5.5', '9')).toEqual(0);
expect(compareVersions('9.5.5', '10')).toEqual(-1);
expect(compareVersions('9.5.5', '8.10')).toEqual(1);
expect(compareVersions('9.5.5', '9.4')).toEqual(1);
expect(compareVersions('9.5.5', '9.5')).toEqual(0);
expect(compareVersions('9.5.5', '9.6')).toEqual(-1);
expect(compareVersions('9.5.5', '10.4')).toEqual(-1);
expect(compareVersions('9.5.5', '8.4.5')).toEqual(1);
expect(compareVersions('9.5.5', '9.4.5')).toEqual(1);
expect(compareVersions('9.5.5', '9.5.4')).toEqual(1);
expect(compareVersions('9.5.5', '9.5.5')).toEqual(0);
expect(compareVersions('9.5.5', '9.5.6')).toEqual(-1);
expect(compareVersions('9.5.5', '9.6.5')).toEqual(-1);
expect(compareVersions('9.5.5', '10.4.5')).toEqual(-1);
});
it('should test semantic version requirements as expected', function()
{
expect(satisfiesVersionRequirement('9', '=10')).toEqual(false);
expect(satisfiesVersionRequirement('9', '<=10')).toEqual(true);
expect(satisfiesVersionRequirement('9', '<10')).toEqual(true);
expect(satisfiesVersionRequirement('9', '>=10')).toEqual(false);
expect(satisfiesVersionRequirement('9', '>10')).toEqual(false);
expect(satisfiesVersionRequirement('9', '=9')).toEqual(true);
expect(satisfiesVersionRequirement('9', '<=9')).toEqual(true);
expect(satisfiesVersionRequirement('9', '<9')).toEqual(false);
expect(satisfiesVersionRequirement('9', '>=9')).toEqual(true);
expect(satisfiesVersionRequirement('9', '>9')).toEqual(false);
expect(satisfiesVersionRequirement('10', '=9')).toEqual(false);
expect(satisfiesVersionRequirement('10', '<=9')).toEqual(false);
expect(satisfiesVersionRequirement('10', '<9')).toEqual(false);
expect(satisfiesVersionRequirement('10', '>=9')).toEqual(true);
expect(satisfiesVersionRequirement('10', '>9')).toEqual(true);
expect(satisfiesVersionRequirement('9.5.4', '=10.4.3')).toEqual(false);
expect(satisfiesVersionRequirement('9.5.4', '<=10.4.3')).toEqual(true);
expect(satisfiesVersionRequirement('9.5.4', '<10.4.3')).toEqual(true);
expect(satisfiesVersionRequirement('9.5.4', '>=10.4.3')).toEqual(false);
expect(satisfiesVersionRequirement('9.5.4', '>10.4.3')).toEqual(false);
expect(satisfiesVersionRequirement('9.5.4', '=9.4.3')).toEqual(false);
expect(satisfiesVersionRequirement('9.5.4', '<=9.4.3')).toEqual(false);
expect(satisfiesVersionRequirement('9.5.4', '<9.4.3')).toEqual(false);
expect(satisfiesVersionRequirement('9.5.4', '>=9.4.3')).toEqual(true);
expect(satisfiesVersionRequirement('9.5.4', '>9.4.3')).toEqual(true);
expect(satisfiesVersionRequirement('9.5.4', '=9.5.4')).toEqual(true);
expect(satisfiesVersionRequirement('9.5.4', '<=9.5.4')).toEqual(true);
expect(satisfiesVersionRequirement('9.5.4', '<9.5.4')).toEqual(false);
expect(satisfiesVersionRequirement('9.5.4', '>=9.5.4')).toEqual(true);
expect(satisfiesVersionRequirement('9.5.4', '>9.5.4')).toEqual(false);
expect(satisfiesVersionRequirement('9.5.4', '=9.6.5')).toEqual(false);
expect(satisfiesVersionRequirement('9.5.4', '<=9.6.5')).toEqual(true);
expect(satisfiesVersionRequirement('9.5.4', '<9.6.5')).toEqual(true);
expect(satisfiesVersionRequirement('9.5.4', '>=9.6.5')).toEqual(false);
expect(satisfiesVersionRequirement('9.5.4', '>9.6.5')).toEqual(false);
expect(satisfiesVersionRequirement('10.5.4', '=9.5.4')).toEqual(false);
expect(satisfiesVersionRequirement('10.5.4', '<=9.5.4')).toEqual(false);
expect(satisfiesVersionRequirement('10.5.4', '<9.5.4')).toEqual(false);
expect(satisfiesVersionRequirement('10.5.4', '>=9.5.4')).toEqual(true);
expect(satisfiesVersionRequirement('10.5.4', '>9.5.4')).toEqual(true);
expect(satisfiesVersionRequirement('9', '>=9 <10')).toEqual(true);
expect(satisfiesVersionRequirement('9', '<10 <9')).toEqual(false);
expect(satisfiesVersionRequirement('9', '>10 <9')).toEqual(false);
expect(satisfiesVersionRequirement('9.5.4', '>=9.5.0 <10')).toEqual(true);
expect(satisfiesVersionRequirement('9.5.4', '>=9.5.4 <10')).toEqual(true);
expect(satisfiesVersionRequirement('9.5.4', '>8 <=9')).toEqual(true);
expect(satisfiesVersionRequirement('9.5.4', '>8 <9.6')).toEqual(true);
expect(satisfiesVersionRequirement('9.5.4', '>=9 <=9.5')).toEqual(true);
expect(satisfiesVersionRequirement('9.5.4', '>9 <9.5')).toEqual(false);
expect(satisfiesVersionRequirement('9.5.4', '>9.4.4 <9.5.4')).toEqual(false);
expect(satisfiesVersionRequirement('9.5.4', '<10 <9')).toEqual(false);
expect(satisfiesVersionRequirement('9.5.4', '>10 <9')).toEqual(false);
expect(satisfiesVersionRequirement('9.5.4', '=9 =9.5')).toEqual(true);
expect(satisfiesVersionRequirement('9.5.4', '=9 =9.5.5')).toEqual(false);
expect(satisfiesVersionRequirement('9.5.4', '=9 >=9.5 <9.6')).toEqual(true);
expect(satisfiesVersionRequirement('9.5.4', '=9 >=9.5 <9.6 =10')).toEqual(false);
});
it('should expectedly fail if the syntax is incorrect', function()
{
// It’s necessary to use a function as the argument here, because it would be directly
// evaluated otherwise, meaning that the thrown error wouldn’t be caught by Karma.
expect(() => satisfiesVersionRequirement('9.5.4', '==9')).toThrow();
expect(() => satisfiesVersionRequirement('9.5.4', '>=9 && <9.5')).toThrow();
expect(() => satisfiesVersionRequirement('9.5.4', '>=9<9.5')).toThrow();
});
});