mirror of
git://projects.qi-hardware.com/eda-tools.git
synced 2024-12-22 19:32:26 +02:00
b2/test/subesc: more tests; also for values; add explanation of escaping
This commit is contained in:
parent
a52247294b
commit
7f24ef0e5b
103
b2/test/subesc
103
b2/test/subesc
@ -1,9 +1,23 @@
|
||||
#!/bin/bash
|
||||
. ./Common
|
||||
|
||||
#
|
||||
# Note that we have to escape things for the shell as well. In general,
|
||||
# for any character C, \C becomes C. However, in the case of <<EOF ... EOF,
|
||||
# \ is left as is if it doesn't precede a special character.
|
||||
#
|
||||
|
||||
###############################################################################
|
||||
|
||||
tst "substitutions: escape *" -R '*\\*' <<EOF
|
||||
tst "substitutions: escape x in regexp" -R '*\\x' <<EOF
|
||||
EOF
|
||||
|
||||
expect <<EOF
|
||||
^.*\\x\$
|
||||
EOF
|
||||
|
||||
#------------------------------------------------------------------------------
|
||||
tst "substitutions: escape * in regexp" -R '*\\*' <<EOF
|
||||
EOF
|
||||
|
||||
expect <<EOF
|
||||
@ -12,7 +26,7 @@ EOF
|
||||
|
||||
#------------------------------------------------------------------------------
|
||||
|
||||
tst "substitutions: escape . (implicit)" -R 'x.y' <<EOF
|
||||
tst "substitutions: escape . in regexp (implicit)" -R 'x.y' <<EOF
|
||||
EOF
|
||||
|
||||
expect <<EOF
|
||||
@ -21,7 +35,7 @@ EOF
|
||||
|
||||
#------------------------------------------------------------------------------
|
||||
|
||||
tst "substitutions: escape |" -R 'a\\\|b' <<EOF
|
||||
tst "substitutions: escape | in regexp" -R 'a\\\|b' <<EOF
|
||||
EOF
|
||||
|
||||
expect <<EOF
|
||||
@ -30,7 +44,7 @@ EOF
|
||||
|
||||
#------------------------------------------------------------------------------
|
||||
|
||||
tst "substitutions: escape \\" -R 'x\\\\y' <<EOF
|
||||
tst "substitutions: escape \\ in regexp" -R 'x\\\\y' <<EOF
|
||||
EOF
|
||||
|
||||
expect <<EOF
|
||||
@ -39,11 +53,90 @@ EOF
|
||||
|
||||
#------------------------------------------------------------------------------
|
||||
|
||||
tst_fail "substitutions: escape EOL" -R 'x\\' <<EOF
|
||||
tst_fail "substitutions: try to escape EOL in regexp" -R 'x\\' <<EOF
|
||||
EOF
|
||||
|
||||
expect <<EOF
|
||||
dummy:2: regexp ends with backslash
|
||||
EOF
|
||||
|
||||
#------------------------------------------------------------------------------
|
||||
|
||||
tst "substitutions: escape space in regexp (match)" -q '"x=a c"' <<EOF
|
||||
!-s
|
||||
y=a
|
||||
x=a\ c { y=b }
|
||||
EOF
|
||||
|
||||
expect <<EOF
|
||||
y=b
|
||||
EOF
|
||||
|
||||
#------------------------------------------------------------------------------
|
||||
|
||||
tst "substitutions: escape space in regexp (no match)" -q '"x=a b"' <<EOF
|
||||
!-s
|
||||
y=a
|
||||
x=a\ c { y=b }
|
||||
EOF
|
||||
|
||||
expect <<EOF
|
||||
y=a
|
||||
EOF
|
||||
|
||||
#------------------------------------------------------------------------------
|
||||
|
||||
tst "substitutions: escape \$ in value" -q <<EOF
|
||||
!-s
|
||||
x=y\\$
|
||||
EOF
|
||||
|
||||
expect <<EOF
|
||||
x=y\$
|
||||
EOF
|
||||
|
||||
#------------------------------------------------------------------------------
|
||||
|
||||
tst "substitutions: escape x in value" -q <<EOF
|
||||
!-s
|
||||
x=y\x
|
||||
EOF
|
||||
|
||||
expect <<EOF
|
||||
x=yx
|
||||
EOF
|
||||
|
||||
#------------------------------------------------------------------------------
|
||||
|
||||
tst "substitutions: escape space in value" -q <<EOF
|
||||
!-s
|
||||
x=x\ y
|
||||
EOF
|
||||
|
||||
expect <<EOF
|
||||
x=x y
|
||||
EOF
|
||||
|
||||
#------------------------------------------------------------------------------
|
||||
|
||||
tst "substitutions: escape \\ in value" -q <<EOF
|
||||
!-s
|
||||
x=a\\\\b
|
||||
EOF
|
||||
|
||||
expect <<EOF
|
||||
x=a\\b
|
||||
EOF
|
||||
|
||||
#------------------------------------------------------------------------------
|
||||
|
||||
tst_fail "substitutions: try to escape EOL in value" -q <<EOF
|
||||
!-s
|
||||
x=y\\
|
||||
EOF
|
||||
|
||||
expect <<EOF
|
||||
s:1: syntax error
|
||||
EOF
|
||||
|
||||
###############################################################################
|
||||
|
Loading…
Reference in New Issue
Block a user