spec.js
4.41 KB
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
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
var assert = require('chai').assert;
var semverutils = require('../semver-utils');
var deepOwnEqual = require('./deepOwnEqual');
describe('parse', function() {
it('should parse a simple 3-part version', function() {
deepOwnEqual(semverutils.parse('1.0.0'), {
semver: '1.0.0',
version: '1.0.0',
major: '1',
minor: '0',
patch: '0'
});
});
it('should parse pre-release versions', function() {
deepOwnEqual(semverutils.parse('1.0.0-alpha1'), {
semver: '1.0.0-alpha1',
version: '1.0.0',
major: '1',
minor: '0',
patch: '0',
release: 'alpha1'
});
});
it('should parse build numbers', function() {
deepOwnEqual(semverutils.parse('1.0.0+build-123'), {
semver: '1.0.0+build-123',
version: '1.0.0',
major: '1',
minor: '0',
patch: '0',
build: 'build-123'
});
});
it('should not parse invalid versions', function() {
assert.equal(semverutils.parse('a.b.c'), null);
assert.equal(semverutils.parse('1'), null);
assert.equal(semverutils.parse('1.0'), null);
assert.equal(semverutils.parse('1.0.0b'), null);
assert.equal(semverutils.parse('1.0.0+build-abc.'), null, 'trailing period');
});
});
describe('parseRange', function() {
it('should parse an exact version as a range', function() {
deepOwnEqual(semverutils.parseRange('1.0.0'), [{
semver: '1.0.0',
major: '1',
minor: '0',
patch: '0'
}]);
});
it('should ignore the v- prefix', function() {
deepOwnEqual(semverutils.parseRange('v1.0.0'), [{
semver: 'v1.0.0',
major: '1',
minor: '0',
patch: '0'
}]);
});
it('should parse a comparison operator', function() {
deepOwnEqual(semverutils.parseRange('< v2.0.0'), [{
semver: '< v2.0.0',
operator: '<',
major: '2',
minor: '0',
patch: '0'
}]);
});
it('should parse tilde', function() {
deepOwnEqual(semverutils.parseRange('~1.0.0'), [{
semver: '~1.0.0',
operator: '~',
major: '1',
minor: '0',
patch: '0'
}]);
});
it('should parse caret', function() {
deepOwnEqual(semverutils.parseRange('^1.0.0'), [{
semver: '^1.0.0',
operator: '^',
major: '1',
minor: '0',
patch: '0'
}]);
});
it('should parse tilde and v- prefix', function() {
deepOwnEqual(semverutils.parseRange('~v1.0.0'), [{
semver: '~v1.0.0',
operator: '~',
major: '1',
minor: '0',
patch: '0'
}]);
});
it('should parse ||', function() {
deepOwnEqual(semverutils.parseRange('~1.0.0 || ~2.0.0'), [{
semver: '~1.0.0',
operator: '~',
major: '1',
minor: '0',
patch: '0'
}, {
operator: '||'
}, {
semver: '~2.0.0',
operator: '~',
major: '2',
minor: '0',
patch: '0'
}]);
});
it('should parse build numbers', function() {
deepOwnEqual(semverutils.parseRange('2.0.0+build.1848'), [{
semver: '2.0.0+build.1848',
major: '2',
minor: '0',
patch: '0',
build: 'build.1848'
}]);
});
it('should parse pre-release versions', function() {
deepOwnEqual(semverutils.parseRange('1.0.0-rc1'), [{
semver: '1.0.0-rc1',
major: '1',
minor: '0',
patch: '0',
release: 'rc1'
}]);
});
it('should parse pre-release versions with hyphens', function() {
deepOwnEqual(semverutils.parseRange('1.0.0-rc-2'), [{
semver: '1.0.0-rc-2',
major: '1',
minor: '0',
patch: '0',
release: 'rc-2'
}]);
});
it('should parse hyphen ranges', function() {
deepOwnEqual(semverutils.parseRange('1.0.0 - 1.0.x'), [{
semver: '1.0.0',
major: '1',
minor: '0',
patch: '0'
}, {
operator: '-'
}, {
semver: '1.0.x',
major: '1',
minor: '0',
patch: 'x'
}]);
});
it('should parse constrained * ranges', function() {
deepOwnEqual(semverutils.parseRange('1.*'), [{
semver: '1.*',
major: '1',
minor: '*',
}]);
});
it('should parse constrained .x', function() {
deepOwnEqual(semverutils.parseRange('1.x'), [{
semver: '1.x',
major: '1',
minor: 'x',
}]);
});
it('should parse ~> ranges', function() {
deepOwnEqual(semverutils.parseRange('~> 2.0.0'), [{
semver: '~> 2.0.0',
operator: '~>',
major: '2',
minor: '0',
patch: '0'
}]);
});
});