mirror of
https://github.com/nvm-sh/nvm.git
synced 2025-05-11 06:41:50 +00:00
31 lines
1.2 KiB
Bash
Executable File
31 lines
1.2 KiB
Bash
Executable File
#!/bin/sh
|
|
|
|
\. ../../../nvm.sh
|
|
\. ../../generated_semvers.sh
|
|
normalized_semver_regexp='^( ?(<|<=|>|>=)?[0-9]+\.[0-9]+\.[0-9]+)+( \|\| ( ?(<|<=|>|>=)?[0-9]+\.[0-9]+\.[0-9]+)+)*$'
|
|
|
|
# Validates the behavior of nvm_string_contains_regexp() which returns 0 if the given string contains the given regular expression.
|
|
|
|
# POSITIVE TEST CASES
|
|
test_cases="$VALID_NORMALIZED_SEMVERS"
|
|
while [ -n "$test_cases" ]; do
|
|
string=$(echo "$test_cases" | head -n1)
|
|
if [ -z "$normalized_semver_regexp" ] || [ -z "$string" ] || ! nvm_string_contains_regexp "$string" "$normalized_semver_regexp"; then
|
|
die "nvm_string_contains_regexp POSITIVE test case failed. regexp: '$normalized_semver_regexp'. string: '$string'.\n"
|
|
fi
|
|
test_cases=$(echo "$test_cases" | tail -n +2)
|
|
done
|
|
|
|
# NEGATIVE TEST CASES
|
|
# string:regexp
|
|
test_cases=$(printf "%s\n%s" "$VALID_NON_NORMALIZED_SEMVERS" "$INVALID_SEMVERS_FOR_PKG_JSON")
|
|
while [ -n "$test_cases" ]; do
|
|
string=$(echo "$test_cases" | head -n1)
|
|
if [ -z "$normalized_semver_regexp" ] || nvm_string_contains_regexp "$string" "$normalized_semver_regexp"; then
|
|
die "nvm_string_contains_regexp NEGATIVE test case failed. regexp: '$normalized_semver_regexp'. string: '$string'.\n"
|
|
fi
|
|
test_cases=$(echo "$test_cases" | tail -n +2)
|
|
done
|
|
exit 0
|
|
|