mirror of
https://github.com/nvm-sh/nvm.git
synced 2025-12-14 00:54:18 +00:00
Dynamically interpret semver expression in local dirs package.json
This commit is contained in:
42
test/fast/Unit tests/nvm_string_equals_regexp
Executable file
42
test/fast/Unit tests/nvm_string_equals_regexp
Executable file
@@ -0,0 +1,42 @@
|
||||
#!/bin/sh
|
||||
|
||||
die () { printf "$@" ; exit 1; }
|
||||
|
||||
\. ../../../nvm.sh
|
||||
|
||||
valid_semver_regexp='^( ?(<|<=|>|>=|=|~|\^)?([0-9]+|x)\.([0-9]+|x)\.([0-9]+|x))+$'
|
||||
|
||||
# POSITIVE 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 }')
|
||||
[ -n "$REGEXP" ] \
|
||||
&& [ -n "$STRING" ] \
|
||||
&& nvm_string_contains_regexp "$STRING" "$REGEXP" \
|
||||
|| die "nvm_string_contains_regexp POSITIVE test case failed. REGEXP: '$REGEXP'. STRING: '$STRING'.\n"
|
||||
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 }')
|
||||
[ -n "$REGEXP" ] \
|
||||
&& ! nvm_string_contains_regexp "$STRING" "$REGEXP" \
|
||||
|| die "nvm_string_contains_regexp NEGATIVE test case failed. REGEXP: '$REGEXP'. STRING: '$STRING'.\n"
|
||||
test_cases=$(echo "$test_cases" | tail -n +2)
|
||||
done
|
||||
exit 0
|
||||
Reference in New Issue
Block a user