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