1#! /bin/sh 2. "${srcdir=.}/init.sh"; path_prepend_ . ../src 3 4# Test recognition of Python format strings. 5 6cat <<\EOF > f-p-1.data 7# Valid: no argument 8"abc%%" 9# Valid: one character argument 10"abc%c" 11# Valid: one string argument 12"abc%s" 13# Valid: one string argument 14"abc%r" 15# Valid: one integer argument 16"abc%i" 17# Valid: one integer argument 18"abc%d" 19# Valid: one integer argument 20"abc%u" 21# Valid: one integer argument 22"abc%o" 23# Valid: one integer argument 24"abc%x" 25# Valid: one integer argument 26"abc%X" 27# Valid: one floating-point argument 28"abc%e" 29# Valid: one floating-point argument 30"abc%E" 31# Valid: one floating-point argument 32"abc%f" 33# Valid: one floating-point argument 34"abc%g" 35# Valid: one floating-point argument 36"abc%G" 37# Valid: one argument with flags 38"abc%0#g" 39# Valid: one argument with width 40"abc%2g" 41# Valid: one argument with width 42"abc%*g" 43# Valid: one argument with precision 44"abc%.4g" 45# Valid: one argument with precision 46"abc%.*g" 47# Valid: one argument with width and precision 48"abc%14.4g" 49# Valid: one argument with width and precision 50"abc%14.*g" 51# Valid: one argument with width and precision 52"abc%*.4g" 53# Valid: one argument with width and precision 54"abc%*.*g" 55# Valid: one argument with size specifier 56"abc%hi" 57# Valid: one argument with size specifier 58"abc%li" 59# Valid: one argument with size specifier 60"abc%Li" 61# Invalid: unterminated 62"abc%" 63# Invalid: unknown format specifier 64"abc%y" 65# Invalid: flags after width 66"abc%*0g" 67# Invalid: twice precision 68"abc%.4.2g" 69# Invalid: two size specifiers 70"abc%lli" 71# Valid: three arguments 72"abc%d%u%u" 73# Valid: a named argument 74"abc%(value)d" 75# Valid: an empty name 76"abc%()d" 77# Invalid: unterminated name 78"abc%(value" 79# Valid: ignored named argument 80"abc%(dummy)%" 81# Invalid: flags before name 82"abc%0(value)d" 83# Valid: three arguments, two with equal names 84"abc%(addr)4x,%(char)c,%(addr)u" 85# Invalid: argument with conflicting types 86"abc%(addr)4x,%(char)c,%(addr)s" 87# Valid: no conflict 88"abc%(addr)r,%(addr)s" 89# Invalid: mixing of named and unnamed arguments 90"abc%d%(addr)x" 91# Valid: named argument with constant precision 92"abc%(addr).9x" 93# Invalid: mixing of named and unnamed arguments 94"abc%(addr).*x" 95EOF 96 97: ${XGETTEXT=xgettext} 98n=0 99while read comment; do 100 read string 101 n=`expr $n + 1` 102 cat <<EOF > f-p-1-$n.in 103gettext(${string}); 104EOF 105 # Hide xgettext's "The translator cannot reorder the arguments." warnings. 106 ${XGETTEXT} -L Python -o f-p-1-$n.po f-p-1-$n.in 2> f-p-1.err \ 107 || { cat f-p-1.err 1>&2; Exit 1; } 108 test -f f-p-1-$n.po || Exit 1 109 fail= 110 if echo "$comment" | grep 'Valid:' > /dev/null; then 111 if grep python-format f-p-1-$n.po > /dev/null; then 112 : 113 else 114 fail=yes 115 fi 116 else 117 if grep python-format f-p-1-$n.po > /dev/null; then 118 fail=yes 119 else 120 : 121 fi 122 fi 123 if test -n "$fail"; then 124 echo "Format string recognition error:" 1>&2 125 cat f-p-1-$n.in 1>&2 126 echo "Got:" 1>&2 127 cat f-p-1-$n.po 1>&2 128 Exit 1 129 fi 130 rm -f f-p-1-$n.in f-p-1-$n.po 131done < f-p-1.data 132 133Exit 0 134