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) { |