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

Side by Side Diff: mojo/public/dart/third_party/pub_semver/test/version_constraint_test.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.version_constraint_test;
6
7 import 'package:test/test.dart';
8
9 import 'package:pub_semver/pub_semver.dart';
10
11 import 'utils.dart';
12
13 main() {
14 test('any', () {
15 expect(VersionConstraint.any.isAny, isTrue);
16 expect(VersionConstraint.any, allows(
17 new Version.parse('0.0.0-blah'),
18 new Version.parse('1.2.3'),
19 new Version.parse('12345.678.90')));
20 });
21
22 test('empty', () {
23 expect(VersionConstraint.empty.isEmpty, isTrue);
24 expect(VersionConstraint.empty.isAny, isFalse);
25 expect(VersionConstraint.empty, doesNotAllow(
26 new Version.parse('0.0.0-blah'),
27 new Version.parse('1.2.3'),
28 new Version.parse('12345.678.90')));
29 });
30
31 group('parse()', () {
32 test('parses an exact version', () {
33 var constraint = new VersionConstraint.parse('1.2.3-alpha');
34
35 expect(constraint is Version, isTrue);
36 expect(constraint, equals(new Version(1, 2, 3, pre: 'alpha')));
37 });
38
39 test('parses "any"', () {
40 var constraint = new VersionConstraint.parse('any');
41
42 expect(constraint is VersionConstraint, isTrue);
43 expect(constraint, allows(
44 new Version.parse('0.0.0'),
45 new Version.parse('1.2.3'),
46 new Version.parse('12345.678.90')));
47 });
48
49 test('parses a ">" minimum version', () {
50 var constraint = new VersionConstraint.parse('>1.2.3');
51
52 expect(constraint, allows(
53 new Version.parse('1.2.3+foo'),
54 new Version.parse('1.2.4')));
55 expect(constraint, doesNotAllow(
56 new Version.parse('1.2.1'),
57 new Version.parse('1.2.3-build'),
58 new Version.parse('1.2.3')));
59 });
60
61 test('parses a ">=" minimum version', () {
62 var constraint = new VersionConstraint.parse('>=1.2.3');
63
64 expect(constraint, allows(
65 new Version.parse('1.2.3'),
66 new Version.parse('1.2.3+foo'),
67 new Version.parse('1.2.4')));
68 expect(constraint, doesNotAllow(
69 new Version.parse('1.2.1'),
70 new Version.parse('1.2.3-build')));
71 });
72
73 test('parses a "<" maximum version', () {
74 var constraint = new VersionConstraint.parse('<1.2.3');
75
76 expect(constraint, allows(
77 new Version.parse('1.2.1'),
78 new Version.parse('1.2.2+foo')));
79 expect(constraint, doesNotAllow(
80 new Version.parse('1.2.3'),
81 new Version.parse('1.2.3+foo'),
82 new Version.parse('1.2.4')));
83 });
84
85 test('parses a "<=" maximum version', () {
86 var constraint = new VersionConstraint.parse('<=1.2.3');
87
88 expect(constraint, allows(
89 new Version.parse('1.2.1'),
90 new Version.parse('1.2.3-build'),
91 new Version.parse('1.2.3')));
92 expect(constraint, doesNotAllow(
93 new Version.parse('1.2.3+foo'),
94 new Version.parse('1.2.4')));
95 });
96
97 test('parses a series of space-separated constraints', () {
98 var constraint = new VersionConstraint.parse('>1.0.0 >=1.2.3 <1.3.0');
99
100 expect(constraint, allows(
101 new Version.parse('1.2.3'),
102 new Version.parse('1.2.5')));
103 expect(constraint, doesNotAllow(
104 new Version.parse('1.2.3-pre'),
105 new Version.parse('1.3.0'),
106 new Version.parse('3.4.5')));
107 });
108
109 test('ignores whitespace around comparison operators', () {
110 var constraint = new VersionConstraint.parse(' >1.0.0>=1.2.3 < 1.3.0');
111
112 expect(constraint, allows(
113 new Version.parse('1.2.3'),
114 new Version.parse('1.2.5')));
115 expect(constraint, doesNotAllow(
116 new Version.parse('1.2.3-pre'),
117 new Version.parse('1.3.0'),
118 new Version.parse('3.4.5')));
119 });
120
121 test('does not allow "any" to be mixed with other constraints', () {
122 expect(() => new VersionConstraint.parse('any 1.0.0'),
123 throwsFormatException);
124 });
125
126 test('parses a "^" version', () {
127 expect(new VersionConstraint.parse('^0.0.3'), equals(
128 new VersionConstraint.compatibleWith(v003)));
129
130 expect(new VersionConstraint.parse('^0.7.2'), equals(
131 new VersionConstraint.compatibleWith(v072)));
132
133 expect(new VersionConstraint.parse('^1.2.3'), equals(
134 new VersionConstraint.compatibleWith(v123)));
135
136 var min = new Version.parse('0.7.2-pre+1');
137 expect(new VersionConstraint.parse('^0.7.2-pre+1'), equals(
138 new VersionConstraint.compatibleWith(min)));
139 });
140
141 test('does not allow "^" to be mixed with other constraints', () {
142 expect(() => new VersionConstraint.parse('>=1.2.3 ^1.0.0'),
143 throwsFormatException);
144 expect(() => new VersionConstraint.parse('^1.0.0 <1.2.3'),
145 throwsFormatException);
146 });
147
148 test('ignores whitespace around "^"', () {
149 var constraint = new VersionConstraint.parse(' ^ 1.2.3 ');
150
151 expect(constraint, equals(
152 new VersionConstraint.compatibleWith(v123)));
153 });
154
155 test('throws FormatException on a bad string', () {
156 var bad = [
157 "", " ", // Empty string.
158 "foo", // Bad text.
159 ">foo", // Bad text after operator.
160 "^foo", // Bad text after "^".
161 "1.0.0 foo", "1.0.0foo", // Bad text after version.
162 "anything", // Bad text after "any".
163 "<>1.0.0", // Multiple operators.
164 "1.0.0<" // Trailing operator.
165 ];
166
167 for (var text in bad) {
168 expect(() => new VersionConstraint.parse(text),
169 throwsFormatException);
170 }
171 });
172 });
173
174 group('compatibleWith()', () {
175 test('returns the range of compatible versions', () {
176 var constraint = new VersionConstraint.compatibleWith(v072);
177
178 expect(constraint, equals(new VersionRange(min: v072, includeMin: true,
179 max: v072.nextBreaking)));
180 });
181
182 test('toString() uses "^"', () {
183 var constraint = new VersionConstraint.compatibleWith(v072);
184
185 expect(constraint.toString(), equals('^0.7.2'));
186 });
187 });
188 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698