trim9.0 revision 303975
1# $FreeBSD: releng/11.0/bin/sh/tests/expansion/trim9.0 292758 2015-12-26 22:27:48Z jilles $ 2 3# POSIX does not specify these but they occasionally occur in the wild. 4# This just serves to keep working what currently works. 5 6failures='' 7ok='' 8 9testcase() { 10 code="$1" 11 expected="$2" 12 oIFS="$IFS" 13 eval "$code" 14 IFS='|' 15 result="$#|$*" 16 IFS="$oIFS" 17 if [ "x$result" = "x$expected" ]; then 18 ok=x$ok 19 else 20 failures=x$failures 21 echo "For $code, expected $expected actual $result" 22 fi 23} 24 25testcase 'shift $#; set -- "${*#Q}"' '1|' 26testcase 'shift $#; set -- "${*##Q}"' '1|' 27testcase 'shift $#; set -- "${*%Q}"' '1|' 28testcase 'shift $#; set -- "${*%%Q}"' '1|' 29testcase 'set -- Q R; set -- "${*#Q}"' '1| R' 30testcase 'set -- Q R; set -- "${*##Q}"' '1| R' 31testcase 'set -- Q R; set -- "${*%R}"' '1|Q ' 32testcase 'set -- Q R; set -- "${*%%R}"' '1|Q ' 33testcase 'set -- Q R; set -- "${*#S}"' '1|Q R' 34testcase 'set -- Q R; set -- "${*##S}"' '1|Q R' 35testcase 'set -- Q R; set -- "${*%S}"' '1|Q R' 36testcase 'set -- Q R; set -- "${*%%S}"' '1|Q R' 37testcase 'set -- Q R; set -- ${*#Q}' '1|R' 38testcase 'set -- Q R; set -- ${*##Q}' '1|R' 39testcase 'set -- Q R; set -- ${*%R}' '1|Q' 40testcase 'set -- Q R; set -- ${*%%R}' '1|Q' 41testcase 'set -- Q R; set -- ${*#S}' '2|Q|R' 42testcase 'set -- Q R; set -- ${*##S}' '2|Q|R' 43testcase 'set -- Q R; set -- ${*%S}' '2|Q|R' 44testcase 'set -- Q R; set -- ${*%%S}' '2|Q|R' 45testcase 'set -- Q R; set -- ${@#Q}' '1|R' 46testcase 'set -- Q R; set -- ${@##Q}' '1|R' 47testcase 'set -- Q R; set -- ${@%R}' '1|Q' 48testcase 'set -- Q R; set -- ${@%%R}' '1|Q' 49testcase 'set -- Q R; set -- ${@#S}' '2|Q|R' 50testcase 'set -- Q R; set -- ${@##S}' '2|Q|R' 51testcase 'set -- Q R; set -- ${@%S}' '2|Q|R' 52testcase 'set -- Q R; set -- ${@%%S}' '2|Q|R' 53testcase 'set -- Q R; set -- "${@#Q}"' '2||R' 54testcase 'set -- Q R; set -- "${@%R}"' '2|Q|' 55testcase 'set -- Q R; set -- "${@%%R}"' '2|Q|' 56testcase 'set -- Q R; set -- "${@#S}"' '2|Q|R' 57testcase 'set -- Q R; set -- "${@##S}"' '2|Q|R' 58testcase 'set -- Q R; set -- "${@%S}"' '2|Q|R' 59testcase 'set -- Q R; set -- "${@%%S}"' '2|Q|R' 60 61test "x$failures" = x 62