1#! /bin/sh 2. "${srcdir=.}/init.sh"; path_prepend_ . ../src 3 4# Test recognition of Python brace format strings. 5 6cat <<\EOF > f-pyb-1.data 7# Invalid: no argument 8"abc" 9# Invalid: escaped braces 10"abc{{}}" 11# Valid: a numeric argument 12"abc{0}" 13# Valid: a named argument 14"abc{value}" 15# Invalid: an empty name 16"abc{}" 17# Invalid: unterminated name 18"abc{value" 19# Valid: three arguments, two with equal names 20"abc{addr},{char},{addr}" 21# Valid: getattr operator 22"abc{value.name}" 23# Invalid: getattr operator with numeric field name 24"abc{value.0}" 25# Valid: getitem operator 26"abc{value[name]}" 27# Invalid: unterminated getitem operator 28"abc{value[name}" 29# Invalid: unterminated getitem operator 30"abc{value[0}" 31# Invalid: unknown character in getitem operator 32"abc{value[!]}" 33# Valid: use of both getattr and getitem operators 34"abc{value.v[name]}" 35# Valid: format specifier 36"abc{value:0}" 37# Valid: standard format specifier 38"abc{value:<<-#012.34e}" 39# Invalid: non-standard format specifier 40"abc{value:<c>}" 41# Valid: nested format specifier 42"abc{value:{foo}}" 43# Invalid: too many nesting of format specifier 44"abc{value:{foo:0}}" 45# Invalid: nested format specifier, in the middle of other format specifiers 46"abc{value:0{foo}0}" 47EOF 48 49: ${XGETTEXT=xgettext} 50n=0 51while read comment; do 52 read string 53 n=`expr $n + 1` 54 cat <<EOF > f-pyb-1-$n.in 55gettext(${string}); 56EOF 57 ${XGETTEXT} -L Python -o f-pyb-1-$n.po f-pyb-1-$n.in || Exit 1 58 test -f f-pyb-1-$n.po || Exit 1 59 fail= 60 if echo "$comment" | grep 'Valid:' > /dev/null; then 61 if grep python-brace-format f-pyb-1-$n.po > /dev/null; then 62 : 63 else 64 fail=yes 65 fi 66 else 67 if grep python-brace-format f-pyb-1-$n.po > /dev/null; then 68 fail=yes 69 else 70 : 71 fi 72 fi 73 if test -n "$fail"; then 74 echo "Format string recognition error:" 1>&2 75 cat f-pyb-1-$n.in 1>&2 76 echo "Got:" 1>&2 77 cat f-pyb-1-$n.po 1>&2 78 Exit 1 79 fi 80 rm -f f-pyb-1-$n.in f-pyb-1-$n.po 81done < f-pyb-1.data 82 83Exit 0 84