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 'package:unittest/unittest.dart'; | 7 import 'package:unittest/unittest.dart'; |
8 import 'test_pub.dart'; | 8 import 'test_pub.dart'; |
9 import '../lib/src/utils.dart'; | 9 import '../lib/src/utils.dart'; |
10 import '../lib/src/version.dart'; | 10 import '../lib/src/version.dart'; |
(...skipping 412 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
423 }); | 423 }); |
424 }); | 424 }); |
425 } | 425 } |
426 | 426 |
427 class VersionConstraintMatcher implements Matcher { | 427 class VersionConstraintMatcher implements Matcher { |
428 final List<Version> _expected; | 428 final List<Version> _expected; |
429 final bool _allow; | 429 final bool _allow; |
430 | 430 |
431 VersionConstraintMatcher(this._expected, this._allow); | 431 VersionConstraintMatcher(this._expected, this._allow); |
432 | 432 |
433 bool matches(item, MatchState matchState) => (item is VersionConstraint) && | 433 bool matches(item, Map matchState) => (item is VersionConstraint) && |
434 _expected.every((version) => item.allows(version) == _allow); | 434 _expected.every((version) => item.allows(version) == _allow); |
435 | 435 |
436 Description describe(Description description) => | 436 Description describe(Description description) => |
437 description.add(' ${_allow ? "allows" : "does not allow"} versions'); | 437 description.add(' ${_allow ? "allows" : "does not allow"} versions'); |
438 | 438 |
439 Description describeMismatch(item, Description mismatchDescription, | 439 Description describeMismatch(item, Description mismatchDescription, |
440 MatchState matchState, bool verbose) { | 440 Map matchState, bool verbose) { |
441 if (item is! VersionConstraint) { | 441 if (item is! VersionConstraint) { |
442 mismatchDescription.add('was not a VersionConstraint'); | 442 mismatchDescription.add('was not a VersionConstraint'); |
443 return mismatchDescription; | 443 return mismatchDescription; |
444 } | 444 } |
445 | 445 |
446 bool first = true; | 446 bool first = true; |
447 for (var version in _expected) { | 447 for (var version in _expected) { |
448 if (item.allows(version) != _allow) { | 448 if (item.allows(version) != _allow) { |
449 if (first) { | 449 if (first) { |
450 if (_allow) { | 450 if (_allow) { |
(...skipping 16 matching lines...) Expand all Loading... |
467 | 467 |
468 Matcher allows(List<Version> versions) => | 468 Matcher allows(List<Version> versions) => |
469 new VersionConstraintMatcher(versions, true); | 469 new VersionConstraintMatcher(versions, true); |
470 | 470 |
471 Matcher doesNotAllow(List<Version> versions) => | 471 Matcher doesNotAllow(List<Version> versions) => |
472 new VersionConstraintMatcher(versions, false); | 472 new VersionConstraintMatcher(versions, false); |
473 | 473 |
474 throwsIllegalArg(function) { | 474 throwsIllegalArg(function) { |
475 expect(function, throwsA((e) => e is ArgumentError)); | 475 expect(function, throwsA((e) => e is ArgumentError)); |
476 } | 476 } |
OLD | NEW |