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/version.dart'; | 9 import '../lib/src/version.dart'; |
10 | 10 |
11 main() { | 11 main() { |
12 initConfig(); | 12 initConfig(); |
13 | 13 |
| 14 final v114 = new Version.parse('1.1.4'); |
14 final v123 = new Version.parse('1.2.3'); | 15 final v123 = new Version.parse('1.2.3'); |
15 final v114 = new Version.parse('1.1.4'); | |
16 final v124 = new Version.parse('1.2.4'); | 16 final v124 = new Version.parse('1.2.4'); |
| 17 final v130 = new Version.parse('1.3.0'); |
| 18 final v140 = new Version.parse('1.4.0'); |
17 final v200 = new Version.parse('2.0.0'); | 19 final v200 = new Version.parse('2.0.0'); |
| 20 final v201 = new Version.parse('2.0.1'); |
18 final v234 = new Version.parse('2.3.4'); | 21 final v234 = new Version.parse('2.3.4'); |
19 final v250 = new Version.parse('2.5.0'); | 22 final v250 = new Version.parse('2.5.0'); |
20 final v300 = new Version.parse('3.0.0'); | 23 final v300 = new Version.parse('3.0.0'); |
21 | 24 |
22 group('Version', () { | 25 group('Version', () { |
23 test('none', () { | 26 test('none', () { |
24 expect(Version.none.toString(), equals('0.0.0')); | 27 expect(Version.none.toString(), equals('0.0.0')); |
25 }); | 28 }); |
26 | 29 |
27 group('constructor', () { | 30 group('constructor', () { |
(...skipping 83 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
111 | 114 |
112 // Intersecting a range allows no versions if the range doesn't allow it. | 115 // Intersecting a range allows no versions if the range doesn't allow it. |
113 expect(v114.intersect(new VersionRange(min: v123, max: v124)).isEmpty, | 116 expect(v114.intersect(new VersionRange(min: v123, max: v124)).isEmpty, |
114 isTrue); | 117 isTrue); |
115 }); | 118 }); |
116 | 119 |
117 test('isEmpty', () { | 120 test('isEmpty', () { |
118 expect(v123.isEmpty, isFalse); | 121 expect(v123.isEmpty, isFalse); |
119 }); | 122 }); |
120 | 123 |
| 124 test('nextMajor', () { |
| 125 expect(v123.nextMajor, equals(v200)); |
| 126 expect(v114.nextMajor, equals(v200)); |
| 127 expect(v200.nextMajor, equals(v300)); |
| 128 |
| 129 // Ignores pre-release if not on a major version. |
| 130 expect(new Version.parse('1.2.3-dev').nextMajor, equals(v200)); |
| 131 |
| 132 // Just removes it if on a major version. |
| 133 expect(new Version.parse('2.0.0-dev').nextMajor, equals(v200)); |
| 134 |
| 135 // Strips build suffix. |
| 136 expect(new Version.parse('1.2.3+patch').nextMajor, equals(v200)); |
| 137 }); |
| 138 |
| 139 test('nextMinor', () { |
| 140 expect(v123.nextMinor, equals(v130)); |
| 141 expect(v130.nextMinor, equals(v140)); |
| 142 |
| 143 // Ignores pre-release if not on a minor version. |
| 144 expect(new Version.parse('1.2.3-dev').nextMinor, equals(v130)); |
| 145 |
| 146 // Just removes it if on a minor version. |
| 147 expect(new Version.parse('1.3.0-dev').nextMinor, equals(v130)); |
| 148 |
| 149 // Strips build suffix. |
| 150 expect(new Version.parse('1.2.3+patch').nextMinor, equals(v130)); |
| 151 }); |
| 152 |
| 153 test('nextPatch', () { |
| 154 expect(v123.nextPatch, equals(v124)); |
| 155 expect(v200.nextPatch, equals(v201)); |
| 156 |
| 157 // Just removes pre-release version if present. |
| 158 expect(new Version.parse('1.2.4-dev').nextPatch, equals(v124)); |
| 159 |
| 160 // Strips build suffix. |
| 161 expect(new Version.parse('1.2.3+patch').nextPatch, equals(v124)); |
| 162 }); |
| 163 |
121 test('parse()', () { | 164 test('parse()', () { |
122 expect(new Version.parse('0.0.0'), equals(new Version(0, 0, 0))); | 165 expect(new Version.parse('0.0.0'), equals(new Version(0, 0, 0))); |
123 expect(new Version.parse('12.34.56'), equals(new Version(12, 34, 56))); | 166 expect(new Version.parse('12.34.56'), equals(new Version(12, 34, 56))); |
124 | 167 |
125 expect(new Version.parse('1.2.3-alpha.1'), equals( | 168 expect(new Version.parse('1.2.3-alpha.1'), equals( |
126 new Version(1, 2, 3, pre: 'alpha.1'))); | 169 new Version(1, 2, 3, pre: 'alpha.1'))); |
127 expect(new Version.parse('1.2.3-x.7.z-92'), equals( | 170 expect(new Version.parse('1.2.3-x.7.z-92'), equals( |
128 new Version(1, 2, 3, pre: 'x.7.z-92'))); | 171 new Version(1, 2, 3, pre: 'x.7.z-92'))); |
129 | 172 |
130 expect(new Version.parse('1.2.3+build.1'), equals( | 173 expect(new Version.parse('1.2.3+build.1'), equals( |
(...skipping 345 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
476 | 519 |
477 Matcher allows(List<Version> versions) => | 520 Matcher allows(List<Version> versions) => |
478 new VersionConstraintMatcher(versions, true); | 521 new VersionConstraintMatcher(versions, true); |
479 | 522 |
480 Matcher doesNotAllow(List<Version> versions) => | 523 Matcher doesNotAllow(List<Version> versions) => |
481 new VersionConstraintMatcher(versions, false); | 524 new VersionConstraintMatcher(versions, false); |
482 | 525 |
483 throwsIllegalArg(function) { | 526 throwsIllegalArg(function) { |
484 expect(function, throwsA((e) => e is ArgumentError)); | 527 expect(function, throwsA((e) => e is ArgumentError)); |
485 } | 528 } |
OLD | NEW |