semver: run v fmt (#7439)
parent
805ec8e177
commit
fade162471
|
@ -3,9 +3,7 @@ module semver
|
||||||
// * Private functions.
|
// * Private functions.
|
||||||
[inline]
|
[inline]
|
||||||
fn version_satisfies(ver Version, input string) bool {
|
fn version_satisfies(ver Version, input string) bool {
|
||||||
range := parse_range(input) or {
|
range := parse_range(input) or { return false }
|
||||||
return false
|
|
||||||
}
|
|
||||||
return range.satisfies(ver)
|
return range.satisfies(ver)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -21,16 +21,12 @@ fn parse(input string) RawVersion {
|
||||||
mut raw_version := input
|
mut raw_version := input
|
||||||
mut prerelease := ''
|
mut prerelease := ''
|
||||||
mut metadata := ''
|
mut metadata := ''
|
||||||
plus_idx := raw_version.last_index('+') or {
|
plus_idx := raw_version.last_index('+') or { -1 }
|
||||||
-1
|
|
||||||
}
|
|
||||||
if plus_idx > 0 {
|
if plus_idx > 0 {
|
||||||
metadata = raw_version[(plus_idx + 1)..]
|
metadata = raw_version[(plus_idx + 1)..]
|
||||||
raw_version = raw_version[0..plus_idx]
|
raw_version = raw_version[0..plus_idx]
|
||||||
}
|
}
|
||||||
hyphen_idx := raw_version.index('-') or {
|
hyphen_idx := raw_version.index('-') or { -1 }
|
||||||
-1
|
|
||||||
}
|
|
||||||
if hyphen_idx > 0 {
|
if hyphen_idx > 0 {
|
||||||
prerelease = raw_version[(hyphen_idx + 1)..]
|
prerelease = raw_version[(hyphen_idx + 1)..]
|
||||||
raw_version = raw_version[0..hyphen_idx]
|
raw_version = raw_version[0..hyphen_idx]
|
||||||
|
|
|
@ -61,14 +61,10 @@ fn parse_range(input string) ?Range {
|
||||||
mut comparator_sets := []ComparatorSet{}
|
mut comparator_sets := []ComparatorSet{}
|
||||||
for raw_comp_set in raw_comparator_sets {
|
for raw_comp_set in raw_comparator_sets {
|
||||||
if can_expand(raw_comp_set) {
|
if can_expand(raw_comp_set) {
|
||||||
s := expand_comparator_set(raw_comp_set) or {
|
s := expand_comparator_set(raw_comp_set) or { return error(err) }
|
||||||
return error(err)
|
|
||||||
}
|
|
||||||
comparator_sets << s
|
comparator_sets << s
|
||||||
} else {
|
} else {
|
||||||
s := parse_comparator_set(raw_comp_set) or {
|
s := parse_comparator_set(raw_comp_set) or { return error(err) }
|
||||||
return error(err)
|
|
||||||
}
|
|
||||||
comparator_sets << s
|
comparator_sets << s
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -82,9 +78,7 @@ fn parse_comparator_set(input string) ?ComparatorSet {
|
||||||
}
|
}
|
||||||
mut comparators := []Comparator{}
|
mut comparators := []Comparator{}
|
||||||
for raw_comp in raw_comparators {
|
for raw_comp in raw_comparators {
|
||||||
c := parse_comparator(raw_comp) or {
|
c := parse_comparator(raw_comp) or { return error('Invalid comparator: $raw_comp') }
|
||||||
return error('Invalid comparator: $raw_comp')
|
|
||||||
}
|
|
||||||
comparators << c
|
comparators << c
|
||||||
}
|
}
|
||||||
return ComparatorSet{comparators}
|
return ComparatorSet{comparators}
|
||||||
|
@ -110,9 +104,7 @@ fn parse_comparator(input string) ?Comparator {
|
||||||
} else {
|
} else {
|
||||||
raw_version = input
|
raw_version = input
|
||||||
}
|
}
|
||||||
version := coerce_version(raw_version) or {
|
version := coerce_version(raw_version) or { return none }
|
||||||
return none
|
|
||||||
}
|
|
||||||
return Comparator{version, op}
|
return Comparator{version, op}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -162,9 +154,7 @@ fn expand_comparator_set(input string) ?ComparatorSet {
|
||||||
}
|
}
|
||||||
|
|
||||||
fn expand_tilda(raw_version string) ?ComparatorSet {
|
fn expand_tilda(raw_version string) ?ComparatorSet {
|
||||||
min_ver := coerce_version(raw_version) or {
|
min_ver := coerce_version(raw_version) or { return none }
|
||||||
return none
|
|
||||||
}
|
|
||||||
mut max_ver := min_ver
|
mut max_ver := min_ver
|
||||||
if min_ver.minor == 0 && min_ver.patch == 0 {
|
if min_ver.minor == 0 && min_ver.patch == 0 {
|
||||||
max_ver = min_ver.increment(.major)
|
max_ver = min_ver.increment(.major)
|
||||||
|
@ -175,9 +165,7 @@ fn expand_tilda(raw_version string) ?ComparatorSet {
|
||||||
}
|
}
|
||||||
|
|
||||||
fn expand_caret(raw_version string) ?ComparatorSet {
|
fn expand_caret(raw_version string) ?ComparatorSet {
|
||||||
min_ver := coerce_version(raw_version) or {
|
min_ver := coerce_version(raw_version) or { return none }
|
||||||
return none
|
|
||||||
}
|
|
||||||
mut max_ver := min_ver
|
mut max_ver := min_ver
|
||||||
if min_ver.major == 0 {
|
if min_ver.major == 0 {
|
||||||
max_ver = min_ver.increment(.minor)
|
max_ver = min_ver.increment(.minor)
|
||||||
|
@ -192,16 +180,12 @@ fn expand_hyphen(raw_range string) ?ComparatorSet {
|
||||||
if raw_versions.len != 2 {
|
if raw_versions.len != 2 {
|
||||||
return none
|
return none
|
||||||
}
|
}
|
||||||
min_ver := coerce_version(raw_versions[0]) or {
|
min_ver := coerce_version(raw_versions[0]) or { return none }
|
||||||
return none
|
|
||||||
}
|
|
||||||
raw_max_ver := parse(raw_versions[1])
|
raw_max_ver := parse(raw_versions[1])
|
||||||
if raw_max_ver.is_missing(ver_major) {
|
if raw_max_ver.is_missing(ver_major) {
|
||||||
return none
|
return none
|
||||||
}
|
}
|
||||||
mut max_ver := raw_max_ver.coerce() or {
|
mut max_ver := raw_max_ver.coerce() or { return none }
|
||||||
return none
|
|
||||||
}
|
|
||||||
if raw_max_ver.is_missing(ver_minor) {
|
if raw_max_ver.is_missing(ver_minor) {
|
||||||
max_ver = max_ver.increment(.minor)
|
max_ver = max_ver.increment(.minor)
|
||||||
return make_comparator_set_ge_lt(min_ver, max_ver)
|
return make_comparator_set_ge_lt(min_ver, max_ver)
|
||||||
|
@ -210,9 +194,7 @@ fn expand_hyphen(raw_range string) ?ComparatorSet {
|
||||||
}
|
}
|
||||||
|
|
||||||
fn expand_xrange(raw_range string) ?ComparatorSet {
|
fn expand_xrange(raw_range string) ?ComparatorSet {
|
||||||
min_ver := parse_xrange(raw_range) or {
|
min_ver := parse_xrange(raw_range) or { return none }
|
||||||
return none
|
|
||||||
}
|
|
||||||
if min_ver.major == 0 {
|
if min_ver.major == 0 {
|
||||||
comparators := [
|
comparators := [
|
||||||
Comparator{min_ver, Operator.ge},
|
Comparator{min_ver, Operator.ge},
|
||||||
|
|
|
@ -26,9 +26,7 @@ pub fn from(input string) ?Version {
|
||||||
return error('Empty input')
|
return error('Empty input')
|
||||||
}
|
}
|
||||||
raw_version := parse(input)
|
raw_version := parse(input)
|
||||||
version := raw_version.validate() or {
|
version := raw_version.validate() or { return error('Invalid version format') }
|
||||||
return error('Invalid version format')
|
|
||||||
}
|
|
||||||
return version
|
return version
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -71,9 +69,7 @@ pub fn (v1 Version) le(v2 Version) bool {
|
||||||
|
|
||||||
// * Utilites.
|
// * Utilites.
|
||||||
pub fn coerce(input string) ?Version {
|
pub fn coerce(input string) ?Version {
|
||||||
ver := coerce_version(input) or {
|
ver := coerce_version(input) or { return error('Invalid version: $input') }
|
||||||
return error('Invalid version: $input')
|
|
||||||
}
|
|
||||||
return ver
|
return ver
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -10,9 +10,7 @@ fn is_version_valid(input string) bool {
|
||||||
[inline]
|
[inline]
|
||||||
fn coerce_version(input string) ?Version {
|
fn coerce_version(input string) ?Version {
|
||||||
raw_ver := parse(input)
|
raw_ver := parse(input)
|
||||||
ver := raw_ver.coerce() or {
|
ver := raw_ver.coerce() or { return error('Invalid version: $input') }
|
||||||
return error('Invalid version: $input')
|
|
||||||
}
|
|
||||||
return ver
|
return ver
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue