Imported Upstream version 0.19.7
[platform/upstream/gettext.git] / gettext-tools / tests / format-python-brace-1
1 #! /bin/sh
2 . "${srcdir=.}/init.sh"; path_prepend_ . ../src
3
4 # Test recognition of Python brace format strings.
5
6 cat <<\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: format specifier
34 "abc{value:0}"
35 # Valid: standard format specifier
36 "abc{value:<<-#012.34e}"
37 # Invalid: non-standard format specifier
38 "abc{value:<c>}"
39 # Valid: nested format specifier
40 "abc{value:{foo}}"
41 # Invalid: too many nesting of format specifier
42 "abc{value:{foo:0}}"
43 # Invalid: nested format specifier, in the middle of other format specifiers
44 "abc{value:0{foo}0}"
45 EOF
46
47 : ${XGETTEXT=xgettext}
48 n=0
49 while read comment; do
50   read string
51   n=`expr $n + 1`
52   cat <<EOF > f-pyb-1-$n.in
53 gettext(${string});
54 EOF
55   ${XGETTEXT} -L Python -o f-pyb-1-$n.po f-pyb-1-$n.in || exit 1
56   test -f f-pyb-1-$n.po || exit 1
57   fail=
58   if echo "$comment" | grep 'Valid:' > /dev/null; then
59     if grep python-brace-format f-pyb-1-$n.po > /dev/null; then
60       :
61     else
62       fail=yes
63     fi
64   else
65     if grep python-brace-format f-pyb-1-$n.po > /dev/null; then
66       fail=yes
67     else
68       :
69     fi
70   fi
71   if test -n "$fail"; then
72     echo "Format string recognition error:" 1>&2
73     cat f-pyb-1-$n.in 1>&2
74     echo "Got:" 1>&2
75     cat f-pyb-1-$n.po 1>&2
76     exit 1
77   fi
78   rm -f f-pyb-1-$n.in f-pyb-1-$n.po
79 done < f-pyb-1.data
80
81 exit 0