OLD | NEW |
1 // Copyright (c) 2012, the Dart project authors. Please see the AUTHORS file | 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 | 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. | 3 // BSD-style license that can be found in the LICENSE file. |
4 | 4 |
5 library version_test; | 5 library version_test; |
6 | 6 |
7 import '../../../pkg/unittest/lib/unittest.dart'; | 7 import '../../../pkg/unittest/lib/unittest.dart'; |
8 import 'test_pub.dart'; | 8 import 'test_pub.dart'; |
9 import '../../pub/utils.dart'; | 9 import '../../pub/utils.dart'; |
10 import '../../pub/version.dart'; | 10 import '../../pub/version.dart'; |
11 | 11 |
12 main() { | 12 main() { |
| 13 initConfig(); |
| 14 |
13 final v123 = new Version.parse('1.2.3'); | 15 final v123 = new Version.parse('1.2.3'); |
14 final v114 = new Version.parse('1.1.4'); | 16 final v114 = new Version.parse('1.1.4'); |
15 final v124 = new Version.parse('1.2.4'); | 17 final v124 = new Version.parse('1.2.4'); |
16 final v200 = new Version.parse('2.0.0'); | 18 final v200 = new Version.parse('2.0.0'); |
17 final v234 = new Version.parse('2.3.4'); | 19 final v234 = new Version.parse('2.3.4'); |
18 final v250 = new Version.parse('2.5.0'); | 20 final v250 = new Version.parse('2.5.0'); |
19 final v300 = new Version.parse('3.0.0'); | 21 final v300 = new Version.parse('3.0.0'); |
20 | 22 |
21 group('Version', () { | 23 group('Version', () { |
22 test('none', () { | 24 test('none', () { |
(...skipping 356 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
379 var constraint = new VersionConstraint.parse('>1.0.0 >=1.2.3 <1.3.0'); | 381 var constraint = new VersionConstraint.parse('>1.0.0 >=1.2.3 <1.3.0'); |
380 expect(constraint, allows([ | 382 expect(constraint, allows([ |
381 new Version.parse('1.2.3'), | 383 new Version.parse('1.2.3'), |
382 new Version.parse('1.2.5')])); | 384 new Version.parse('1.2.5')])); |
383 expect(constraint, doesNotAllow([ | 385 expect(constraint, doesNotAllow([ |
384 new Version.parse('1.2.3-pre'), | 386 new Version.parse('1.2.3-pre'), |
385 new Version.parse('1.3.0'), | 387 new Version.parse('1.3.0'), |
386 new Version.parse('3.4.5')])); | 388 new Version.parse('3.4.5')])); |
387 }); | 389 }); |
388 | 390 |
| 391 test('ignores whitespace around operators', () { |
| 392 var constraint = new VersionConstraint.parse(' >1.0.0>=1.2.3 < 1.3.0'); |
| 393 expect(constraint, allows([ |
| 394 new Version.parse('1.2.3'), |
| 395 new Version.parse('1.2.5')])); |
| 396 expect(constraint, doesNotAllow([ |
| 397 new Version.parse('1.2.3-pre'), |
| 398 new Version.parse('1.3.0'), |
| 399 new Version.parse('3.4.5')])); |
| 400 }); |
| 401 |
| 402 test('does not allow "any" to be mixed with other constraints', () { |
| 403 expect(() => new VersionConstraint.parse('any 1.0.0'), |
| 404 throwsFormatException); |
| 405 }); |
| 406 |
389 test('throws FormatException on a bad string', () { | 407 test('throws FormatException on a bad string', () { |
390 expect(() => new VersionConstraint.parse(''), throwsFormatException); | 408 var bad = [ |
391 expect(() => new VersionConstraint.parse(' '), throwsFormatException); | 409 "", " ", // Empty string. |
392 expect(() => new VersionConstraint.parse('not a version'), | 410 "foo", // Bad text. |
393 throwsFormatException); | 411 ">foo", // Bad text after operator. |
| 412 "1.0.0 foo", "1.0.0foo", // Bad text after version. |
| 413 "anything", // Bad text after "any". |
| 414 "<>1.0.0", // Multiple operators. |
| 415 "1.0.0<" // Trailing operator. |
| 416 ]; |
| 417 |
| 418 for (var text in bad) { |
| 419 expect(() => new VersionConstraint.parse(text), |
| 420 throwsFormatException); |
| 421 } |
394 }); | 422 }); |
395 }); | 423 }); |
396 }); | 424 }); |
397 } | 425 } |
398 | 426 |
399 class VersionConstraintMatcher implements Matcher { | 427 class VersionConstraintMatcher implements Matcher { |
400 final List<Version> _expected; | 428 final List<Version> _expected; |
401 final bool _allow; | 429 final bool _allow; |
402 | 430 |
403 VersionConstraintMatcher(this._expected, this._allow); | 431 VersionConstraintMatcher(this._expected, this._allow); |
(...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
439 | 467 |
440 Matcher allows(List<Version> versions) => | 468 Matcher allows(List<Version> versions) => |
441 new VersionConstraintMatcher(versions, true); | 469 new VersionConstraintMatcher(versions, true); |
442 | 470 |
443 Matcher doesNotAllow(List<Version> versions) => | 471 Matcher doesNotAllow(List<Version> versions) => |
444 new VersionConstraintMatcher(versions, false); | 472 new VersionConstraintMatcher(versions, false); |
445 | 473 |
446 throwsIllegalArg(function) { | 474 throwsIllegalArg(function) { |
447 expect(function, throwsA((e) => e is ArgumentError)); | 475 expect(function, throwsA((e) => e is ArgumentError)); |
448 } | 476 } |
OLD | NEW |