mirror of
git://projects.qi-hardware.com/eda-tools.git
synced 2024-11-04 23:05:21 +02:00
240 lines
4.3 KiB
Bash
Executable File
240 lines
4.3 KiB
Bash
Executable File
#!/bin/bash
|
|
. ./Common
|
|
|
|
###############################################################################
|
|
|
|
tst "substitutions: match fixed string, return other string (match)" \
|
|
-ds -q FOO=x <<EOF
|
|
!-s
|
|
FOO=x { BAR=y }
|
|
EOF
|
|
|
|
expect <<EOF
|
|
FOO=RE {
|
|
BAR=y
|
|
}
|
|
BAR=y
|
|
EOF
|
|
|
|
#------------------------------------------------------------------------------
|
|
|
|
tst "substitutions: match fixed string, return other string (no match)" \
|
|
-q FOO=y <<EOF
|
|
!-s
|
|
FOO=x { BAR=y }
|
|
EOF
|
|
|
|
expect <<EOF
|
|
EOF
|
|
|
|
#------------------------------------------------------------------------------
|
|
|
|
tst "substitutions: match fixed string, return input" -ds -q FOO=x <<EOF
|
|
!-s
|
|
FOO=x { BAR=\$\$ }
|
|
EOF
|
|
|
|
expect <<EOF
|
|
FOO=RE {
|
|
BAR=\$\$
|
|
}
|
|
BAR=x
|
|
EOF
|
|
|
|
#------------------------------------------------------------------------------
|
|
|
|
tst "substitutions: match *, return input" -q FOO=xyz <<EOF
|
|
!-s
|
|
FOO=* { BAR=\$\$ }
|
|
EOF
|
|
|
|
expect <<EOF
|
|
BAR=xyz
|
|
EOF
|
|
|
|
#------------------------------------------------------------------------------
|
|
|
|
tst "substitutions: match ??? with xyz" -q FOO=xyz <<EOF
|
|
!-s
|
|
FOO=??? { BAR=x }
|
|
EOF
|
|
|
|
expect <<EOF
|
|
BAR=x
|
|
EOF
|
|
|
|
#------------------------------------------------------------------------------
|
|
|
|
tst "substitutions: don't match ??? with axyz" -q FOO=axyz <<EOF
|
|
!-s
|
|
FOO=??? { BAR=x }
|
|
EOF
|
|
|
|
expect <<EOF
|
|
EOF
|
|
|
|
#------------------------------------------------------------------------------
|
|
|
|
tst "substitutions: don't match ??? with xyza" -q FOO=xyza <<EOF
|
|
!-s
|
|
FOO=??? { BAR=x }
|
|
EOF
|
|
|
|
expect <<EOF
|
|
EOF
|
|
|
|
#------------------------------------------------------------------------------
|
|
|
|
tst "substitutions: match ?.? with x.z" -q FOO=x.z <<EOF
|
|
!-s
|
|
FOO=?.? { BAR=x }
|
|
EOF
|
|
|
|
expect <<EOF
|
|
BAR=x
|
|
EOF
|
|
|
|
#------------------------------------------------------------------------------
|
|
|
|
tst "substitutions: don't match ?.? with xyz" -q FOO=xyz <<EOF
|
|
!-s
|
|
FOO=?.? { BAR=x }
|
|
EOF
|
|
|
|
expect <<EOF
|
|
EOF
|
|
|
|
#------------------------------------------------------------------------------
|
|
|
|
tst "substitutions: match ?(?)?, return \$1" -q FOO=xyz <<EOF
|
|
!-s
|
|
FOO=?(?)? { BAR=\$1 }
|
|
EOF
|
|
|
|
expect <<EOF
|
|
BAR=y
|
|
EOF
|
|
|
|
#------------------------------------------------------------------------------
|
|
|
|
tst "substitutions: match ?(*)?, return \$1" -q FOO=xyzzy <<EOF
|
|
!-s
|
|
FOO=?(*)? { BAR=\$1 }
|
|
EOF
|
|
|
|
expect <<EOF
|
|
BAR=yzz
|
|
EOF
|
|
|
|
#------------------------------------------------------------------------------
|
|
|
|
tst_fail "substitutions: $0 does not exist" -q FOO=xyzzy <<EOF
|
|
!-s
|
|
FOO=?(*)? { BAR=\$0 }
|
|
EOF
|
|
|
|
expect <<EOF
|
|
s:1: invalid variable name
|
|
EOF
|
|
|
|
#------------------------------------------------------------------------------
|
|
|
|
tst_fail "substitutions: $2 with only one () pair" -q FOO=xyzzy <<EOF
|
|
!-s
|
|
FOO=?(*)? { BAR=\$2 }
|
|
EOF
|
|
|
|
expect <<EOF
|
|
s:2: \$2 but only 1 parenthesis
|
|
EOF
|
|
|
|
#------------------------------------------------------------------------------
|
|
|
|
tst "substitutions: $2 with two () pairs" -q FOO=xyzzy <<EOF
|
|
!-s
|
|
FOO=?(?)(*)? { BAR=\$2 }
|
|
EOF
|
|
|
|
expect <<EOF
|
|
BAR=zz
|
|
EOF
|
|
|
|
#------------------------------------------------------------------------------
|
|
|
|
tst_fail "substitutions: $3 with only two () pairs" -q FOO=xyzzy <<EOF
|
|
!-s
|
|
FOO=?(?)(*)? { BAR=\$3 }
|
|
EOF
|
|
|
|
expect <<EOF
|
|
s:2: \$3 but only 2 parentheses
|
|
EOF
|
|
|
|
#------------------------------------------------------------------------------
|
|
|
|
tst "substitutions: [ab], match a" -q FOO=abc <<EOF
|
|
!-s
|
|
FOO=([ab])* { BAR=\$1 }
|
|
EOF
|
|
|
|
expect <<EOF
|
|
BAR=a
|
|
EOF
|
|
|
|
#------------------------------------------------------------------------------
|
|
|
|
tst "substitutions: [ab], match b" -q FOO=abc <<EOF
|
|
!-s
|
|
FOO=*([ab])* { BAR=\$1 }
|
|
EOF
|
|
|
|
expect <<EOF
|
|
BAR=b
|
|
EOF
|
|
|
|
#------------------------------------------------------------------------------
|
|
|
|
tst_fail "substitutions: [ab is invalid" <<EOF
|
|
!-s
|
|
FOO=[ab { BAR=x }
|
|
EOF
|
|
|
|
expect <<EOF
|
|
s:2: Unmatched [ or [^
|
|
EOF
|
|
|
|
#------------------------------------------------------------------------------
|
|
|
|
tst "substitutions: (a|b), match a" -q FOO=xa <<EOF
|
|
!-s
|
|
FOO=*(a|b) { BAR=\$1 }
|
|
EOF
|
|
|
|
expect <<EOF
|
|
BAR=a
|
|
EOF
|
|
|
|
#------------------------------------------------------------------------------
|
|
|
|
tst "substitutions: (a|b), match b" -q FOO=xb <<EOF
|
|
!-s
|
|
FOO=*(a|b) { BAR=\$1 }
|
|
EOF
|
|
|
|
expect <<EOF
|
|
BAR=b
|
|
EOF
|
|
|
|
#------------------------------------------------------------------------------
|
|
|
|
tst "substitutions: (|x), match the empty part" -q FOO=y <<EOF
|
|
!-s
|
|
FOO=(|x)y { BAR=\$1 }
|
|
EOF
|
|
|
|
expect <<EOF
|
|
BAR=
|
|
EOF
|
|
|
|
###############################################################################
|