[Fix] `nvm_format_version` should only return 3 version groups
parent
77e0449c89
commit
de64a2d95f
6
nvm.sh
6
nvm.sh
|
@ -339,10 +339,12 @@ nvm_ensure_version_prefix() {
|
|||
nvm_format_version() {
|
||||
local VERSION
|
||||
VERSION="$(nvm_ensure_version_prefix "$1")"
|
||||
if [ "_$(nvm_num_version_groups "$VERSION")" != "_3" ]; then
|
||||
local NUM_GROUPS
|
||||
NUM_GROUPS="$(nvm_num_version_groups "$VERSION")"
|
||||
if [ $NUM_GROUPS -lt 3 ]; then
|
||||
nvm_format_version "${VERSION%.}.0"
|
||||
else
|
||||
echo "$VERSION"
|
||||
echo "$VERSION" | cut -f1-3 -d.
|
||||
fi
|
||||
}
|
||||
|
||||
|
|
|
@ -4,11 +4,18 @@ die () { echo $@ ; exit 1; }
|
|||
|
||||
. ../../../nvm.sh
|
||||
|
||||
OUTPUT="$(nvm_format_version 0.1.2)"
|
||||
INPUT="0.1.2"
|
||||
OUTPUT="$(nvm_format_version "$INPUT")"
|
||||
EXPECTED_OUTPUT="v0.1.2"
|
||||
[ "_$OUTPUT" = "_$EXPECTED_OUTPUT" ] || die "nvm_format_version 0.1.2 did not return $EXPECTED_OUTPUT; got $OUTPUT"
|
||||
[ "_$OUTPUT" = "_$EXPECTED_OUTPUT" ] || die "nvm_format_version $INPUT did not return $EXPECTED_OUTPUT; got $OUTPUT"
|
||||
|
||||
OUTPUT="$(nvm_format_version 0.1)"
|
||||
INPUT="0.1"
|
||||
OUTPUT="$(nvm_format_version "$INPUT")"
|
||||
EXPECTED_OUTPUT="v0.1.0"
|
||||
[ "_$OUTPUT" = "_$EXPECTED_OUTPUT" ] || die "nvm_format_version 0.1.0 did not return $EXPECTED_OUTPUT; got $OUTPUT"
|
||||
[ "_$OUTPUT" = "_$EXPECTED_OUTPUT" ] || die "nvm_format_version $INPUT did not return $EXPECTED_OUTPUT; got $OUTPUT"
|
||||
|
||||
INPUT="1.2.3.4.5"
|
||||
OUTPUT="$(nvm_format_version "$INPUT")"
|
||||
EXPECTED_OUTPUT="v1.2.3"
|
||||
[ "_$OUTPUT" = "_$EXPECTED_OUTPUT" ] || die "nvm_format_version $INPUT did not return $EXPECTED_OUTPUT; got $OUTPUT"
|
||||
|
||||
|
|
Loading…
Reference in New Issue