Skip to content

Commit 8758c51

Browse files
author
edwmurph
committed
temp debugging commit
1 parent 7c888aa commit 8758c51

File tree

2 files changed

+40
-41
lines changed

2 files changed

+40
-41
lines changed

nvm.sh

+39-40
Original file line numberDiff line numberDiff line change
@@ -351,44 +351,43 @@ nvm_normalize_semver() {
351351

352352
# convert comparators into required grammar
353353
local validated_comparator_set
354-
validated_comparator_set=$(command printf " %s " "$comparator_set" \
355-
| command sed -E "
356-
# exactly 1 space is needed before and after every comparator (including the first and last comparators)
357-
s/\011/ /g;s/ +/ /g;
358-
359-
# normalize all wildcards to x
360-
s/X|\*/x/g;
361-
362-
# space out numbers surrounding '-'
363-
s/ ?- ?/ - /g;
364-
365-
# ' 1 ' => ' 1.x.x '
366-
# ' x ' => ' x.x.x '
367-
s/ ([0-9]+|x) / \1.x.x /g;
368-
369-
# ' 1.2 ' => ' 1.2.x '
370-
# ' 1.x ' => ' 1.x.x '
371-
# ' x.x ' => ' x.x.x '
372-
s/ (([0-9]+|x)\.([0-9]+|x)) / \1.x /g;
373-
374-
# ' 1.2.3 - 1.2.4 ' => ' >=1.2.3 <=1.2.4 '
375-
s/ (([0-9]+|x)\.([0-9]+|x)\.([0-9]+|x)) ?\- ?(([0-9]+|x)\.([0-9]+|x)\.([0-9]+|x)) / >=\1 <=\5 /g;
376-
377-
# ' > 1.2.3 ' => ' >1.2.3 '
378-
# ' < 1.2.5 ' => ' <1.2.5 '
379-
# ' <= 1.2.3 ' => ' <=1.2.3 '
380-
# ' >= 1.2.3 ' => ' >=1.2.3 '
381-
# ' = 1.2.3 ' => ' =1.2.3 '
382-
# ' ~ 1.2.3 ' => ' ~1.2.3 '
383-
# ' ^ 1.2.3 ' => ' ^1.2.3 '
384-
# ' v 1.2.3 ' => ' v1.2.3 '
385-
s/ (v|<|>|<=|>=|=|~|\^) (([0-9]+|x)\.([0-9]+|x)\.([0-9]+|x)) / \1\2 /g;
386-
387-
# ' =1.2.3 ' => ' 1.2.3 '
388-
# ' v1.2.3 ' => ' 1.2.3 '
389-
s/ (=|v)//g;
390-
" \
391-
| command awk '{
354+
validated_comparator_set=$(command printf " %s " "$comparator_set" |
355+
command sed -E "
356+
# exactly 1 space is needed before and after every comparator (including the first and last comparators)
357+
s/\011/ /g;s/ +/ /g;
358+
359+
# normalize all wildcards to x
360+
s/X|\*/x/g;
361+
362+
# space out numbers surrounding '-'
363+
s/ ?- ?/ - /g;
364+
365+
# ' 1 ' => ' 1.x.x '
366+
# ' x ' => ' x.x.x '
367+
s/ ([0-9]+|x) / \1.x.x /g;
368+
369+
# ' 1.2 ' => ' 1.2.x '
370+
# ' 1.x ' => ' 1.x.x '
371+
# ' x.x ' => ' x.x.x '
372+
s/ (([0-9]+|x)\.([0-9]+|x)) / \1.x /g;
373+
374+
# ' 1.2.3 - 1.2.4 ' => ' >=1.2.3 <=1.2.4 '
375+
s/ (([0-9]+|x)\.([0-9]+|x)\.([0-9]+|x)) ?\- ?(([0-9]+|x)\.([0-9]+|x)\.([0-9]+|x)) / >=\1 <=\5 /g;
376+
377+
# ' > 1.2.3 ' => ' >1.2.3 '
378+
# ' < 1.2.5 ' => ' <1.2.5 '
379+
# ' <= 1.2.3 ' => ' <=1.2.3 '
380+
# ' >= 1.2.3 ' => ' >=1.2.3 '
381+
# ' = 1.2.3 ' => ' =1.2.3 '
382+
# ' ~ 1.2.3 ' => ' ~1.2.3 '
383+
# ' ^ 1.2.3 ' => ' ^1.2.3 '
384+
# ' v 1.2.3 ' => ' v1.2.3 '
385+
s/ (v|<|>|<=|>=|=|~|\^) (([0-9]+|x)\.([0-9]+|x)\.([0-9]+|x)) / \1\2 /g;
386+
387+
# ' =1.2.3 ' => ' 1.2.3 '
388+
# ' v1.2.3 ' => ' 1.2.3 '
389+
s/ (=|v)//g;" |
390+
command awk '{
392391
# handle conversions of comparators with ^ or ~ or x into required grammar
393392
# ` ^0.0.1 ` => ` >=0.0.1 <0.0.2 `
394393
# ` ^0.1.2 ` => ` >=0.1.2 <0.2.0 `
@@ -462,8 +461,8 @@ nvm_normalize_semver() {
462461
}
463462
}
464463
print output
465-
}' \
466-
| command sed -E 's/^ +//;s/ +$//'
464+
}' |
465+
command sed -E 's/^ +//;s/ +$//'
467466
)
468467

469468
# only comparator_sets composed of the required grammar are marked as valid

test/fast/Unit tests/nvm_normalize_semver

+1-1
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@ while [ -n "$test_cases" ]; do
4848
expected_output=$(echo "$line" | awk -F: '{ print $2 }')
4949
actual_output=$(nvm_normalize_semver "$input")
5050
if [ -z "$input" ] || [ "$actual_output" != "$expected_output" ]; then
51-
die "nvm_validate_semver test case failed. Expected output: '$expected_output'. Actual output: '$actual_output'. Input: '$input'.\n"
51+
die "nvm_normalize_semver test case failed. Expected output: '$expected_output'. Actual output: '$actual_output'. Input: '$input'.\n"
5252
fi
5353
test_cases=$(echo "$test_cases" | tail -n +2)
5454
done

0 commit comments

Comments
 (0)