mirror of
https://github.com/nvm-sh/nvm.git
synced 2025-05-11 06:41:50 +00:00
57 lines
1.4 KiB
Bash
Executable File
57 lines
1.4 KiB
Bash
Executable File
#!/bin/sh
|
|
|
|
\. ../../../nvm.sh
|
|
\. ../../generated_semvers.sh
|
|
|
|
# TODO add more test cases here
|
|
# Some test cases should just test that valid semvers from 'Shared test tesources'/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_normalize_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
|
|
|