mirror of
https://github.com/apple/pkl.git
synced 2026-07-08 22:15:11 +02:00
Fix semver comparison logic (#773)
Fix `isLessThan` logic between semvers
This commit is contained in:
@@ -15,6 +15,15 @@ examples {
|
|||||||
test.catch(() -> semver.Version("1.02.3"))
|
test.catch(() -> semver.Version("1.02.3"))
|
||||||
test.catch(() -> semver.Version("aaa"))
|
test.catch(() -> semver.Version("aaa"))
|
||||||
}
|
}
|
||||||
|
|
||||||
|
["List.sortWith()"] {
|
||||||
|
List(
|
||||||
|
semver.Version("100.0.0"),
|
||||||
|
semver.Version("0.100.0"),
|
||||||
|
semver.Version("0.0.100")
|
||||||
|
)
|
||||||
|
.sortWith(semver.comparator)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
facts {
|
facts {
|
||||||
@@ -123,6 +132,9 @@ facts {
|
|||||||
|
|
||||||
!semver.Version("1.2.3-alpha+def").isLessThan(semver.Version("1.2.3-alpha+abc"))
|
!semver.Version("1.2.3-alpha+def").isLessThan(semver.Version("1.2.3-alpha+abc"))
|
||||||
!semver.Version("1.2.3-alpha+abc").isLessThan(semver.Version("1.2.3-alpha+def"))
|
!semver.Version("1.2.3-alpha+abc").isLessThan(semver.Version("1.2.3-alpha+def"))
|
||||||
|
|
||||||
|
semver.Version("1.2.3").isLessThan(semver.Version("2.0.100"))
|
||||||
|
semver.Version("1.2.3").isLessThan(semver.Version("2.100.0"))
|
||||||
}
|
}
|
||||||
|
|
||||||
["Version.isLessThanOrEquals()"] {
|
["Version.isLessThanOrEquals()"] {
|
||||||
@@ -141,6 +153,10 @@ facts {
|
|||||||
semver.Version("1.3.3").isGreaterThan(semver.Version("1.2.3"))
|
semver.Version("1.3.3").isGreaterThan(semver.Version("1.2.3"))
|
||||||
semver.Version("1.2.4").isGreaterThan(semver.Version("1.2.3"))
|
semver.Version("1.2.4").isGreaterThan(semver.Version("1.2.3"))
|
||||||
semver.Version("1.2.3-beta").isGreaterThan(semver.Version("1.2.3-alpha"))
|
semver.Version("1.2.3-beta").isGreaterThan(semver.Version("1.2.3-alpha"))
|
||||||
|
|
||||||
|
semver.Version("2.0.100").isGreaterThan(semver.Version("1.2.3"))
|
||||||
|
semver.Version("2.100.0").isGreaterThan(semver.Version("1.2.3"))
|
||||||
|
semver.Version("2.0.100").isGreaterThan(semver.Version("1.2.3"))
|
||||||
}
|
}
|
||||||
|
|
||||||
["Version.isGreaterThanOrEquals()"] {
|
["Version.isGreaterThanOrEquals()"] {
|
||||||
|
|||||||
@@ -92,6 +92,8 @@ facts {
|
|||||||
true
|
true
|
||||||
true
|
true
|
||||||
true
|
true
|
||||||
|
true
|
||||||
|
true
|
||||||
}
|
}
|
||||||
["Version.isLessThanOrEquals()"] {
|
["Version.isLessThanOrEquals()"] {
|
||||||
true
|
true
|
||||||
@@ -108,6 +110,9 @@ facts {
|
|||||||
true
|
true
|
||||||
true
|
true
|
||||||
true
|
true
|
||||||
|
true
|
||||||
|
true
|
||||||
|
true
|
||||||
}
|
}
|
||||||
["Version.isGreaterThanOrEquals()"] {
|
["Version.isGreaterThanOrEquals()"] {
|
||||||
true
|
true
|
||||||
@@ -172,4 +177,19 @@ examples {
|
|||||||
"`1.02.3` is not a valid semantic version number."
|
"`1.02.3` is not a valid semantic version number."
|
||||||
"`aaa` is not a valid semantic version number."
|
"`aaa` is not a valid semantic version number."
|
||||||
}
|
}
|
||||||
|
["List.sortWith()"] {
|
||||||
|
List(new {
|
||||||
|
major = 0
|
||||||
|
minor = 0
|
||||||
|
patch = 100
|
||||||
|
}, new {
|
||||||
|
major = 0
|
||||||
|
minor = 100
|
||||||
|
patch = 0
|
||||||
|
}, new {
|
||||||
|
major = 100
|
||||||
|
minor = 0
|
||||||
|
patch = 0
|
||||||
|
})
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
+12
-8
@@ -133,10 +133,10 @@ class Version {
|
|||||||
///
|
///
|
||||||
/// Note: `version1.equals(version2)` differs from `version1 == version2` in that it ignores [build].
|
/// Note: `version1.equals(version2)` differs from `version1 == version2` in that it ignores [build].
|
||||||
function equals(other: Version): Boolean =
|
function equals(other: Version): Boolean =
|
||||||
major == other.major &&
|
major == other.major
|
||||||
minor == other.minor &&
|
&& minor == other.minor
|
||||||
patch == other.patch &&
|
&& patch == other.patch
|
||||||
preRelease == other.preRelease
|
&& preRelease == other.preRelease
|
||||||
|
|
||||||
/// Tells whether this version is less than [other] according to semantic versioning rules.
|
/// Tells whether this version is less than [other] according to semantic versioning rules.
|
||||||
///
|
///
|
||||||
@@ -157,10 +157,14 @@ class Version {
|
|||||||
/// semver.Version("1.0.0-rc.1").isLessThan(semver.Version("1.0.0"))
|
/// semver.Version("1.0.0-rc.1").isLessThan(semver.Version("1.0.0"))
|
||||||
/// ```
|
/// ```
|
||||||
function isLessThan(other: Version): Boolean =
|
function isLessThan(other: Version): Boolean =
|
||||||
major < other.major ||
|
major < other.major
|
||||||
minor < other.minor ||
|
|| major == other.major && minor < other.minor
|
||||||
patch < other.patch ||
|
|| major == other.major && minor == other.minor && patch < other.patch
|
||||||
isPreReleaseLessThan(other)
|
||
|
||||||
|
major == other.major
|
||||||
|
&& minor == other.minor
|
||||||
|
&& patch == other.patch
|
||||||
|
&& isPreReleaseLessThan(other)
|
||||||
|
|
||||||
/// Tells whether this version is less than or equal to [other] according to semantic versioning rules.
|
/// Tells whether this version is less than or equal to [other] according to semantic versioning rules.
|
||||||
function isLessThanOrEquals(other: Version): Boolean =
|
function isLessThanOrEquals(other: Version): Boolean =
|
||||||
|
|||||||
Reference in New Issue
Block a user