Imported Upstream version 0.19.7
[platform/upstream/gettext.git] / gettext-tools / tests / format-php-2
1 #! /bin/sh
2 . "${srcdir=.}/init.sh"; path_prepend_ . ../src
3
4 # Test checking of PHP format strings.
5
6 cat <<\EOF > f-ph-2.data
7 # Valid: %% doesn't count
8 msgid  "abc%%def"
9 msgstr "xyz"
10 # Invalid: invalid msgstr
11 msgid  "abc%%def"
12 msgstr "xyz%"
13 # Valid: same arguments
14 msgid  "abc%s%gdef"
15 msgstr "xyz%s%g"
16 # Valid: same arguments, with different widths
17 msgid  "abc%2sdef"
18 msgstr "xyz%3s"
19 # Valid: same arguments but in numbered syntax
20 msgid  "abc%s%gdef"
21 msgstr "xyz%1$s%2$g"
22 # Valid: permutation
23 msgid  "abc%s%g%cdef"
24 msgstr "xyz%3$c%2$g%1$s"
25 # Invalid: too few arguments
26 msgid  "abc%2$udef%1$s"
27 msgstr "xyz%1$s"
28 # Invalid: too few arguments
29 msgid  "abc%sdef%u"
30 msgstr "xyz%s"
31 # Invalid: too many arguments
32 msgid  "abc%udef"
33 msgstr "xyz%uvw%c"
34 # Valid: same numbered arguments, with different widths
35 msgid  "abc%2$5s%1$4s"
36 msgstr "xyz%2$4s%1$5s"
37 # Invalid: missing argument
38 msgid  "abc%2$sdef%1$u"
39 msgstr "xyz%1$u"
40 # Invalid: missing argument
41 msgid  "abc%1$sdef%2$u"
42 msgstr "xyz%2$u"
43 # Invalid: added argument
44 msgid  "abc%1$udef"
45 msgstr "xyz%1$uvw%2$c"
46 # Valid: type compatibility
47 msgid  "abc%b"
48 msgstr "xyz%d"
49 # Valid: type compatibility
50 msgid  "abc%u"
51 msgstr "xyz%d"
52 # Valid: type compatibility
53 msgid  "abc%o"
54 msgstr "xyz%d"
55 # Valid: type compatibility
56 msgid  "abc%x"
57 msgstr "xyz%d"
58 # Valid: type compatibility
59 msgid  "abc%X"
60 msgstr "xyz%d"
61 # Valid: type compatibility
62 msgid  "abc%e"
63 msgstr "xyz%f"
64 # Invalid: type incompatibility
65 msgid  "abc%s"
66 msgstr "xyz%d"
67 # Invalid: type incompatibility
68 msgid  "abc%s"
69 msgstr "xyz%e"
70 # Invalid: type incompatibility
71 msgid  "abc%s"
72 msgstr "xyz%c"
73 # Invalid: type incompatibility
74 msgid  "abc%d"
75 msgstr "xyz%e"
76 # Invalid: type incompatibility
77 msgid  "abc%d"
78 msgstr "xyz%c"
79 # Invalid: type incompatibility
80 msgid  "abc%e"
81 msgstr "xyz%c"
82 EOF
83
84 : ${MSGFMT=msgfmt}
85 n=0
86 while 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}
94 EOF
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
116 done < f-ph-2.data
117
118 exit 0