From e1b7496cf06435824d8249e012e2f006c92077ca Mon Sep 17 00:00:00 2001 From: Jordan Harband Date: Sun, 1 Feb 2015 13:01:40 -0800 Subject: [PATCH] Add nvm_is_valid_version --- nvm.sh | 16 ++++++++++++++++ test/fast/Unit tests/nvm_is_valid_version | 13 +++++++++++++ 2 files changed, 29 insertions(+) create mode 100755 test/fast/Unit tests/nvm_is_valid_version diff --git a/nvm.sh b/nvm.sh index 7e1a961..497ad2b 100644 --- a/nvm.sh +++ b/nvm.sh @@ -263,6 +263,22 @@ $(nvm_ls_remote_iojs "$PATTERN")" | command grep -v "N/A" | command sed '/^$/d') fi } +nvm_is_valid_version() { + if nvm_validate_implicit_alias "$1" 2> /dev/null; then + return 0 + fi + case "$1" in + "$(nvm_iojs_prefix)" | "$(nvm_node_prefix)") + return 0 + ;; + *) + local VERSION + VERSION="$(nvm_strip_iojs_prefix "$1")" + nvm_version_greater "$VERSION" + ;; + esac +} + nvm_normalize_version() { echo "$1" | command sed -e 's/^v//' | command awk -F. '{ printf("%d%06d%06d\n", $1,$2,$3); }' } diff --git a/test/fast/Unit tests/nvm_is_valid_version b/test/fast/Unit tests/nvm_is_valid_version new file mode 100755 index 0000000..d34f767 --- /dev/null +++ b/test/fast/Unit tests/nvm_is_valid_version @@ -0,0 +1,13 @@ +#!/bin/sh + +die () { echo $@ ; exit 1; } + +. ../../../nvm.sh + +nvm_is_valid_version 0.1.2 || die "nvm_is_valid_version 0.1.2 did not return 0" +nvm_is_valid_version foo && die "nvm_is_valid_version foo did not return 1" +nvm_is_valid_version iojs-1 || die "nvm_is_valid_version iojs-1 did not return 0" +nvm_is_valid_version iojs || die "nvm_is_valid_version iojs did not return 0" +nvm_is_valid_version node || die "nvm_is_valid_version node did not return 0" +nvm_is_valid_version stable || die "nvm_is_valid_version stable did not return 0" +nvm_is_valid_version unstable || die "nvm_is_valid_version unstable did not return 0"