trim9.0 revision 292758
1292758Sjilles# $FreeBSD: head/bin/sh/tests/expansion/trim9.0 292758 2015-12-26 22:27:48Z jilles $ 2292758Sjilles 3292758Sjilles# POSIX does not specify these but they occasionally occur in the wild. 4292758Sjilles# This just serves to keep working what currently works. 5292758Sjilles 6292758Sjillesfailures='' 7292758Sjillesok='' 8292758Sjilles 9292758Sjillestestcase() { 10292758Sjilles code="$1" 11292758Sjilles expected="$2" 12292758Sjilles oIFS="$IFS" 13292758Sjilles eval "$code" 14292758Sjilles IFS='|' 15292758Sjilles result="$#|$*" 16292758Sjilles IFS="$oIFS" 17292758Sjilles if [ "x$result" = "x$expected" ]; then 18292758Sjilles ok=x$ok 19292758Sjilles else 20292758Sjilles failures=x$failures 21292758Sjilles echo "For $code, expected $expected actual $result" 22292758Sjilles fi 23292758Sjilles} 24292758Sjilles 25292758Sjillestestcase 'shift $#; set -- "${*#Q}"' '1|' 26292758Sjillestestcase 'shift $#; set -- "${*##Q}"' '1|' 27292758Sjillestestcase 'shift $#; set -- "${*%Q}"' '1|' 28292758Sjillestestcase 'shift $#; set -- "${*%%Q}"' '1|' 29292758Sjillestestcase 'set -- Q R; set -- "${*#Q}"' '1| R' 30292758Sjillestestcase 'set -- Q R; set -- "${*##Q}"' '1| R' 31292758Sjillestestcase 'set -- Q R; set -- "${*%R}"' '1|Q ' 32292758Sjillestestcase 'set -- Q R; set -- "${*%%R}"' '1|Q ' 33292758Sjillestestcase 'set -- Q R; set -- "${*#S}"' '1|Q R' 34292758Sjillestestcase 'set -- Q R; set -- "${*##S}"' '1|Q R' 35292758Sjillestestcase 'set -- Q R; set -- "${*%S}"' '1|Q R' 36292758Sjillestestcase 'set -- Q R; set -- "${*%%S}"' '1|Q R' 37292758Sjillestestcase 'set -- Q R; set -- ${*#Q}' '1|R' 38292758Sjillestestcase 'set -- Q R; set -- ${*##Q}' '1|R' 39292758Sjillestestcase 'set -- Q R; set -- ${*%R}' '1|Q' 40292758Sjillestestcase 'set -- Q R; set -- ${*%%R}' '1|Q' 41292758Sjillestestcase 'set -- Q R; set -- ${*#S}' '2|Q|R' 42292758Sjillestestcase 'set -- Q R; set -- ${*##S}' '2|Q|R' 43292758Sjillestestcase 'set -- Q R; set -- ${*%S}' '2|Q|R' 44292758Sjillestestcase 'set -- Q R; set -- ${*%%S}' '2|Q|R' 45292758Sjillestestcase 'set -- Q R; set -- ${@#Q}' '1|R' 46292758Sjillestestcase 'set -- Q R; set -- ${@##Q}' '1|R' 47292758Sjillestestcase 'set -- Q R; set -- ${@%R}' '1|Q' 48292758Sjillestestcase 'set -- Q R; set -- ${@%%R}' '1|Q' 49292758Sjillestestcase 'set -- Q R; set -- ${@#S}' '2|Q|R' 50292758Sjillestestcase 'set -- Q R; set -- ${@##S}' '2|Q|R' 51292758Sjillestestcase 'set -- Q R; set -- ${@%S}' '2|Q|R' 52292758Sjillestestcase 'set -- Q R; set -- ${@%%S}' '2|Q|R' 53292758Sjillestestcase 'set -- Q R; set -- "${@#Q}"' '2||R' 54292758Sjillestestcase 'set -- Q R; set -- "${@%R}"' '2|Q|' 55292758Sjillestestcase 'set -- Q R; set -- "${@%%R}"' '2|Q|' 56292758Sjillestestcase 'set -- Q R; set -- "${@#S}"' '2|Q|R' 57292758Sjillestestcase 'set -- Q R; set -- "${@##S}"' '2|Q|R' 58292758Sjillestestcase 'set -- Q R; set -- "${@%S}"' '2|Q|R' 59292758Sjillestestcase 'set -- Q R; set -- "${@%%S}"' '2|Q|R' 60292758Sjilles 61292758Sjillestest "x$failures" = x 62