compatibleWith(): implement toString() and use to parse ^
diff --git a/lib/src/version_constraint.dart b/lib/src/version_constraint.dart
index 0cd45b6..f67375f 100644
--- a/lib/src/version_constraint.dart
+++ b/lib/src/version_constraint.dart
@@ -112,8 +112,7 @@
'"^" constraint "$constraint" in "$originalText".');
}
- return new VersionRange(min: version, includeMin: true,
- max: version.nextBreaking);
+ return new VersionConstraint.compatibleWith(version);
}
while (true) {
@@ -156,10 +155,8 @@
/// Versions are considered backward compatible with [version] if they
/// are greater than or equal to [version], but less than the next breaking
/// version ([Version.nextBreaking]) of [version].
- factory VersionConstraint.compatibleWith(Version version) {
- return new VersionRange(min: version, includeMin: true,
- max: version.nextBreaking);
- }
+ factory VersionConstraint.compatibleWith(Version version) =>
+ new _CompatibleWithVersionRange(version);
/// Creates a new version constraint that is the intersection of
/// [constraints].
@@ -199,3 +196,11 @@
VersionConstraint intersect(VersionConstraint other) => this;
String toString() => '<empty>';
}
+
+class _CompatibleWithVersionRange extends VersionRange {
+ _CompatibleWithVersionRange(Version version) : super(
+ min: version, includeMin: true,
+ max: version.nextBreaking, includeMax: false);
+
+ String toString() => '^$min';
+}
diff --git a/test/version_constraint_test.dart b/test/version_constraint_test.dart
index 316d57d..9ba6905 100644
--- a/test/version_constraint_test.dart
+++ b/test/version_constraint_test.dart
@@ -174,10 +174,18 @@
});
});
- test('compatibleWith', () {
- var constraint = new VersionConstraint.compatibleWith(v072);
+ group('compatibleWith()', () {
+ test('returns the range of compatible versions', () {
+ var constraint = new VersionConstraint.compatibleWith(v072);
- expect(constraint, equals(new VersionRange(min: v072, includeMin: true,
- max: v072.nextBreaking)));
+ expect(constraint, equals(new VersionRange(min: v072, includeMin: true,
+ max: v072.nextBreaking)));
+ });
+
+ test('toString() uses "^"', () {
+ var constraint = new VersionConstraint.compatibleWith(v072);
+
+ expect(constraint.toString(), equals('^0.7.2'));
+ });
});
}