Skip to content

Commit

Permalink
[dev_build] v1.0.0+5 fix version boundaries toString
Browse files Browse the repository at this point in the history
  • Loading branch information
alextekartik committed Jul 17, 2024
1 parent f58b61b commit 42c95ef
Show file tree
Hide file tree
Showing 4 changed files with 62 additions and 5 deletions.
2 changes: 1 addition & 1 deletion dev_build/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
## 1.0.0+4
## 1.0.0+5

* Make it `1.0.0`

Expand Down
45 changes: 45 additions & 0 deletions dev_build/lib/src/package/package.dart
Original file line number Diff line number Diff line change
Expand Up @@ -174,6 +174,51 @@ class VersionBoundaries {

@override
String toString() {
return toShortString();
}

bool _isShort() {
var min = this.min;
var max = this.max;
if (min == null || max == null) {
return false;
}
if (!min.include || max.include) {
return false;
}
if (Version(min.value.major + 1, 0, 0) == max.value) {
return true;
}
if (min.value.major == 0) {
if (min.value.minor == 0) {
if (Version(min.value.major, min.value.minor, min.value.patch + 1) ==
max.value) {
return true;
}
} else {
if (Version(min.value.major, min.value.minor + 1, 0) == max.value) {
return true;
}
}
} else {
if (Version(min.value.major + 1, 0, 0) == max.value) {
return true;
}
}
return false;
}

/// Short string if possible, default to minMaxString.
String toShortString() {
if (_isShort()) {
return '^${min!.value}';
} else {
return toMinMaxString();
}
}

/// >=minVersion <maxVersion
String toMinMaxString() {
var sb = StringBuffer();
if (min != null) {
if (max == min) {
Expand Down
2 changes: 1 addition & 1 deletion dev_build/pubspec.yaml
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
name: dev_build
version: 1.0.0+4
version: 1.0.0+5
description: Development utilities for dart and flutter packages. CI and build helpers.
repository: https://github.com/tekartik/dev_test.dart/tree/master/dev_build

Expand Down
18 changes: 15 additions & 3 deletions dev_build/test/build_support_pubspec_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -105,9 +105,21 @@ environment:
expect(boundaries.matchesMin(Version(3, 0, 0)), isTrue);

expect(VersionBoundaries.parse('0.0.1').toString(), '0.0.1');
expect(VersionBoundaries.parse('^0.0.1').toString(), '>=0.0.1 <0.0.2');
expect(VersionBoundaries.parse('^0.1.2').toString(), '>=0.1.2 <0.2.0');
expect(VersionBoundaries.parse('^1.2.3').toString(), '>=1.2.3 <2.0.0');
expect(VersionBoundaries.parse('0.0.1').toMinMaxString(), '0.0.1');
expect(VersionBoundaries.parse('0.0.1').toShortString(), '0.0.1');
expect(VersionBoundaries.parse('^0.0.1').toString(), '^0.0.1');
expect(VersionBoundaries.parse('^0.0.1').toShortString(), '^0.0.1');
expect(
VersionBoundaries.parse('^0.0.1').toMinMaxString(), '>=0.0.1 <0.0.2');
expect(VersionBoundaries.parse('^0.1.2').toString(), '^0.1.2');
expect(
VersionBoundaries.parse('^0.1.2').toMinMaxString(), '>=0.1.2 <0.2.0');
expect(VersionBoundaries.parse('^1.2.3').toString(), '^1.2.3');
expect(
VersionBoundaries.parse('^1.2.3').toMinMaxString(), '>=1.2.3 <2.0.0');
expect(VersionBoundaries.parse('^1.2.3-4').toString(), '^1.2.3-4');
expect(VersionBoundaries.parse('^1.2.3-4').toMinMaxString(),
'>=1.2.3-4 <2.0.0');

boundaries = VersionBoundaries.parse('>1.0.0');
expect(boundaries.matches(Version(1, 1, 0)), isTrue);
Expand Down

0 comments on commit 42c95ef

Please sign in to comment.