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 | |
389 test('throws FormatException on a bad string', () { | 402 test('throws FormatException on a bad string', () { |
390 expect(() => new VersionConstraint.parse(''), throwsFormatException); | 403 expect(() => new VersionConstraint.parse(''), throwsFormatException); |
391 expect(() => new VersionConstraint.parse(' '), throwsFormatException); | 404 expect(() => new VersionConstraint.parse(' '), throwsFormatException); |
392 expect(() => new VersionConstraint.parse('not a version'), | 405 expect(() => new VersionConstraint.parse('1.0.0 what is this here'), |
406 throwsFormatException); | |
407 | |
408 // Multiple operators. | |
409 expect(() => new VersionConstraint.parse('<>1.0.0'), | |
410 throwsFormatException); | |
411 | |
412 // "any" after operator. | |
413 expect(() => new VersionConstraint.parse('<any'), | |
414 throwsFormatException); | |
415 | |
416 // Trailing operator. | |
417 expect(() => new VersionConstraint.parse('1.0.0<'), | |
393 throwsFormatException); | 418 throwsFormatException); |
nweiz
2013/02/21 01:31:11
Other strings to test: "foo", "1.0.0foo", "anythin
Bob Nystrom
2013/02/21 20:00:50
Done.
| |
394 }); | 419 }); |
395 }); | 420 }); |
396 }); | 421 }); |
397 } | 422 } |
398 | 423 |
399 class VersionConstraintMatcher implements Matcher { | 424 class VersionConstraintMatcher implements Matcher { |
400 final List<Version> _expected; | 425 final List<Version> _expected; |
401 final bool _allow; | 426 final bool _allow; |
402 | 427 |
403 VersionConstraintMatcher(this._expected, this._allow); | 428 VersionConstraintMatcher(this._expected, this._allow); |
(...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
439 | 464 |
440 Matcher allows(List<Version> versions) => | 465 Matcher allows(List<Version> versions) => |
441 new VersionConstraintMatcher(versions, true); | 466 new VersionConstraintMatcher(versions, true); |
442 | 467 |
443 Matcher doesNotAllow(List<Version> versions) => | 468 Matcher doesNotAllow(List<Version> versions) => |
444 new VersionConstraintMatcher(versions, false); | 469 new VersionConstraintMatcher(versions, false); |
445 | 470 |
446 throwsIllegalArg(function) { | 471 throwsIllegalArg(function) { |
447 expect(function, throwsA((e) => e is ArgumentError)); | 472 expect(function, throwsA((e) => e is ArgumentError)); |
448 } | 473 } |
OLD | NEW |