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

Side by Side Diff: test/version_constraint_test.dart

Issue 607663002: Harvest from pub. Mostly a straight copy, except: (Closed) Base URL: https://github.com/dart-lang/pub_semver.git@master
Patch Set: Revise! Created 6 years, 2 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
« no previous file with comments | « test/utils.dart ('k') | test/version_range_test.dart » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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:unittest/unittest.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 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('throws FormatException on a bad string', () {
127 var bad = [
128 "", " ", // Empty string.
129 "foo", // Bad text.
130 ">foo", // Bad text after operator.
131 "1.0.0 foo", "1.0.0foo", // Bad text after version.
132 "anything", // Bad text after "any".
133 "<>1.0.0", // Multiple operators.
134 "1.0.0<" // Trailing operator.
135 ];
136
137 for (var text in bad) {
138 expect(() => new VersionConstraint.parse(text),
139 throwsFormatException);
140 }
141 });
142 });
143 }
OLDNEW
« no previous file with comments | « test/utils.dart ('k') | test/version_range_test.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698