1
0
mirror of git://projects.qi-hardware.com/eda-tools.git synced 2024-07-01 03:22:01 +03:00

b2/test/: add first set of substitution tests

This commit is contained in:
Werner Almesberger 2012-06-03 02:10:12 -03:00
parent b35b6e2688
commit fb7b2461a5
3 changed files with 375 additions and 0 deletions

48
b2/test/subfn Executable file
View File

@ -0,0 +1,48 @@
#!/bin/bash
. ./Common
###############################################################################
tst "substitutions: F1 -> FN (expand \$\$)" -q F1=foo <<EOF
!-s
FN=* { RES=\$\$ }
EOF
expect <<EOF
RES=foo
EOF
#------------------------------------------------------------------------------
tst "substitutions: F2 -> FN (expand \$\$)" -q F1=foo F2=bar <<EOF
!-s
FN=?a? { RES=\$\$ }
EOF
expect <<EOF
RES=bar
EOF
#------------------------------------------------------------------------------
tst_fail "substitutions: F* -> FN (expand \$FN)" -q F1=foo <<EOF
!-s
FN=* { RES=\$FN }
EOF
expect <<EOF
s:2: \$FN may be undefined
EOF
#------------------------------------------------------------------------------
tst_fail "substitutions: assign to FN" <<EOF
!-s
FN=foo
EOF
expect <<EOF
s:2: can't assign to pseudo-variable FN
EOF
###############################################################################

239
b2/test/subre Executable file
View File

@ -0,0 +1,239 @@
#!/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
###############################################################################

88
b2/test/subvar Executable file
View File

@ -0,0 +1,88 @@
#!/bin/bash
. ./Common
###############################################################################
tst "substitutions: variable expansion $FOO" -ds -q <<EOF
!-s
FOO=x
BAR = \$FOO
EOF
expect <<EOF
FOO=x
BAR=\${FOO}
FOO=x
BAR=x
EOF
#------------------------------------------------------------------------------
tst "substitutions: variable expansion ${FOO}bar" -ds -q <<EOF
!-s
FOO=x
BAR = \${FOO}bar
EOF
expect <<EOF
FOO=x
BAR=\${FOO}bar
FOO=x
BAR=xbar
EOF
#------------------------------------------------------------------------------
tst_fail "substitutions: expand unknown variable" -ds <<EOF
!-s
BAR = \${FOO}
EOF
expect <<EOF
s:2: \$FOO may be undefined
EOF
#------------------------------------------------------------------------------
tst "substitutions: expand variable used in match" -ds -q FOO=blah <<EOF
!-s
FOO = * { BAR = \$FOO }
EOF
expect <<EOF
FOO=RE {
BAR=\${FOO}
}
BAR=blah
EOF
#------------------------------------------------------------------------------
tst_fail "substitutions: expand variable used in different branch" -ds <<EOF
!-s
FOO = * { BAR = \$FOO }
FOO = \$BAR
EOF
expect <<EOF
s:3: \$BAR may be undefined
EOF
#------------------------------------------------------------------------------
tst "substitutions: expand two variables" -ds -q <<EOF
!-s
FOO = a
BAR = b
FOO = \$FOO\$BAR
EOF
expect <<EOF
FOO=a
BAR=b
FOO=\${FOO}\${BAR}
FOO=ab
BAR=b
EOF
###############################################################################