aboutsummaryrefslogtreecommitdiff
path: root/shell/hush_test
diff options
context:
space:
mode:
authorDenys Vlasenko <dvlasenk@redhat.com>2010-09-05 14:45:38 +0200
committerDenys Vlasenko <dvlasenk@redhat.com>2010-09-05 14:47:58 +0200
commit36f774a0cd2bf8dd72b192aab93831c5ac0c58f0 (patch)
treeafa0b3d247e4dd163b89b7b61f4e3e0f3143b102 /shell/hush_test
parent701e127f7d892909a58c6f3333e23588ccef9e22 (diff)
downloadbusybox-w32-36f774a0cd2bf8dd72b192aab93831c5ac0c58f0.tar.gz
busybox-w32-36f774a0cd2bf8dd72b192aab93831c5ac0c58f0.tar.bz2
busybox-w32-36f774a0cd2bf8dd72b192aab93831c5ac0c58f0.zip
hush: add support for ${var/pattern/repl}, conditional on bash compat
function old new delta expand_vars_to_list 2386 2833 +447 expand_string_to_string 69 110 +41 parse_dollar 681 721 +40 hush_main 963 945 -18 ------------------------------------------------------------------------------ (add/remove: 0/0 grow/shrink: 3/1 up/down: 528/-18) Total: 510 bytes Signed-off-by: Denys Vlasenko <dvlasenk@redhat.com>
Diffstat (limited to 'shell/hush_test')
-rw-r--r--shell/hush_test/hush-vars/var_bash1.right14
-rwxr-xr-xshell/hush_test/hush-vars/var_bash1.tests18
-rw-r--r--shell/hush_test/hush-vars/var_bash2.right10
-rwxr-xr-xshell/hush_test/hush-vars/var_bash2.tests24
-rw-r--r--shell/hush_test/hush-vars/var_bash3.right20
-rwxr-xr-xshell/hush_test/hush-vars/var_bash3.tests41
-rw-r--r--shell/hush_test/hush-vars/var_bash4.right23
-rwxr-xr-xshell/hush_test/hush-vars/var_bash4.tests47
-rw-r--r--shell/hush_test/hush-vars/var_bash5.right4
-rwxr-xr-xshell/hush_test/hush-vars/var_bash5.tests11
10 files changed, 212 insertions, 0 deletions
diff --git a/shell/hush_test/hush-vars/var_bash1.right b/shell/hush_test/hush-vars/var_bash1.right
new file mode 100644
index 000000000..c0a07699b
--- /dev/null
+++ b/shell/hush_test/hush-vars/var_bash1.right
@@ -0,0 +1,14 @@
1
2
3f
4bcdef
5abcdef
6abcdef
7bcde
8abcd
9abcd
10abcdef
11bcdef
12abcdef
13abcdef
14abcdef
diff --git a/shell/hush_test/hush-vars/var_bash1.tests b/shell/hush_test/hush-vars/var_bash1.tests
new file mode 100755
index 000000000..24d3c9a00
--- /dev/null
+++ b/shell/hush_test/hush-vars/var_bash1.tests
@@ -0,0 +1,18 @@
1var=abcdef
2
3echo ${var:7}
4echo ${var:6}
5echo ${var:5}
6echo ${var:1}
7echo ${var:0}
8echo ${var:-1}
9
10echo ${var:1:4}
11echo ${var:0:4}
12echo ${var::4}
13echo ${var:-1:4}
14
15echo ${var:1:7}
16echo ${var:0:7}
17echo ${var::7}
18echo ${var:-1:7}
diff --git a/shell/hush_test/hush-vars/var_bash2.right b/shell/hush_test/hush-vars/var_bash2.right
new file mode 100644
index 000000000..acba5c6fb
--- /dev/null
+++ b/shell/hush_test/hush-vars/var_bash2.right
@@ -0,0 +1,10 @@
1abc123xcba123
2abx123dcba123
3abx123dxba123
4abcx23dcba123
5abcxxxdcbaxxx
6abx
7xba123
8abx23
9abc23dcba123
10abcdcba
diff --git a/shell/hush_test/hush-vars/var_bash2.tests b/shell/hush_test/hush-vars/var_bash2.tests
new file mode 100755
index 000000000..29c526cef
--- /dev/null
+++ b/shell/hush_test/hush-vars/var_bash2.tests
@@ -0,0 +1,24 @@
1var=abc123dcba123
2
3echo ${var/d/x}
4echo ${var/c/x}
5echo ${var//c/x}
6echo ${var/[123]/x}
7echo ${var//[123]/x}
8echo ${var/c*/x}
9echo ${var/*c/x}
10
11# must match longest match: result is "abx23"
12echo ${var/c*1/x}
13
14# empty replacement - 2nd slash can be omitted
15echo ${var/[123]}
16echo ${var//[123]}
17
18### ash doesn't support
19### # match only at the beginning:
20### echo ${var/#a/x}
21### echo ${var/#b/x} # should not match
22### echo ${var//#b/x} # should not match
23### # match only at the end:
24### echo ${var/%3/x}
diff --git a/shell/hush_test/hush-vars/var_bash3.right b/shell/hush_test/hush-vars/var_bash3.right
new file mode 100644
index 000000000..a97c850ea
--- /dev/null
+++ b/shell/hush_test/hush-vars/var_bash3.right
@@ -0,0 +1,20 @@
11 a041#c
22 a041#c
33 a\041#c
44 a\041#c
55 a\041#c
66 a\041#c
77 a\041#c
88 a\041#c
99 a\041#c
1010 a\c
1111 a\c
1212 a\c
1313 a\\c
1414 a\\c
1515 a\\c
1616 a\tc
1717 a\tc
1818 a\tc
1919 atc
2020 a\tc
diff --git a/shell/hush_test/hush-vars/var_bash3.tests b/shell/hush_test/hush-vars/var_bash3.tests
new file mode 100755
index 000000000..146dbb6a5
--- /dev/null
+++ b/shell/hush_test/hush-vars/var_bash3.tests
@@ -0,0 +1,41 @@
1a='abc'
2r=${a//b/\041#}
3echo 1 $r
4echo 2 ${a//b/\041#}
5echo 3 "${a//b/\041#}"
6
7a='abc'
8r=${a//b/\\041#}
9echo 4 $r
10echo 5 ${a//b/\\041#}
11echo 6 "${a//b/\\041#}"
12
13a='abc'
14b='\041#'
15r=${a//b/$b}
16echo 7 $r
17echo 8 ${a//b/$b}
18echo 9 "${a//b/$b}"
19
20a='abc'
21b='\'
22r="${a//b/$b}"
23echo 10 $r
24echo 11 ${a//b/$b}
25echo 12 "${a//b/$b}"
26
27a='abc'
28b='\\'
29r="${a//b/$b}"
30echo 13 $r
31echo 14 ${a//b/$b}
32echo 15 "${a//b/$b}"
33
34a='abc'
35b='\t'
36r="${a//b/$b}"
37echo 16 $r
38echo 17 ${a//b/$b}
39echo 18 "${a//b/$b}"
40echo 19 ${a//b/\t}
41echo 20 "${a//b/\t}"
diff --git a/shell/hush_test/hush-vars/var_bash4.right b/shell/hush_test/hush-vars/var_bash4.right
new file mode 100644
index 000000000..600e8532f
--- /dev/null
+++ b/shell/hush_test/hush-vars/var_bash4.right
@@ -0,0 +1,23 @@
1Source: a*b\*c
2Replace str: _\\_\z_
3Pattern: single backslash and star: "replace literal star"
4In assignment: a_\_z_b\*c
5Unquoted: a_\_z_b\*c
6Quoted: a_\_\z_b\*c
7Pattern: double backslash and star: "replace backslash and everything after it"
8In assignment: a*b_\_z_
9Unquoted: a*b_\_z_
10Quoted: a*b_\_\z_
11
12Source: a\bc
13Replace str: _\\_\z_
14Pattern: single backslash and b: "replace b"
15In assignment: a\_\_z_c
16Unquoted: a\_\_z_c
17Quoted: a\_\_\z_c
18Pattern: double backslash and b: "replace backslash and b"
19In assignment: a_\_z_c
20Unquoted: a_\_z_c
21Quoted: a_\_\z_c
22
23Done: 0
diff --git a/shell/hush_test/hush-vars/var_bash4.tests b/shell/hush_test/hush-vars/var_bash4.tests
new file mode 100755
index 000000000..d5470614b
--- /dev/null
+++ b/shell/hush_test/hush-vars/var_bash4.tests
@@ -0,0 +1,47 @@
1# This testcase demonstrates that backslashes are treated differently
2# in 1st and 2nd parts of ${var/search/repl}:
3# if quoted ("${var/search/repl}"), and repl contains \a (a non-special char),
4# the backslash in repl stays; if unquoted, backslash is removed.
5# But search part does not act like that: \a is always converted to just a,
6# even in quotes.
7#
8# bash4 (and probably bash3 too): "Quoted:" results are different from
9# unquoted and assignment expansions - they have a backslash before z.
10
11v='a*b\*c'
12echo 'Source: ' "$v"
13echo 'Replace str: ' '_\\_\z_'
14
15echo 'Pattern: ' 'single backslash and star: "replace literal star"'
16r=${v/\*/_\\_\z_}
17echo 'In assignment:' "$r"
18echo 'Unquoted: ' ${v/\*/_\\_\z_}
19echo 'Quoted: ' "${v/\*/_\\_\z_}"
20
21echo 'Pattern: ' 'double backslash and star: "replace backslash and everything after it"'
22r=${v/\\*/_\\_\z_}
23echo 'In assignment:' "$r"
24echo 'Unquoted: ' ${v/\\*/_\\_\z_}
25echo 'Quoted: ' "${v/\\*/_\\_\z_}"
26
27echo
28
29v='a\bc'
30echo 'Source: ' "$v"
31echo 'Replace str: ' '_\\_\z_'
32
33echo 'Pattern: ' 'single backslash and b: "replace b"'
34r=${v/\b/_\\_\z_}
35echo 'In assignment:' "$r"
36echo 'Unquoted: ' ${v/\b/_\\_\z_}
37echo 'Quoted: ' "${v/\b/_\\_\z_}"
38
39echo 'Pattern: ' 'double backslash and b: "replace backslash and b"'
40r=${v/\\b/_\\_\z_}
41echo 'In assignment:' "$r"
42echo 'Unquoted: ' ${v/\\b/_\\_\z_}
43echo 'Quoted: ' "${v/\\b/_\\_\z_}"
44
45echo
46
47echo Done: $?
diff --git a/shell/hush_test/hush-vars/var_bash5.right b/shell/hush_test/hush-vars/var_bash5.right
new file mode 100644
index 000000000..278ed3228
--- /dev/null
+++ b/shell/hush_test/hush-vars/var_bash5.right
@@ -0,0 +1,4 @@
1a/
2a/d
3a/e/f
4Done: 0
diff --git a/shell/hush_test/hush-vars/var_bash5.tests b/shell/hush_test/hush-vars/var_bash5.tests
new file mode 100755
index 000000000..7f482a554
--- /dev/null
+++ b/shell/hush_test/hush-vars/var_bash5.tests
@@ -0,0 +1,11 @@
1# This testcase checks whether slashes in ${v/a/b} are parsed before
2# or after expansions
3
4v='a/b/c'
5s='b/c'
6r='e/f'
7echo "${v/$s}"
8echo "${v/$s/d}"
9echo "${v/$s/$r}"
10
11echo Done: $?