mirror of
https://github.com/nvm-sh/nvm.git
synced 2025-05-11 22:51:51 +00:00
44 lines
1.2 KiB
Bash
Executable File
44 lines
1.2 KiB
Bash
Executable File
#!/bin/sh
|
|
|
|
die () { printf "$@" ; exit 1; }
|
|
|
|
\. ../../../nvm.sh
|
|
|
|
valid_semver_regexp='^( ?(<|<=|>|>=|=|~|\^)?([0-9]+|x)\.([0-9]+|x)\.([0-9]+|x))+$'
|
|
|
|
# POSITIVE TEST CASES
|
|
|
|
# TODO add more test cases
|
|
# string:regexp
|
|
test_cases="1.2.3:$valid_semver_regexp
|
|
11.22.33:$valid_semver_regexp"
|
|
|
|
while [ -n "$test_cases" ]; do
|
|
line=$(echo "$test_cases" | head -n1)
|
|
string=$(echo "$line" | awk -F: '{ print $1 }')
|
|
regexp=$(echo "$line" | awk -F: '{ print $2 }')
|
|
if [ -z "$regexp" ] || [ -z "$string" ] || ! nvm_string_contains_regexp "$string" "$regexp"; then
|
|
die "nvm_string_contains_regexp POSITIVE test case failed. regexp: '$regexp'. string: '$string'.\n"
|
|
fi
|
|
test_cases=$(echo "$test_cases" | tail -n +2)
|
|
done
|
|
|
|
# NEGATIVE TEST CASES
|
|
|
|
# string:regexp
|
|
test_cases="1.2.a:$valid_semver_regexp
|
|
:$valid_semver_regexp
|
|
11.22.a:$valid_semver_regexp"
|
|
|
|
while [ -n "$test_cases" ]; do
|
|
line=$(echo "$test_cases" | head -n1)
|
|
string=$(echo "$line" | awk -F: '{ print $1 }')
|
|
regexp=$(echo "$line" | awk -F: '{ print $2 }')
|
|
if [ -z "$regexp" ] || nvm_string_contains_regexp "$string" "$regexp"; then
|
|
die "nvm_string_contains_regexp NEGATIVE test case failed. regexp: '$regexp'. string: '$string'.\n"
|
|
fi
|
|
test_cases=$(echo "$test_cases" | tail -n +2)
|
|
done
|
|
exit 0
|
|
|