ash testsuite: update some of variable tests with newer versions from hush

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
This commit is contained in:
Denys Vlasenko 2016-10-02 18:08:04 +02:00
parent c4cf542c57
commit e3354bc44a
6 changed files with 156 additions and 25 deletions

View File

@ -1,23 +1,40 @@
Source: a*b\*c
Replace str: _\\_\z_
Pattern: single backslash and star: "replace literal star"
In assignment: a_\_z_b\*c
Unquoted: a_\_z_b\*c
Unquoted =: a_\_z_b\*c
Quoted: a_\_\z_b\*c
Quoted =: a_\_\z_b\*c
Pattern: double backslash and star: "replace backslash and everything after it"
In assignment: a*b_\_z_
Unquoted: a*b_\_z_
Unquoted =: a*b_\_z_
Quoted: a*b_\_\z_
Quoted =: a*b_\_\z_
Source: a\bc
Replace str: _\\_\z_
Pattern: single backslash and b: "replace b"
In assignment: a\_\_z_c
Unquoted: a\_\_z_c
Unquoted =: a\_\_z_c
Quoted: a\_\_\z_c
Quoted =: a\_\_\z_c
Pattern: double backslash and b: "replace backslash and b"
In assignment: a_\_z_c
Unquoted: a_\_z_c
Unquoted =: a_\_z_c
Quoted: a_\_\z_c
Quoted =: a_\_\z_c
Source: a\bc
Replace str: _\\_\z_ (as variable $s)
Pattern: single backslash and b: "replace b"
Unquoted: a\_\\_\z_c
Unquoted =: a\_\\_\z_c
Quoted: a\_\\_\z_c
Quoted =: a\_\\_\z_c
Pattern: double backslash and b: "replace backslash and b"
Unquoted: a_\\_\z_c
Unquoted =: a_\\_\z_c
Quoted: a_\\_\z_c
Quoted =: a_\\_\z_c
Done: 0

View File

@ -6,23 +6,30 @@
# even in quotes.
#
# bash4 (and probably bash3 too): "Quoted:" results are different from
# unquoted and assignment expansions - they have a backslash before z.
# unquoted expansions - they have a backslash before z.
#
# The difference only exists if repl is a literal. If it is a variable:
# ${v/.../$s}, then all backslashes are preserved in both cases.
v='a*b\*c'
echo 'Source: ' "$v"
echo 'Replace str: ' '_\\_\z_'
echo 'Pattern: ' 'single backslash and star: "replace literal star"'
r=${v/\*/_\\_\z_}
echo 'In assignment:' "$r"
echo 'Unquoted: ' ${v/\*/_\\_\z_}
r=${v/\*/_\\_\z_}
echo 'Unquoted =: ' "$r"
echo 'Quoted: ' "${v/\*/_\\_\z_}"
r="${v/\*/_\\_\z_}"
echo 'Quoted =: ' "$r"
echo 'Pattern: ' 'double backslash and star: "replace backslash and everything after it"'
r=${v/\\*/_\\_\z_}
echo 'In assignment:' "$r"
echo 'Unquoted: ' ${v/\\*/_\\_\z_}
r=${v/\\*/_\\_\z_}
echo 'Unquoted =: ' "$r"
echo 'Quoted: ' "${v/\\*/_\\_\z_}"
r="${v/\\*/_\\_\z_}"
echo 'Quoted =: ' "$r"
echo
@ -31,16 +38,43 @@ echo 'Source: ' "$v"
echo 'Replace str: ' '_\\_\z_'
echo 'Pattern: ' 'single backslash and b: "replace b"'
r=${v/\b/_\\_\z_}
echo 'In assignment:' "$r"
echo 'Unquoted: ' ${v/\b/_\\_\z_}
r=${v/\b/_\\_\z_}
echo 'Unquoted =: ' "$r"
echo 'Quoted: ' "${v/\b/_\\_\z_}"
r="${v/\b/_\\_\z_}"
echo 'Quoted =: ' "$r"
echo 'Pattern: ' 'double backslash and b: "replace backslash and b"'
r=${v/\\b/_\\_\z_}
echo 'In assignment:' "$r"
echo 'Unquoted: ' ${v/\\b/_\\_\z_}
r=${v/\\b/_\\_\z_}
echo 'Unquoted =: ' "$r"
echo 'Quoted: ' "${v/\\b/_\\_\z_}"
r="${v/\\b/_\\_\z_}"
echo 'Quoted =: ' "$r"
echo
v='a\bc'
s='_\\_\z_'
echo 'Source: ' "$v"
echo 'Replace str: ' "$s" '(as variable $s)'
echo 'Pattern: ' 'single backslash and b: "replace b"'
echo 'Unquoted: ' ${v/\b/$s}
r=${v/\b/$s}
echo 'Unquoted =: ' "$r"
echo 'Quoted: ' "${v/\b/$s}"
r="${v/\b/$s}"
echo 'Quoted =: ' "$r"
echo 'Pattern: ' 'double backslash and b: "replace backslash and b"'
echo 'Unquoted: ' ${v/\\b/$s}
r=${v/\\b/$s}
echo 'Unquoted =: ' "$r"
echo 'Quoted: ' "${v/\\b/$s}"
r="${v/\\b/$s}"
echo 'Quoted =: ' "$r"
echo

