Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(228)

Side by Side Diff: sdk/lib/_internal/pub_generated/test/version_test.dart

Issue 557563002: Store the async-await compiled pub code directly in the repo. (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Created 6 years, 3 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
1 // Copyright (c) 2012, the Dart project authors. Please see the AUTHORS file
2 // for details. All rights reserved. Use of this source code is governed by a
3 // BSD-style license that can be found in the LICENSE file.
4
5 library version_test; 1 library version_test;
6
7 import 'package:unittest/unittest.dart'; 2 import 'package:unittest/unittest.dart';
8 import 'test_pub.dart'; 3 import 'test_pub.dart';
9 import '../lib/src/version.dart'; 4 import '../lib/src/version.dart';
10
11 main() { 5 main() {
12 initConfig(); 6 initConfig();
13
14 final v114 = new Version.parse('1.1.4'); 7 final v114 = new Version.parse('1.1.4');
15 final v123 = new Version.parse('1.2.3'); 8 final v123 = new Version.parse('1.2.3');
16 final v124 = new Version.parse('1.2.4'); 9 final v124 = new Version.parse('1.2.4');
17 final v130 = new Version.parse('1.3.0'); 10 final v130 = new Version.parse('1.3.0');
18 final v140 = new Version.parse('1.4.0'); 11 final v140 = new Version.parse('1.4.0');
19 final v200 = new Version.parse('2.0.0'); 12 final v200 = new Version.parse('2.0.0');
20 final v201 = new Version.parse('2.0.1'); 13 final v201 = new Version.parse('2.0.1');
21 final v234 = new Version.parse('2.3.4'); 14 final v234 = new Version.parse('2.3.4');
22 final v250 = new Version.parse('2.5.0'); 15 final v250 = new Version.parse('2.5.0');
23 final v300 = new Version.parse('3.0.0'); 16 final v300 = new Version.parse('3.0.0');
24
25 group('Version', () { 17 group('Version', () {
26 test('none', () { 18 test('none', () {
27 expect(Version.none.toString(), equals('0.0.0')); 19 expect(Version.none.toString(), equals('0.0.0'));
28 }); 20 });
29
30 group('constructor', () { 21 group('constructor', () {
31 test('throws on negative numbers', () { 22 test('throws on negative numbers', () {
32 throwsIllegalArg(() => new Version(-1, 1, 1)); 23 throwsIllegalArg(() => new Version(-1, 1, 1));
33 throwsIllegalArg(() => new Version(1, -1, 1)); 24 throwsIllegalArg(() => new Version(1, -1, 1));
34 throwsIllegalArg(() => new Version(1, 1, -1)); 25 throwsIllegalArg(() => new Version(1, 1, -1));
35 }); 26 });
36 }); 27 });
37
38 group('comparison', () { 28 group('comparison', () {
39 // A correctly sorted list of versions.
40 var versions = [ 29 var versions = [
41 '1.0.0-alpha', 30 '1.0.0-alpha',
42 '1.0.0-alpha.1', 31 '1.0.0-alpha.1',
43 '1.0.0-beta.2', 32 '1.0.0-beta.2',
44 '1.0.0-beta.11', 33 '1.0.0-beta.11',
45 '1.0.0-rc.1', 34 '1.0.0-rc.1',
46 '1.0.0-rc.1+build.1', 35 '1.0.0-rc.1+build.1',
47 '1.0.0', 36 '1.0.0',
48 '1.0.0+0.3.7', 37 '1.0.0+0.3.7',
49 '1.3.7+build', 38 '1.3.7+build',
50 '1.3.7+build.2.b8f12d7', 39 '1.3.7+build.2.b8f12d7',
51 '1.3.7+build.11.e0f985a', 40 '1.3.7+build.11.e0f985a',
52 '2.0.0', 41 '2.0.0',
53 '2.1.0', 42 '2.1.0',
54 '2.2.0', 43 '2.2.0',
55 '2.11.0', 44 '2.11.0',
56 '2.11.1' 45 '2.11.1'];
57 ];
58
59 test('compareTo()', () { 46 test('compareTo()', () {
60 // Ensure that every pair of versions compares in the order that it
61 // appears in the list.
62 for (var i = 0; i < versions.length; i++) { 47 for (var i = 0; i < versions.length; i++) {
63 for (var j = 0; j < versions.length; j++) { 48 for (var j = 0; j < versions.length; j++) {
64 var a = new Version.parse(versions[i]); 49 var a = new Version.parse(versions[i]);
65 var b = new Version.parse(versions[j]); 50 var b = new Version.parse(versions[j]);
66 var expectation = i.compareTo(j); 51 var expectation = i.compareTo(j);
67 expect(a.compareTo(b), equals(expectation)); 52 expect(a.compareTo(b), equals(expectation));
68 } 53 }
69 } 54 }
70 }); 55 });
71
72 test('operators', () { 56 test('operators', () {
73 for (var i = 0; i < versions.length; i++) { 57 for (var i = 0; i < versions.length; i++) {
74 for (var j = 0; j < versions.length; j++) { 58 for (var j = 0; j < versions.length; j++) {
75 var a = new Version.parse(versions[i]); 59 var a = new Version.parse(versions[i]);
76 var b = new Version.parse(versions[j]); 60 var b = new Version.parse(versions[j]);
77 expect(a < b, equals(i < j)); 61 expect(a < b, equals(i < j));
78 expect(a > b, equals(i > j)); 62 expect(a > b, equals(i > j));
79 expect(a <= b, equals(i <= j)); 63 expect(a <= b, equals(i <= j));
80 expect(a >= b, equals(i >= j)); 64 expect(a >= b, equals(i >= j));
81 expect(a == b, equals(i == j)); 65 expect(a == b, equals(i == j));
82 expect(a != b, equals(i != j)); 66 expect(a != b, equals(i != j));
83 } 67 }
84 } 68 }
85 }); 69 });
86
87 test('equality', () { 70 test('equality', () {
88 expect(new Version.parse('01.2.3'), equals(new Version.parse('1.2.3'))); 71 expect(new Version.parse('01.2.3'), equals(new Version.parse('1.2.3')));
89 expect(new Version.parse('1.02.3'), equals(new Version.parse('1.2.3'))); 72 expect(new Version.parse('1.02.3'), equals(new Version.parse('1.2.3')));
90 expect(new Version.parse('1.2.03'), equals(new Version.parse('1.2.3'))); 73 expect(new Version.parse('1.2.03'), equals(new Version.parse('1.2.3')));
91 expect(new Version.parse('1.2.3-01'), 74 expect(
75 new Version.parse('1.2.3-01'),
92 equals(new Version.parse('1.2.3-1'))); 76 equals(new Version.parse('1.2.3-1')));
93 expect(new Version.parse('1.2.3+01'), 77 expect(
78 new Version.parse('1.2.3+01'),
94 equals(new Version.parse('1.2.3+1'))); 79 equals(new Version.parse('1.2.3+1')));
95 }); 80 });
96 }); 81 });
97
98 test('allows()', () { 82 test('allows()', () {
99 expect(v123.allows(v123), isTrue); 83 expect(v123.allows(v123), isTrue);
100 expect(v123.allows(v114), isFalse); 84 expect(v123.allows(v114), isFalse);
101 expect(v123.allows(v124), isFalse); 85 expect(v123.allows(v124), isFalse);
102 }); 86 });
103
104 test('intersect()', () { 87 test('intersect()', () {
105 // Intersecting the same version returns the version.
106 expect(v123.intersect(v123), equals(v123)); 88 expect(v123.intersect(v123), equals(v123));
107
108 // Intersecting a different version allows no versions.
109 expect(v123.intersect(v114).isEmpty, isTrue); 89 expect(v123.intersect(v114).isEmpty, isTrue);
110 90 expect(
111 // Intersecting a range returns the version if the range allows it. 91 v123.intersect(new VersionRange(min: v114, max: v124)),
112 expect(v123.intersect(new VersionRange(min: v114, max: v124)),
113 equals(v123)); 92 equals(v123));
114 93 expect(
115 // Intersecting a range allows no versions if the range doesn't allow it. 94 v114.intersect(new VersionRange(min: v123, max: v124)).isEmpty,
116 expect(v114.intersect(new VersionRange(min: v123, max: v124)).isEmpty,
117 isTrue); 95 isTrue);
118 }); 96 });
119
120 test('isEmpty', () { 97 test('isEmpty', () {
121 expect(v123.isEmpty, isFalse); 98 expect(v123.isEmpty, isFalse);
122 }); 99 });
123
124 test('nextMajor', () { 100 test('nextMajor', () {
125 expect(v123.nextMajor, equals(v200)); 101 expect(v123.nextMajor, equals(v200));
126 expect(v114.nextMajor, equals(v200)); 102 expect(v114.nextMajor, equals(v200));
127 expect(v200.nextMajor, equals(v300)); 103 expect(v200.nextMajor, equals(v300));
128
129 // Ignores pre-release if not on a major version.
130 expect(new Version.parse('1.2.3-dev').nextMajor, equals(v200)); 104 expect(new Version.parse('1.2.3-dev').nextMajor, equals(v200));
131
132 // Just removes it if on a major version.
133 expect(new Version.parse('2.0.0-dev').nextMajor, equals(v200)); 105 expect(new Version.parse('2.0.0-dev').nextMajor, equals(v200));
134
135 // Strips build suffix.
136 expect(new Version.parse('1.2.3+patch').nextMajor, equals(v200)); 106 expect(new Version.parse('1.2.3+patch').nextMajor, equals(v200));
137 }); 107 });
138
139 test('nextMinor', () { 108 test('nextMinor', () {
140 expect(v123.nextMinor, equals(v130)); 109 expect(v123.nextMinor, equals(v130));
141 expect(v130.nextMinor, equals(v140)); 110 expect(v130.nextMinor, equals(v140));
142
143 // Ignores pre-release if not on a minor version.
144 expect(new Version.parse('1.2.3-dev').nextMinor, equals(v130)); 111 expect(new Version.parse('1.2.3-dev').nextMinor, equals(v130));
145
146 // Just removes it if on a minor version.
147 expect(new Version.parse('1.3.0-dev').nextMinor, equals(v130)); 112 expect(new Version.parse('1.3.0-dev').nextMinor, equals(v130));
148
149 // Strips build suffix.
150 expect(new Version.parse('1.2.3+patch').nextMinor, equals(v130)); 113 expect(new Version.parse('1.2.3+patch').nextMinor, equals(v130));
151 }); 114 });
152
153 test('nextPatch', () { 115 test('nextPatch', () {
154 expect(v123.nextPatch, equals(v124)); 116 expect(v123.nextPatch, equals(v124));
155 expect(v200.nextPatch, equals(v201)); 117 expect(v200.nextPatch, equals(v201));
156
157 // Just removes pre-release version if present.
158 expect(new Version.parse('1.2.4-dev').nextPatch, equals(v124)); 118 expect(new Version.parse('1.2.4-dev').nextPatch, equals(v124));
159
160 // Strips build suffix.
161 expect(new Version.parse('1.2.3+patch').nextPatch, equals(v124)); 119 expect(new Version.parse('1.2.3+patch').nextPatch, equals(v124));
162 }); 120 });
163
164 test('parse()', () { 121 test('parse()', () {
165 expect(new Version.parse('0.0.0'), equals(new Version(0, 0, 0))); 122 expect(new Version.parse('0.0.0'), equals(new Version(0, 0, 0)));
166 expect(new Version.parse('12.34.56'), equals(new Version(12, 34, 56))); 123 expect(new Version.parse('12.34.56'), equals(new Version(12, 34, 56)));
167 124 expect(
168 expect(new Version.parse('1.2.3-alpha.1'), equals( 125 new Version.parse('1.2.3-alpha.1'),
169 new Version(1, 2, 3, pre: 'alpha.1'))); 126 equals(new Version(1, 2, 3, pre: 'alpha.1')));
170 expect(new Version.parse('1.2.3-x.7.z-92'), equals( 127 expect(
171 new Version(1, 2, 3, pre: 'x.7.z-92'))); 128 new Version.parse('1.2.3-x.7.z-92'),
172 129 equals(new Version(1, 2, 3, pre: 'x.7.z-92')));
173 expect(new Version.parse('1.2.3+build.1'), equals( 130 expect(
174 new Version(1, 2, 3, build: 'build.1'))); 131 new Version.parse('1.2.3+build.1'),
175 expect(new Version.parse('1.2.3+x.7.z-92'), equals( 132 equals(new Version(1, 2, 3, build: 'build.1')));
176 new Version(1, 2, 3, build: 'x.7.z-92'))); 133 expect(
177 134 new Version.parse('1.2.3+x.7.z-92'),
178 expect(new Version.parse('1.0.0-rc-1+build-1'), equals( 135 equals(new Version(1, 2, 3, build: 'x.7.z-92')));
179 new Version(1, 0, 0, pre: 'rc-1', build: 'build-1'))); 136 expect(
180 137 new Version.parse('1.0.0-rc-1+build-1'),
138 equals(new Version(1, 0, 0, pre: 'rc-1', build: 'build-1')));
181 expect(() => new Version.parse('1.0'), throwsFormatException); 139 expect(() => new Version.parse('1.0'), throwsFormatException);
182 expect(() => new Version.parse('1.2.3.4'), throwsFormatException); 140 expect(() => new Version.parse('1.2.3.4'), throwsFormatException);
183 expect(() => new Version.parse('1234'), throwsFormatException); 141 expect(() => new Version.parse('1234'), throwsFormatException);
184 expect(() => new Version.parse('-2.3.4'), throwsFormatException); 142 expect(() => new Version.parse('-2.3.4'), throwsFormatException);
185 expect(() => new Version.parse('1.3-pre'), throwsFormatException); 143 expect(() => new Version.parse('1.3-pre'), throwsFormatException);
186 expect(() => new Version.parse('1.3+build'), throwsFormatException); 144 expect(() => new Version.parse('1.3+build'), throwsFormatException);
187 expect(() => new Version.parse('1.3+bu?!3ild'), throwsFormatException); 145 expect(() => new Version.parse('1.3+bu?!3ild'), throwsFormatException);
188 }); 146 });
189
190 test('toString()', () { 147 test('toString()', () {
191 expect(new Version(0, 0, 0).toString(), equals('0.0.0')); 148 expect(new Version(0, 0, 0).toString(), equals('0.0.0'));
192 expect(new Version(12, 34, 56).toString(), equals('12.34.56')); 149 expect(new Version(12, 34, 56).toString(), equals('12.34.56'));
193 150 expect(
194 expect(new Version(1, 2, 3, pre: 'alpha.1').toString(), equals( 151 new Version(1, 2, 3, pre: 'alpha.1').toString(),
195 '1.2.3-alpha.1')); 152 equals('1.2.3-alpha.1'));
196 expect(new Version(1, 2, 3, pre: 'x.7.z-92').toString(), equals( 153 expect(
197 '1.2.3-x.7.z-92')); 154 new Version(1, 2, 3, pre: 'x.7.z-92').toString(),
198 155 equals('1.2.3-x.7.z-92'));
199 expect(new Version(1, 2, 3, build: 'build.1').toString(), equals( 156 expect(
200 '1.2.3+build.1')); 157 new Version(1, 2, 3, build: 'build.1').toString(),
201 expect(new Version(1, 2, 3, pre: 'pre', build: 'bui').toString(), equals( 158 equals('1.2.3+build.1'));
202 '1.2.3-pre+bui')); 159 expect(
160 new Version(1, 2, 3, pre: 'pre', build: 'bui').toString(),
161 equals('1.2.3-pre+bui'));
203 }); 162 });
204 }); 163 });
205
206 group('VersionRange', () { 164 group('VersionRange', () {
207 group('constructor', () { 165 group('constructor', () {
208 test('takes a min and max', () { 166 test('takes a min and max', () {
209 var range = new VersionRange(min: v123, max: v124); 167 var range = new VersionRange(min: v123, max: v124);
210 expect(range.isAny, isFalse); 168 expect(range.isAny, isFalse);
211 expect(range.min, equals(v123)); 169 expect(range.min, equals(v123));
212 expect(range.max, equals(v124)); 170 expect(range.max, equals(v124));
213 }); 171 });
214
215 test('allows omitting max', () { 172 test('allows omitting max', () {
216 var range = new VersionRange(min: v123); 173 var range = new VersionRange(min: v123);
217 expect(range.isAny, isFalse); 174 expect(range.isAny, isFalse);
218 expect(range.min, equals(v123)); 175 expect(range.min, equals(v123));
219 expect(range.max, isNull); 176 expect(range.max, isNull);
220 }); 177 });
221
222 test('allows omitting min and max', () { 178 test('allows omitting min and max', () {
223 var range = new VersionRange(); 179 var range = new VersionRange();
224 expect(range.isAny, isTrue); 180 expect(range.isAny, isTrue);
225 expect(range.min, isNull); 181 expect(range.min, isNull);
226 expect(range.max, isNull); 182 expect(range.max, isNull);
227 }); 183 });
228
229 test('takes includeMin', () { 184 test('takes includeMin', () {
230 var range = new VersionRange(min: v123, includeMin: true); 185 var range = new VersionRange(min: v123, includeMin: true);
231 expect(range.includeMin, isTrue); 186 expect(range.includeMin, isTrue);
232 }); 187 });
233
234 test('includeMin defaults to false if omitted', () { 188 test('includeMin defaults to false if omitted', () {
235 var range = new VersionRange(min: v123); 189 var range = new VersionRange(min: v123);
236 expect(range.includeMin, isFalse); 190 expect(range.includeMin, isFalse);
237 }); 191 });
238
239 test('takes includeMax', () { 192 test('takes includeMax', () {
240 var range = new VersionRange(max: v123, includeMax: true); 193 var range = new VersionRange(max: v123, includeMax: true);
241 expect(range.includeMax, isTrue); 194 expect(range.includeMax, isTrue);
242 }); 195 });
243
244 test('includeMax defaults to false if omitted', () { 196 test('includeMax defaults to false if omitted', () {
245 var range = new VersionRange(max: v123); 197 var range = new VersionRange(max: v123);
246 expect(range.includeMax, isFalse); 198 expect(range.includeMax, isFalse);
247 }); 199 });
248
249 test('throws if min > max', () { 200 test('throws if min > max', () {
250 throwsIllegalArg(() => new VersionRange(min: v124, max: v123)); 201 throwsIllegalArg(() => new VersionRange(min: v124, max: v123));
251 }); 202 });
252 }); 203 });
253
254 group('allows()', () { 204 group('allows()', () {
255 test('version must be greater than min', () { 205 test('version must be greater than min', () {
256 var range = new VersionRange(min: v123); 206 var range = new VersionRange(min: v123);
257
258 expect(range.allows(new Version.parse('1.2.2')), isFalse); 207 expect(range.allows(new Version.parse('1.2.2')), isFalse);
259 expect(range.allows(new Version.parse('1.2.3')), isFalse); 208 expect(range.allows(new Version.parse('1.2.3')), isFalse);
260 expect(range.allows(new Version.parse('1.3.3')), isTrue); 209 expect(range.allows(new Version.parse('1.3.3')), isTrue);
261 expect(range.allows(new Version.parse('2.3.3')), isTrue); 210 expect(range.allows(new Version.parse('2.3.3')), isTrue);
262 }); 211 });
263
264 test('version must be min or greater if includeMin', () { 212 test('version must be min or greater if includeMin', () {
265 var range = new VersionRange(min: v123, includeMin: true); 213 var range = new VersionRange(min: v123, includeMin: true);
266
267 expect(range.allows(new Version.parse('1.2.2')), isFalse); 214 expect(range.allows(new Version.parse('1.2.2')), isFalse);
268 expect(range.allows(new Version.parse('1.2.3')), isTrue); 215 expect(range.allows(new Version.parse('1.2.3')), isTrue);
269 expect(range.allows(new Version.parse('1.3.3')), isTrue); 216 expect(range.allows(new Version.parse('1.3.3')), isTrue);
270 expect(range.allows(new Version.parse('2.3.3')), isTrue); 217 expect(range.allows(new Version.parse('2.3.3')), isTrue);
271 }); 218 });
272
273 test('pre-release versions of inclusive min are excluded', () { 219 test('pre-release versions of inclusive min are excluded', () {
274 var range = new VersionRange(min: v123, includeMin: true); 220 var range = new VersionRange(min: v123, includeMin: true);
275
276 expect(range.allows(new Version.parse('1.2.3-dev')), isFalse); 221 expect(range.allows(new Version.parse('1.2.3-dev')), isFalse);
277 expect(range.allows(new Version.parse('1.2.4-dev')), isTrue); 222 expect(range.allows(new Version.parse('1.2.4-dev')), isTrue);
278 }); 223 });
279
280 test('version must be less than max', () { 224 test('version must be less than max', () {
281 var range = new VersionRange(max: v234); 225 var range = new VersionRange(max: v234);
282
283 expect(range.allows(new Version.parse('2.3.3')), isTrue); 226 expect(range.allows(new Version.parse('2.3.3')), isTrue);
284 expect(range.allows(new Version.parse('2.3.4')), isFalse); 227 expect(range.allows(new Version.parse('2.3.4')), isFalse);
285 expect(range.allows(new Version.parse('2.4.3')), isFalse); 228 expect(range.allows(new Version.parse('2.4.3')), isFalse);
286 }); 229 });
287
288 test('pre-release versions of non-pre-release max are excluded', () { 230 test('pre-release versions of non-pre-release max are excluded', () {
289 var range = new VersionRange(max: v234); 231 var range = new VersionRange(max: v234);
290
291 expect(range.allows(new Version.parse('2.3.3')), isTrue); 232 expect(range.allows(new Version.parse('2.3.3')), isTrue);
292 expect(range.allows(new Version.parse('2.3.4-dev')), isFalse); 233 expect(range.allows(new Version.parse('2.3.4-dev')), isFalse);
293 expect(range.allows(new Version.parse('2.3.4')), isFalse); 234 expect(range.allows(new Version.parse('2.3.4')), isFalse);
294 }); 235 });
295
296 test('pre-release versions of pre-release max are included', () { 236 test('pre-release versions of pre-release max are included', () {
297 var range = new VersionRange(max: new Version.parse('2.3.4-dev.2')); 237 var range = new VersionRange(max: new Version.parse('2.3.4-dev.2'));
298
299 expect(range.allows(new Version.parse('2.3.4-dev.1')), isTrue); 238 expect(range.allows(new Version.parse('2.3.4-dev.1')), isTrue);
300 expect(range.allows(new Version.parse('2.3.4-dev.2')), isFalse); 239 expect(range.allows(new Version.parse('2.3.4-dev.2')), isFalse);
301 expect(range.allows(new Version.parse('2.3.4-dev.3')), isFalse); 240 expect(range.allows(new Version.parse('2.3.4-dev.3')), isFalse);
302 }); 241 });
303
304 test('version must be max or less if includeMax', () { 242 test('version must be max or less if includeMax', () {
305 var range = new VersionRange(min: v123, max: v234, includeMax: true); 243 var range = new VersionRange(min: v123, max: v234, includeMax: true);
306
307 expect(range.allows(new Version.parse('2.3.3')), isTrue); 244 expect(range.allows(new Version.parse('2.3.3')), isTrue);
308 expect(range.allows(new Version.parse('2.3.4')), isTrue); 245 expect(range.allows(new Version.parse('2.3.4')), isTrue);
309 expect(range.allows(new Version.parse('2.4.3')), isFalse); 246 expect(range.allows(new Version.parse('2.4.3')), isFalse);
310
311 // Pre-releases of the max are allowed.
312 expect(range.allows(new Version.parse('2.3.4-dev')), isTrue); 247 expect(range.allows(new Version.parse('2.3.4-dev')), isTrue);
313 }); 248 });
314
315 test('has no min if one was not set', () { 249 test('has no min if one was not set', () {
316 var range = new VersionRange(max: v123); 250 var range = new VersionRange(max: v123);
317
318 expect(range.allows(new Version.parse('0.0.0')), isTrue); 251 expect(range.allows(new Version.parse('0.0.0')), isTrue);
319 expect(range.allows(new Version.parse('1.2.3')), isFalse); 252 expect(range.allows(new Version.parse('1.2.3')), isFalse);
320 }); 253 });
321
322 test('has no max if one was not set', () { 254 test('has no max if one was not set', () {
323 var range = new VersionRange(min: v123); 255 var range = new VersionRange(min: v123);
324
325 expect(range.allows(new Version.parse('1.2.3')), isFalse); 256 expect(range.allows(new Version.parse('1.2.3')), isFalse);
326 expect(range.allows(new Version.parse('1.3.3')), isTrue); 257 expect(range.allows(new Version.parse('1.3.3')), isTrue);
327 expect(range.allows(new Version.parse('999.3.3')), isTrue); 258 expect(range.allows(new Version.parse('999.3.3')), isTrue);
328 }); 259 });
329
330 test('allows any version if there is no min or max', () { 260 test('allows any version if there is no min or max', () {
331 var range = new VersionRange(); 261 var range = new VersionRange();
332
333 expect(range.allows(new Version.parse('0.0.0')), isTrue); 262 expect(range.allows(new Version.parse('0.0.0')), isTrue);
334 expect(range.allows(new Version.parse('999.99.9')), isTrue); 263 expect(range.allows(new Version.parse('999.99.9')), isTrue);
335 }); 264 });
336 }); 265 });
337
338 group('intersect()', () { 266 group('intersect()', () {
339 test('two overlapping ranges', () { 267 test('two overlapping ranges', () {
340 var a = new VersionRange(min: v123, max: v250); 268 var a = new VersionRange(min: v123, max: v250);
341 var b = new VersionRange(min: v200, max: v300); 269 var b = new VersionRange(min: v200, max: v300);
342 var intersect = a.intersect(b); 270 var intersect = a.intersect(b);
343 expect(intersect.min, equals(v200)); 271 expect(intersect.min, equals(v200));
344 expect(intersect.max, equals(v250)); 272 expect(intersect.max, equals(v250));
345 expect(intersect.includeMin, isFalse); 273 expect(intersect.includeMin, isFalse);
346 expect(intersect.includeMax, isFalse); 274 expect(intersect.includeMax, isFalse);
347 }); 275 });
348
349 test('a non-overlapping range allows no versions', () { 276 test('a non-overlapping range allows no versions', () {
350 var a = new VersionRange(min: v114, max: v124); 277 var a = new VersionRange(min: v114, max: v124);
351 var b = new VersionRange(min: v200, max: v250); 278 var b = new VersionRange(min: v200, max: v250);
352 expect(a.intersect(b).isEmpty, isTrue); 279 expect(a.intersect(b).isEmpty, isTrue);
353 }); 280 });
354
355 test('adjacent ranges allow no versions if exclusive', () { 281 test('adjacent ranges allow no versions if exclusive', () {
356 var a = new VersionRange(min: v114, max: v124, includeMax: false); 282 var a = new VersionRange(min: v114, max: v124, includeMax: false);
357 var b = new VersionRange(min: v124, max: v200, includeMin: true); 283 var b = new VersionRange(min: v124, max: v200, includeMin: true);
358 expect(a.intersect(b).isEmpty, isTrue); 284 expect(a.intersect(b).isEmpty, isTrue);
359 }); 285 });
360
361 test('adjacent ranges allow version if inclusive', () { 286 test('adjacent ranges allow version if inclusive', () {
362 var a = new VersionRange(min: v114, max: v124, includeMax: true); 287 var a = new VersionRange(min: v114, max: v124, includeMax: true);
363 var b = new VersionRange(min: v124, max: v200, includeMin: true); 288 var b = new VersionRange(min: v124, max: v200, includeMin: true);
364 expect(a.intersect(b), equals(v124)); 289 expect(a.intersect(b), equals(v124));
365 }); 290 });
366
367 test('with an open range', () { 291 test('with an open range', () {
368 var open = new VersionRange(); 292 var open = new VersionRange();
369 var a = new VersionRange(min: v114, max: v124); 293 var a = new VersionRange(min: v114, max: v124);
370 expect(open.intersect(open), equals(open)); 294 expect(open.intersect(open), equals(open));
371 expect(a.intersect(open), equals(a)); 295 expect(a.intersect(open), equals(a));
372 }); 296 });
373
374 test('returns the version if the range allows it', () { 297 test('returns the version if the range allows it', () {
375 expect(new VersionRange(min: v114, max: v124).intersect(v123), 298 expect(
299 new VersionRange(min: v114, max: v124).intersect(v123),
376 equals(v123)); 300 equals(v123));
377 expect(new VersionRange(min: v123, max: v124).intersect(v114).isEmpty, 301 expect(
302 new VersionRange(min: v123, max: v124).intersect(v114).isEmpty,
378 isTrue); 303 isTrue);
379 }); 304 });
380 }); 305 });
381
382 test('isEmpty', () { 306 test('isEmpty', () {
383 expect(new VersionRange().isEmpty, isFalse); 307 expect(new VersionRange().isEmpty, isFalse);
384 expect(new VersionRange(min: v123, max: v124).isEmpty, isFalse); 308 expect(new VersionRange(min: v123, max: v124).isEmpty, isFalse);
385 }); 309 });
386 }); 310 });
387
388 group('VersionConstraint', () { 311 group('VersionConstraint', () {
389 test('any', () { 312 test('any', () {
390 expect(VersionConstraint.any.isAny, isTrue); 313 expect(VersionConstraint.any.isAny, isTrue);
391 expect(VersionConstraint.any, allows([ 314 expect(
392 new Version.parse('0.0.0-blah'), 315 VersionConstraint.any,
393 new Version.parse('1.2.3'), 316 allows(
394 new Version.parse('12345.678.90')])); 317 [
318 new Version.parse('0.0.0-blah'),
319 new Version.parse('1.2.3'),
320 new Version.parse('12345.678.90')]));
395 }); 321 });
396
397 test('empty', () { 322 test('empty', () {
398 expect(VersionConstraint.empty.isEmpty, isTrue); 323 expect(VersionConstraint.empty.isEmpty, isTrue);
399 expect(VersionConstraint.empty.isAny, isFalse); 324 expect(VersionConstraint.empty.isAny, isFalse);
400 expect(VersionConstraint.empty, doesNotAllow([ 325 expect(
401 new Version.parse('0.0.0-blah'), 326 VersionConstraint.empty,
402 new Version.parse('1.2.3'), 327 doesNotAllow(
403 new Version.parse('12345.678.90')])); 328 [
329 new Version.parse('0.0.0-blah'),
330 new Version.parse('1.2.3'),
331 new Version.parse('12345.678.90')]));
404 }); 332 });
405
406 group('parse()', () { 333 group('parse()', () {
407 test('parses an exact version', () { 334 test('parses an exact version', () {
408 var constraint = new VersionConstraint.parse('1.2.3-alpha'); 335 var constraint = new VersionConstraint.parse('1.2.3-alpha');
409 expect(constraint is Version, isTrue); 336 expect(constraint is Version, isTrue);
410 expect(constraint, equals(new Version(1, 2, 3, pre: 'alpha'))); 337 expect(constraint, equals(new Version(1, 2, 3, pre: 'alpha')));
411 }); 338 });
412
413 test('parses "any"', () { 339 test('parses "any"', () {
414 var constraint = new VersionConstraint.parse('any'); 340 var constraint = new VersionConstraint.parse('any');
415 expect(constraint is VersionConstraint, isTrue); 341 expect(constraint is VersionConstraint, isTrue);
416 expect(constraint, allows([ 342 expect(
417 new Version.parse('0.0.0'), 343 constraint,
418 new Version.parse('1.2.3'), 344 allows(
419 new Version.parse('12345.678.90')])); 345 [
346 new Version.parse('0.0.0'),
347 new Version.parse('1.2.3'),
348 new Version.parse('12345.678.90')]));
420 }); 349 });
421
422 test('parses a ">" minimum version', () { 350 test('parses a ">" minimum version', () {
423 expect(new VersionConstraint.parse('>1.2.3'), allows([ 351 expect(
424 new Version.parse('1.2.3+foo'), 352 new VersionConstraint.parse('>1.2.3'),
425 new Version.parse('1.2.4')])); 353 allows([new Version.parse('1.2.3+foo'), new Version.parse('1.2.4')]) );
426 expect(new VersionConstraint.parse('>1.2.3'), doesNotAllow([ 354 expect(
427 new Version.parse('1.2.1'), 355 new VersionConstraint.parse('>1.2.3'),
428 new Version.parse('1.2.3-build'), 356 doesNotAllow(
429 new Version.parse('1.2.3')])); 357 [
358 new Version.parse('1.2.1'),
359 new Version.parse('1.2.3-build'),
360 new Version.parse('1.2.3')]));
430 }); 361 });
431
432 test('parses a ">=" minimum version', () { 362 test('parses a ">=" minimum version', () {
433 expect(new VersionConstraint.parse('>=1.2.3'), allows([ 363 expect(
434 new Version.parse('1.2.3'), 364 new VersionConstraint.parse('>=1.2.3'),
435 new Version.parse('1.2.3+foo'), 365 allows(
436 new Version.parse('1.2.4')])); 366 [
437 expect(new VersionConstraint.parse('>=1.2.3'), doesNotAllow([ 367 new Version.parse('1.2.3'),
438 new Version.parse('1.2.1'), 368 new Version.parse('1.2.3+foo'),
439 new Version.parse('1.2.3-build')])); 369 new Version.parse('1.2.4')]));
370 expect(
371 new VersionConstraint.parse('>=1.2.3'),
372 doesNotAllow([new Version.parse('1.2.1'), new Version.parse('1.2.3-b uild')]));
440 }); 373 });
441
442 test('parses a "<" maximum version', () { 374 test('parses a "<" maximum version', () {
443 expect(new VersionConstraint.parse('<1.2.3'), allows([ 375 expect(
444 new Version.parse('1.2.1'), 376 new VersionConstraint.parse('<1.2.3'),
445 new Version.parse('1.2.2+foo')])); 377 allows([new Version.parse('1.2.1'), new Version.parse('1.2.2+foo')]) );
446 expect(new VersionConstraint.parse('<1.2.3'), doesNotAllow([ 378 expect(
447 new Version.parse('1.2.3'), 379 new VersionConstraint.parse('<1.2.3'),
448 new Version.parse('1.2.3+foo'), 380 doesNotAllow(
449 new Version.parse('1.2.4')])); 381 [
382 new Version.parse('1.2.3'),
383 new Version.parse('1.2.3+foo'),
384 new Version.parse('1.2.4')]));
450 }); 385 });
451
452 test('parses a "<=" maximum version', () { 386 test('parses a "<=" maximum version', () {
453 expect(new VersionConstraint.parse('<=1.2.3'), allows([ 387 expect(
454 new Version.parse('1.2.1'), 388 new VersionConstraint.parse('<=1.2.3'),
455 new Version.parse('1.2.3-build'), 389 allows(
456 new Version.parse('1.2.3')])); 390 [
457 expect(new VersionConstraint.parse('<=1.2.3'), doesNotAllow([ 391 new Version.parse('1.2.1'),
458 new Version.parse('1.2.3+foo'), 392 new Version.parse('1.2.3-build'),
459 new Version.parse('1.2.4')])); 393 new Version.parse('1.2.3')]));
394 expect(
395 new VersionConstraint.parse('<=1.2.3'),
396 doesNotAllow([new Version.parse('1.2.3+foo'), new Version.parse('1.2 .4')]));
460 }); 397 });
461
462 test('parses a series of space-separated constraints', () { 398 test('parses a series of space-separated constraints', () {
463 var constraint = new VersionConstraint.parse('>1.0.0 >=1.2.3 <1.3.0'); 399 var constraint = new VersionConstraint.parse('>1.0.0 >=1.2.3 <1.3.0');
464 expect(constraint, allows([ 400 expect(
465 new Version.parse('1.2.3'), 401 constraint,
466 new Version.parse('1.2.5')])); 402 allows([new Version.parse('1.2.3'), new Version.parse('1.2.5')]));
467 expect(constraint, doesNotAllow([ 403 expect(
468 new Version.parse('1.2.3-pre'), 404 constraint,
469 new Version.parse('1.3.0'), 405 doesNotAllow(
470 new Version.parse('3.4.5')])); 406 [
407 new Version.parse('1.2.3-pre'),
408 new Version.parse('1.3.0'),
409 new Version.parse('3.4.5')]));
471 }); 410 });
472
473 test('ignores whitespace around operators', () { 411 test('ignores whitespace around operators', () {
474 var constraint = new VersionConstraint.parse(' >1.0.0>=1.2.3 < 1.3.0'); 412 var constraint = new VersionConstraint.parse(' >1.0.0>=1.2.3 < 1.3.0');
475 expect(constraint, allows([ 413 expect(
476 new Version.parse('1.2.3'), 414 constraint,
477 new Version.parse('1.2.5')])); 415 allows([new Version.parse('1.2.3'), new Version.parse('1.2.5')]));
478 expect(constraint, doesNotAllow([ 416 expect(
479 new Version.parse('1.2.3-pre'), 417 constraint,
480 new Version.parse('1.3.0'), 418 doesNotAllow(
481 new Version.parse('3.4.5')])); 419 [
420 new Version.parse('1.2.3-pre'),
421 new Version.parse('1.3.0'),
422 new Version.parse('3.4.5')]));
482 }); 423 });
483
484 test('does not allow "any" to be mixed with other constraints', () { 424 test('does not allow "any" to be mixed with other constraints', () {
485 expect(() => new VersionConstraint.parse('any 1.0.0'), 425 expect(
426 () => new VersionConstraint.parse('any 1.0.0'),
486 throwsFormatException); 427 throwsFormatException);
487 }); 428 });
488
489 test('throws FormatException on a bad string', () { 429 test('throws FormatException on a bad string', () {
490 var bad = [ 430 var bad = [
491 "", " ", // Empty string. 431 "",
492 "foo", // Bad text. 432 " ",
493 ">foo", // Bad text after operator. 433 "foo",
494 "1.0.0 foo", "1.0.0foo", // Bad text after version. 434 ">foo",
495 "anything", // Bad text after "any". 435 "1.0.0 foo",
496 "<>1.0.0", // Multiple operators. 436 "1.0.0foo",
497 "1.0.0<" // Trailing operator. 437 "anything",
498 ]; 438 "<>1.0.0",
499 439 "1.0.0<"];
500 for (var text in bad) { 440 for (var text in bad) {
501 expect(() => new VersionConstraint.parse(text), 441 expect(
442 () => new VersionConstraint.parse(text),
502 throwsFormatException); 443 throwsFormatException);
503 } 444 }
504 }); 445 });
505 }); 446 });
506 }); 447 });
507 } 448 }
508
509 class VersionConstraintMatcher implements Matcher { 449 class VersionConstraintMatcher implements Matcher {
510 final List<Version> _expected; 450 final List<Version> _expected;
511 final bool _allow; 451 final bool _allow;
512
513 VersionConstraintMatcher(this._expected, this._allow); 452 VersionConstraintMatcher(this._expected, this._allow);
514 453 bool matches(item, Map matchState) =>
515 bool matches(item, Map matchState) => (item is VersionConstraint) && 454 (item is VersionConstraint) &&
516 _expected.every((version) => item.allows(version) == _allow); 455 _expected.every((version) => item.allows(version) == _allow);
517
518 Description describe(Description description) => 456 Description describe(Description description) =>
519 description.add(' ${_allow ? "allows" : "does not allow"} versions'); 457 description.add(' ${_allow ? "allows" : "does not allow"} versions');
520
521 Description describeMismatch(item, Description mismatchDescription, 458 Description describeMismatch(item, Description mismatchDescription,
522 Map matchState, bool verbose) { 459 Map matchState, bool verbose) {
523 if (item is! VersionConstraint) { 460 if (item is! VersionConstraint) {
524 mismatchDescription.add('was not a VersionConstraint'); 461 mismatchDescription.add('was not a VersionConstraint');
525 return mismatchDescription; 462 return mismatchDescription;
526 } 463 }
527
528 bool first = true; 464 bool first = true;
529 for (var version in _expected) { 465 for (var version in _expected) {
530 if (item.allows(version) != _allow) { 466 if (item.allows(version) != _allow) {
531 if (first) { 467 if (first) {
532 if (_allow) { 468 if (_allow) {
533 mismatchDescription.addDescriptionOf(item).add('did not allow '); 469 mismatchDescription.addDescriptionOf(item).add('did not allow ');
534 } else { 470 } else {
535 mismatchDescription.addDescriptionOf(item).add('allowed '); 471 mismatchDescription.addDescriptionOf(item).add('allowed ');
536 } 472 }
537 } else { 473 } else {
538 mismatchDescription.add(' and '); 474 mismatchDescription.add(' and ');
539 } 475 }
540 first = false; 476 first = false;
541
542 mismatchDescription.add(version.toString()); 477 mismatchDescription.add(version.toString());
543 } 478 }
544 } 479 }
545
546 return mismatchDescription; 480 return mismatchDescription;
547 } 481 }
548 } 482 }
549
550 Matcher allows(List<Version> versions) => 483 Matcher allows(List<Version> versions) =>
551 new VersionConstraintMatcher(versions, true); 484 new VersionConstraintMatcher(versions, true);
552
553 Matcher doesNotAllow(List<Version> versions) => 485 Matcher doesNotAllow(List<Version> versions) =>
554 new VersionConstraintMatcher(versions, false); 486 new VersionConstraintMatcher(versions, false);
555
556 throwsIllegalArg(function) { 487 throwsIllegalArg(function) {
557 expect(function, throwsA((e) => e is ArgumentError)); 488 expect(function, throwsA((e) => e is ArgumentError));
558 } 489 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698