Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright (c) 2014, the Dart project authors. Please see the AUTHORS file | 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 | 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 pub_semver.src.version; | 5 library pub_semver.src.version; |
| 6 | 6 |
| 7 import 'dart:math'; | 7 import 'dart:math'; |
| 8 | 8 |
| 9 import 'package:collection/equality.dart'; | 9 import 'package:collection/equality.dart'; |
| 10 | 10 |
| (...skipping 219 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 230 return _incrementMajor(); | 230 return _incrementMajor(); |
| 231 } | 231 } |
| 232 | 232 |
| 233 Version _incrementMajor() => new Version(major + 1, 0, 0); | 233 Version _incrementMajor() => new Version(major + 1, 0, 0); |
| 234 Version _incrementMinor() => new Version(major, minor + 1, 0); | 234 Version _incrementMinor() => new Version(major, minor + 1, 0); |
| 235 Version _incrementPatch() => new Version(major, minor, patch + 1); | 235 Version _incrementPatch() => new Version(major, minor, patch + 1); |
| 236 | 236 |
| 237 /// Tests if [other] matches this version exactly. | 237 /// Tests if [other] matches this version exactly. |
| 238 bool allows(Version other) => this == other; | 238 bool allows(Version other) => this == other; |
| 239 | 239 |
| 240 VersionConstraint intersect(VersionConstraint other) { | 240 bool allowsAll(VersionConstraint other) => other.isEmpty || other == this; |
|
Bob Nystrom
2015/05/05 20:49:09
What about:
var v123 = new Version.parse("1.2.3")
nweiz
2015/05/05 22:52:33
In general, we don't handle VersionRanges that loo
| |
| 241 if (other.isEmpty) return other; | |
| 242 | 241 |
| 243 // Intersect a version and a range. | 242 bool allowsAny(VersionConstraint other) => other.allows(this); |
| 244 if (other is VersionRange) return other.intersect(this); | |
| 245 | 243 |
| 246 // Intersecting two versions only works if they are the same. | 244 VersionConstraint intersect(VersionConstraint other) => |
| 247 if (other is Version) { | 245 other.allows(this) ? this : VersionConstraint.empty; |
| 248 return this == other ? this : VersionConstraint.empty; | 246 |
| 247 VersionConstraint union(VersionConstraint other) { | |
| 248 if (other.allows(this)) return other; | |
| 249 | |
| 250 if (other is VersionRange) { | |
| 251 if (other.min == this) { | |
| 252 return new VersionRange( | |
| 253 min: other.min, max: other.max, | |
| 254 includeMin: true, includeMax: other.includeMax); | |
| 255 } | |
| 256 | |
| 257 if (other.max == this) { | |
| 258 return new VersionRange( | |
| 259 min: other.min, max: other.max, | |
| 260 includeMin: other.includeMin, includeMax: true); | |
| 261 } | |
| 249 } | 262 } |
| 250 | 263 |
| 251 throw new ArgumentError( | 264 return new VersionConstraint.unionOf([this, other]); |
| 252 'Unknown VersionConstraint type $other.'); | |
| 253 } | 265 } |
| 254 | 266 |
| 255 int compareTo(Version other) { | 267 int compareTo(Version other) { |
| 256 if (major != other.major) return major.compareTo(other.major); | 268 if (major != other.major) return major.compareTo(other.major); |
| 257 if (minor != other.minor) return minor.compareTo(other.minor); | 269 if (minor != other.minor) return minor.compareTo(other.minor); |
| 258 if (patch != other.patch) return patch.compareTo(other.patch); | 270 if (patch != other.patch) return patch.compareTo(other.patch); |
| 259 | 271 |
| 260 // Pre-releases always come before no pre-release string. | 272 // Pre-releases always come before no pre-release string. |
| 261 if (!isPreRelease && other.isPreRelease) return 1; | 273 if (!isPreRelease && other.isPreRelease) return 1; |
| 262 if (!other.isPreRelease && isPreRelease) return -1; | 274 if (!other.isPreRelease && isPreRelease) return -1; |
| (...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 303 // Compare two strings. | 315 // Compare two strings. |
| 304 return aPart.compareTo(bPart); | 316 return aPart.compareTo(bPart); |
| 305 } | 317 } |
| 306 } | 318 } |
| 307 } | 319 } |
| 308 | 320 |
| 309 // The lists are entirely equal. | 321 // The lists are entirely equal. |
| 310 return 0; | 322 return 0; |
| 311 } | 323 } |
| 312 } | 324 } |
| OLD | NEW |