View File

@ -1,4 +1,11 @@
a/
a/d
a/e/f
1 a/
2 a/d
3 a/e/f
4 a\
5 a\d
6 a\e\f
7 a\\
8 a\\d
9 a\\e\\f
a ab
Done: 0

View File

@ -4,8 +4,26 @@
v='a/b/c'
s='b/c'
r='e/f'
echo "${v/$s}"
echo "${v/$s/d}"
echo "${v/$s/$r}"
echo "1 ${v/$s}"
echo "2 ${v/$s/d}"
echo "3 ${v/$s/$r}"
v='a\b\c'
s='b\\c'
r='e\f'
echo "4 ${v/$s}"
echo "5 ${v/$s/d}"
echo "6 ${v/$s/$r}"
v='a\\b\\c'
s='b\\\\c'
r='e\\f'
echo "7 ${v/$s}"
echo "8 ${v/$s/d}"
echo "9 ${v/$s/$r}"
v='a-$a-\t-\\-\"-\`-\--\z-\*-\?-b'
s='-$a-\\t-\\\\-\\"-\\`-\\--\\z-\\\*-\\\?-'
echo "a ${v/$s}"
echo Done: $?

View File

@ -1,3 +1,19 @@
Empty:
Empty:
Empty:
Empty:
Empty:
Empty:
Empty:
Empty:
Empty:
Empty:
Empty:
Empty:
Empty:
Empty:
Empty:
Empty:
abcdcd
abcdcd
abcdcd
@ -5,7 +21,9 @@ cdcd
babcdcd
babcdcd
ababcdcd
Empty:
ababcdcd}_tail
ababcdcd_tail
ababcd
ababcd
ababcd
@ -13,5 +31,11 @@ abab
ababcdc
ababcdc
ababcdcd
end
Empty:
ababcdcd}_tail
ababcdcd_tail
ababcdcd
ab
ab
ab
End

View File

@ -1,3 +1,25 @@
unset var
echo Empty:${var#}
echo Empty:${var##}
echo Empty:${var#*}
echo Empty:${var##*}
echo Empty:${var%}
echo Empty:${var%%}
echo Empty:${var%*}
echo Empty:${var%%*}
var=
echo Empty:${var#}
echo Empty:${var##}
echo Empty:${var#*}
echo Empty:${var##*}
echo Empty:${var%}
echo Empty:${var%%}
echo Empty:${var%*}
echo Empty:${var%%*}
var=ababcdcd
echo ${var#ab}
@ -7,7 +29,9 @@ echo ${var##a*b}
echo ${var#?}
echo ${var##?}
echo ${var#*}
echo ${var##*}
echo Empty:${var##*}
echo ${var#}}_tail
echo ${var#\}}_tail
echo ${var%cd}
echo ${var%%cd}
@ -16,6 +40,13 @@ echo ${var%%c*d}
echo ${var%?}
echo ${var%%?}
echo ${var%*}
echo ${var%%*}
echo Empty:${var%%*}
echo ${var#}}_tail
echo ${var#\}}_tail
echo ${var%\\*}
echo end
a=ab}; echo ${a%\}};
a=abc; c=c; echo ${a%${c}}
a=ab{{c; echo ${a%`echo {{c`}
echo End