1#! /bin/sh 2. "${srcdir=.}/init.sh"; path_prepend_ . ../src 3 4# Test recognition of PHP format strings. 5 6cat <<\EOF > f-ph-1.data 7# Valid: no argument 8"abc%%" 9# Valid: one string argument 10"abc%s" 11# Valid: one integer argument 12"abc%b" 13# Valid: one integer argument 14"abc%d" 15# Valid: one integer argument 16"abc%u" 17# Valid: one integer argument 18"abc%o" 19# Valid: one integer argument 20"abc%x" 21# Valid: one integer argument 22"abc%X" 23# Valid: one floating-point argument 24"abc%e" 25# Valid: one floating-point argument 26"abc%f" 27# Valid: one character argument 28"abc%c" 29# Valid: one argument with flags 30"abc%-f" 31# Valid: one argument with padding flags 32"abc%'=f" 33# Valid: one argument with width 34"abc%2f" 35# Valid: one argument with precision 36"abc%.4f" 37# Valid: one argument with width and precision 38"abc%14.4f" 39# Invalid: unterminated 40"abc%" 41# Invalid: unknown format specifier 42"abc%y" 43# Invalid: unknown format specifier 44"abc%F" 45# Invalid: flags after width 46"abc%5-f" 47# Invalid: twice precision 48"abc%.4.2f" 49# Valid: three arguments 50"abc%d%x%x" 51# Valid: a numbered argument 52"abc%1$d" 53# Invalid: zero 54"abc%0$d" 55# Valid: two-digit numbered arguments 56"abc%11$def%10$dgh%9$dij%8$dkl%7$dmn%6$dop%5$dqr%4$dst%3$duv%2$dwx%1$dyz" 57# Invalid: unterminated number 58"abc%1" 59# Invalid: flags before number 60"abc%-1$d" 61# Valid: three arguments, two with same number 62"abc%1$4x,%2$c,%1$u" 63# Invalid: argument with conflicting types 64"abc%1$4x,%2$c,%1$s" 65# Valid: no conflict 66"abc%1$4x,%2$c,%1$u" 67# Valid: mixing of numbered and unnumbered arguments 68"abc%d%2$x" 69# Valid: numbered argument with constant precision 70"abc%1$.9x" 71# Valid: missing non-final argument 72"abc%2$x%3$s" 73# Valid: permutation 74"abc%2$ddef%1$d" 75# Valid: multiple uses of same argument 76"abc%2$xdef%1$sghi%2$x" 77EOF 78 79: ${XGETTEXT=xgettext} 80n=0 81while read comment; do 82 read string 83 n=`expr $n + 1` 84 echo "<?= gettext(${string}) ?>" | sed -e 's/\$/\\\$/g' > f-ph-1-$n.in 85 ${XGETTEXT} -L PHP -o f-ph-1-$n.po f-ph-1-$n.in || Exit 1 86 test -f f-ph-1-$n.po || Exit 1 87 fail= 88 if echo "$comment" | grep 'Valid:' > /dev/null; then 89 if grep php-format f-ph-1-$n.po > /dev/null; then 90 : 91 else 92 fail=yes 93 fi 94 else 95 if grep php-format f-ph-1-$n.po > /dev/null; then 96 fail=yes 97 else 98 : 99 fi 100 fi 101 if test -n "$fail"; then 102 echo "Format string recognition error:" 1>&2 103 cat f-ph-1-$n.in 1>&2 104 echo "Got:" 1>&2 105 cat f-ph-1-$n.po 1>&2 106 Exit 1 107 fi 108 rm -f f-ph-1-$n.in f-ph-1-$n.po 109done < f-ph-1.data 110 111Exit 0 112