nvm/test/fast/Unit tests/nvm_validate_semver

57 lines
1.4 KiB
Bash
Executable File

#!/bin/sh
die () { printf "$@" ; exit 1; }
\. ../../../nvm.sh
# TODO add more test cases here
# Some test cases should just test that valid semvers from sharedTestResources/semvers just produce some result
# input:expected_output
test_cases="1.2.3:1.2.3
1.2.3 - 1.2.4:>=1.2.3 <=1.2.4
1.2.3-1.2.4:>=1.2.3 <=1.2.4
11.22.33 - 11.22.44:>=11.22.33 <=11.22.44
1.2.x - 1.2.4:>=1.2.0 <=1.2.4
1.2.xx - 1.2.4:
1.2.3 || 1.2.4:1.2.3 || 1.2.4
*:>0.0.0
x:>0.0.0
X:>0.0.0
1:>=1.0.0 <2.0.0
1.2:>=1.2.0 <1.3.0
< 1.2.3:<1.2.3
> 1.2.3:>1.2.3
<= 1.2.3:<=1.2.3
>= 1.2.3:>=1.2.3
= 1.2.3:1.2.3
^0.0.1 ^0.1.2 ^1.2.3:>=0.0.1 <0.0.2 >=0.1.2 <0.2.0 >=1.2.3 <2.0.0
~0.0.1 ~0.1.2 ~1.2.3:>=0.0.1 <0.1.0 >=0.1.2 <0.2.0 >=1.2.3 <1.3.0
~ 1.2.3:>=1.2.3 <1.3.0
^ 1.2.3:>=1.2.3 <2.0.0
1.2.3 || 1.2.4 1.2.5:1.2.3 || 1.2.4 1.2.5
a:
1 || 2 a:
1 || a:
a || 1.2.3:
1.2.?:
^0.0.1:>=0.0.1 <0.0.2
<x.x.x:
>=x.1.1:>0.0.0
>x.1.1:>0.0.0
~x.1.1:>0.0.0
^x.1.1:>0.0.0
11.22.33:11.22.33"
while [ -n "$test_cases" ]; do
line=$(echo "$test_cases" | head -n1)
input=$(echo "$line" | awk -F: '{ print $1 }')
expected_output=$(echo "$line" | awk -F: '{ print $2 }')
actual_output=$(nvm_validate_semver "$input")
if [ -z "$input" ] || [ "$actual_output" != "$expected_output" ]; then
die "nvm_validate_semver test case failed. Expected output: '$expected_output'. Actual output: '$actual_output'. Input: '$input'.\n"
fi
test_cases=$(echo "$test_cases" | tail -n +2)
done
exit 0