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

Side by Side Diff: mojo/public/dart/third_party/pub_semver/test/utils.dart

Issue 1346773002: Stop running pub get at gclient sync time and fix build bugs (Closed) Base URL: git@github.com:domokit/mojo.git@master
Patch Set: Created 5 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
OLDNEW
(Empty)
1 // Copyright (c) 2014, 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 pub_semver.test.utils;
6
7 import 'package:test/test.dart';
8
9 import 'package:pub_semver/pub_semver.dart';
10
11 /// Some stock example versions to use in tests.
12 final v003 = new Version.parse('0.0.3');
13 final v010 = new Version.parse('0.1.0');
14 final v072 = new Version.parse('0.7.2');
15 final v080 = new Version.parse('0.8.0');
16 final v114 = new Version.parse('1.1.4');
17 final v123 = new Version.parse('1.2.3');
18 final v124 = new Version.parse('1.2.4');
19 final v130 = new Version.parse('1.3.0');
20 final v140 = new Version.parse('1.4.0');
21 final v200 = new Version.parse('2.0.0');
22 final v201 = new Version.parse('2.0.1');
23 final v234 = new Version.parse('2.3.4');
24 final v250 = new Version.parse('2.5.0');
25 final v300 = new Version.parse('3.0.0');
26
27 /// A [Matcher] that tests if a [VersionConstraint] allows or does not allow a
28 /// given list of [Version]s.
29 class _VersionConstraintMatcher implements Matcher {
30 final List<Version> _expected;
31 final bool _allow;
32
33 _VersionConstraintMatcher(this._expected, this._allow);
34
35 bool matches(item, Map matchState) => (item is VersionConstraint) &&
36 _expected.every((version) => item.allows(version) == _allow);
37
38 Description describe(Description description) {
39 description.addAll(' ${_allow ? "allows" : "does not allow"} versions ',
40 ', ', '', _expected);
41 return description;
42 }
43
44 Description describeMismatch(item, Description mismatchDescription,
45 Map matchState, bool verbose) {
46 if (item is! VersionConstraint) {
47 mismatchDescription.add('was not a VersionConstraint');
48 return mismatchDescription;
49 }
50
51 var first = true;
52 for (var version in _expected) {
53 if (item.allows(version) != _allow) {
54 if (first) {
55 if (_allow) {
56 mismatchDescription.addDescriptionOf(item).add(' did not allow ');
57 } else {
58 mismatchDescription.addDescriptionOf(item).add(' allowed ');
59 }
60 } else {
61 mismatchDescription.add(' and ');
62 }
63 first = false;
64
65 mismatchDescription.add(version.toString());
66 }
67 }
68
69 return mismatchDescription;
70 }
71 }
72
73 /// Gets a [Matcher] that validates that a [VersionConstraint] allows all
74 /// given versions.
75 Matcher allows(Version v1, [Version v2, Version v3, Version v4,
76 Version v5, Version v6, Version v7, Version v8]) {
77 var versions = _makeVersionList(v1, v2, v3, v4, v5, v6, v7, v8);
78 return new _VersionConstraintMatcher(versions, true);
79 }
80
81 /// Gets a [Matcher] that validates that a [VersionConstraint] allows none of
82 /// the given versions.
83 Matcher doesNotAllow(Version v1, [Version v2, Version v3, Version v4,
84 Version v5, Version v6, Version v7, Version v8]) {
85 var versions = _makeVersionList(v1, v2, v3, v4, v5, v6, v7, v8);
86 return new _VersionConstraintMatcher(versions, false);
87 }
88
89 List<Version> _makeVersionList(Version v1, [Version v2, Version v3, Version v4,
90 Version v5, Version v6, Version v7, Version v8]) {
91 var versions = [v1];
92 if (v2 != null) versions.add(v2);
93 if (v3 != null) versions.add(v3);
94 if (v4 != null) versions.add(v4);
95 if (v5 != null) versions.add(v5);
96 if (v6 != null) versions.add(v6);
97 if (v7 != null) versions.add(v7);
98 if (v8 != null) versions.add(v8);
99 return versions;
100 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698