2020-10-26 20:05:18 +03:00
|
|
|
module semver
|
|
|
|
|
|
|
|
// * Private functions.
|
|
|
|
[inline]
|
|
|
|
fn version_satisfies(ver Version, input string) bool {
|
2020-12-21 22:25:19 +03:00
|
|
|
range := parse_range(input) or { return false }
|
2020-10-26 20:05:18 +03:00
|
|
|
return range.satisfies(ver)
|
|
|
|
}
|
|
|
|
|
|
|
|
fn compare_eq(v1 Version, v2 Version) bool {
|
2021-01-23 11:33:22 +03:00
|
|
|
return v1.major == v2.major && v1.minor == v2.minor && v1.patch == v2.patch
|
|
|
|
&& v1.prerelease == v2.prerelease
|
2020-10-26 20:05:18 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
fn compare_gt(v1 Version, v2 Version) bool {
|
2023-05-27 01:57:02 +03:00
|
|
|
return match true {
|
|
|
|
v1.major < v2.major { false }
|
|
|
|
v1.major > v2.major { true }
|
|
|
|
v1.minor < v2.minor { false }
|
|
|
|
v1.minor > v2.minor { true }
|
|
|
|
else { v1.patch > v2.patch }
|
2020-10-26 20:05:18 +03:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
fn compare_lt(v1 Version, v2 Version) bool {
|
2023-05-27 01:57:02 +03:00
|
|
|
return match true {
|
|
|
|
v1.major > v2.major { false }
|
|
|
|
v1.major < v2.major { true }
|
|
|
|
v1.minor > v2.minor { false }
|
|
|
|
v1.minor < v2.minor { true }
|
|
|
|
else { v1.patch < v2.patch }
|
2020-10-26 20:05:18 +03:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
fn compare_ge(v1 Version, v2 Version) bool {
|
2023-05-27 01:57:02 +03:00
|
|
|
return if compare_eq(v1, v2) { true } else { compare_gt(v1, v2) }
|
2020-10-26 20:05:18 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
fn compare_le(v1 Version, v2 Version) bool {
|
2023-05-27 01:57:02 +03:00
|
|
|
return if compare_eq(v1, v2) { true } else { compare_lt(v1, v2) }
|
2020-10-26 20:05:18 +03:00
|
|
|
}
|