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

Unified Diff: lib/src/version.dart

Issue 1127783002: Add more set-like version constraint operations. (Closed) Base URL: git@github.com:dart-lang/pub_semver@master
Patch Set: merge Created 5 years, 7 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 side-by-side diff with in-line comments
Download patch
Index: lib/src/version.dart
diff --git a/lib/src/version.dart b/lib/src/version.dart
index 2bf535fcc94f2687c5809e9b1d721f5cfea58b68..640ebecfc4e26b25184bced6daf6e7448ba52959 100644
--- a/lib/src/version.dart
+++ b/lib/src/version.dart
@@ -237,19 +237,31 @@ class Version implements Comparable<Version>, VersionConstraint {
/// Tests if [other] matches this version exactly.
bool allows(Version other) => this == other;
- VersionConstraint intersect(VersionConstraint other) {
- if (other.isEmpty) return other;
+ 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
- // Intersect a version and a range.
- if (other is VersionRange) return other.intersect(this);
+ bool allowsAny(VersionConstraint other) => other.allows(this);
- // Intersecting two versions only works if they are the same.
- if (other is Version) {
- return this == other ? this : VersionConstraint.empty;
+ VersionConstraint intersect(VersionConstraint other) =>
+ other.allows(this) ? this : VersionConstraint.empty;
+
+ VersionConstraint union(VersionConstraint other) {
+ if (other.allows(this)) return other;
+
+ if (other is VersionRange) {
+ if (other.min == this) {
+ return new VersionRange(
+ min: other.min, max: other.max,
+ includeMin: true, includeMax: other.includeMax);
+ }
+
+ if (other.max == this) {
+ return new VersionRange(
+ min: other.min, max: other.max,
+ includeMin: other.includeMin, includeMax: true);
+ }
}
- throw new ArgumentError(
- 'Unknown VersionConstraint type $other.');
+ return new VersionConstraint.unionOf([this, other]);
}
int compareTo(Version other) {

Powered by Google App Engine
This is Rietveld 408576698