1#! /bin/sh 2. "${srcdir=.}/init.sh"; path_prepend_ . ../src 3 4# Test checking of PHP format strings. 5 6cat <<\EOF > f-ph-2.data 7# Valid: %% doesn't count 8msgid "abc%%def" 9msgstr "xyz" 10# Invalid: invalid msgstr 11msgid "abc%%def" 12msgstr "xyz%" 13# Valid: same arguments 14msgid "abc%s%gdef" 15msgstr "xyz%s%g" 16# Valid: same arguments, with different widths 17msgid "abc%2sdef" 18msgstr "xyz%3s" 19# Valid: same arguments but in numbered syntax 20msgid "abc%s%gdef" 21msgstr "xyz%1$s%2$g" 22# Valid: permutation 23msgid "abc%s%g%cdef" 24msgstr "xyz%3$c%2$g%1$s" 25# Invalid: too few arguments 26msgid "abc%2$udef%1$s" 27msgstr "xyz%1$s" 28# Invalid: too few arguments 29msgid "abc%sdef%u" 30msgstr "xyz%s" 31# Invalid: too many arguments 32msgid "abc%udef" 33msgstr "xyz%uvw%c" 34# Valid: same numbered arguments, with different widths 35msgid "abc%2$5s%1$4s" 36msgstr "xyz%2$4s%1$5s" 37# Invalid: missing argument 38msgid "abc%2$sdef%1$u" 39msgstr "xyz%1$u" 40# Invalid: missing argument 41msgid "abc%1$sdef%2$u" 42msgstr "xyz%2$u" 43# Invalid: added argument 44msgid "abc%1$udef" 45msgstr "xyz%1$uvw%2$c" 46# Valid: type compatibility 47msgid "abc%b" 48msgstr "xyz%d" 49# Valid: type compatibility 50msgid "abc%u" 51msgstr "xyz%d" 52# Valid: type compatibility 53msgid "abc%o" 54msgstr "xyz%d" 55# Valid: type compatibility 56msgid "abc%x" 57msgstr "xyz%d" 58# Valid: type compatibility 59msgid "abc%X" 60msgstr "xyz%d" 61# Valid: type compatibility 62msgid "abc%e" 63msgstr "xyz%f" 64# Invalid: type incompatibility 65msgid "abc%s" 66msgstr "xyz%d" 67# Invalid: type incompatibility 68msgid "abc%s" 69msgstr "xyz%e" 70# Invalid: type incompatibility 71msgid "abc%s" 72msgstr "xyz%c" 73# Invalid: type incompatibility 74msgid "abc%d" 75msgstr "xyz%e" 76# Invalid: type incompatibility 77msgid "abc%d" 78msgstr "xyz%c" 79# Invalid: type incompatibility 80msgid "abc%e" 81msgstr "xyz%c" 82EOF 83 84: ${MSGFMT=msgfmt} 85n=0 86while read comment; do 87 read msgid_line 88 read msgstr_line 89 n=`expr $n + 1` 90 cat <<EOF > f-ph-2-$n.po 91#, php-format 92${msgid_line} 93${msgstr_line} 94EOF 95 fail= 96 if echo "$comment" | grep 'Valid:' > /dev/null; then 97 if ${MSGFMT} --check-format -o f-ph-2-$n.mo f-ph-2-$n.po; then 98 : 99 else 100 fail=yes 101 fi 102 else 103 ${MSGFMT} --check-format -o f-ph-2-$n.mo f-ph-2-$n.po 2> /dev/null 104 if test $? = 1; then 105 : 106 else 107 fail=yes 108 fi 109 fi 110 if test -n "$fail"; then 111 echo "Format string checking error:" 1>&2 112 cat f-ph-2-$n.po 1>&2 113 Exit 1 114 fi 115 rm -f f-ph-2-$n.po f-ph-2-$n.mo 116done < f-ph-2.data 117 118Exit 0 119