Imported Upstream version 0.19.7
[platform/upstream/gettext.git] / gettext-tools / tests / format-perl-2
1 #! /bin/sh
2 . "${srcdir=.}/init.sh"; path_prepend_ . ../src
3
4 # Test checking of Perl format strings.
5
6 cat <<\EOF > f-pl-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%i"
48 msgstr "xyz%d"
49 # Valid: type compatibility
50 msgid  "abc%b"
51 msgstr "xyz%o"
52 # Valid: type compatibility
53 msgid  "abc%o"
54 msgstr "xyz%u"
55 # Valid: type compatibility
56 msgid  "abc%u"
57 msgstr "xyz%x"
58 # Valid: type compatibility
59 msgid  "abc%u"
60 msgstr "xyz%X"
61 # Valid: type and size compatibility
62 msgid  "abc%x"
63 msgstr "xyz%X"
64 # Valid: type compatibility
65 msgid  "abc%e"
66 msgstr "xyz%E"
67 # Valid: type compatibility
68 msgid  "abc%e"
69 msgstr "xyz%f"
70 # Valid: type compatibility
71 msgid  "abc%e"
72 msgstr "xyz%F"
73 # Valid: type compatibility
74 msgid  "abc%e"
75 msgstr "xyz%g"
76 # Valid: type compatibility
77 msgid  "abc%e"
78 msgstr "xyz%G"
79 # Invalid: type incompatibility
80 msgid  "abc%c"
81 msgstr "xyz%s"
82 # Invalid: type incompatibility
83 msgid  "abc%c"
84 msgstr "xyz%_"
85 # Invalid: type incompatibility
86 msgid  "abc%c"
87 msgstr "xyz%i"
88 # Invalid: type incompatibility
89 msgid  "abc%c"
90 msgstr "xyz%u"
91 # Invalid: type incompatibility
92 msgid  "abc%c"
93 msgstr "xyz%e"
94 # Invalid: type incompatibility
95 msgid  "abc%c"
96 msgstr "xyz%p"
97 # Invalid: type incompatibility
98 msgid  "abc%c"
99 msgstr "xyz%n"
100 # Invalid: type incompatibility
101 msgid  "abc%s"
102 msgstr "xyz%_"
103 # Invalid: type incompatibility
104 msgid  "abc%s"
105 msgstr "xyz%i"
106 # Invalid: type incompatibility
107 msgid  "abc%s"
108 msgstr "xyz%u"
109 # Invalid: type incompatibility
110 msgid  "abc%s"
111 msgstr "xyz%e"
112 # Invalid: type incompatibility
113 msgid  "abc%s"
114 msgstr "xyz%p"
115 # Invalid: type incompatibility
116 msgid  "abc%s"
117 msgstr "xyz%n"
118 # Invalid: type incompatibility
119 msgid  "abc%_"
120 msgstr "xyz%i"
121 # Invalid: type incompatibility
122 msgid  "abc%_"
123 msgstr "xyz%u"
124 # Invalid: type incompatibility
125 msgid  "abc%_"
126 msgstr "xyz%e"
127 # Invalid: type incompatibility
128 msgid  "abc%_"
129 msgstr "xyz%p"
130 # Invalid: type incompatibility
131 msgid  "abc%_"
132 msgstr "xyz%n"
133 # Invalid: type incompatibility
134 msgid  "abc%i"
135 msgstr "xyz%u"
136 # Invalid: type incompatibility
137 msgid  "abc%i"
138 msgstr "xyz%e"
139 # Invalid: type incompatibility
140 msgid  "abc%i"
141 msgstr "xyz%p"
142 # Invalid: type incompatibility
143 msgid  "abc%i"
144 msgstr "xyz%n"
145 # Invalid: type incompatibility
146 msgid  "abc%u"
147 msgstr "xyz%e"
148 # Invalid: type incompatibility
149 msgid  "abc%u"
150 msgstr "xyz%p"
151 # Invalid: type incompatibility
152 msgid  "abc%u"
153 msgstr "xyz%n"
154 # Invalid: type incompatibility
155 msgid  "abc%e"
156 msgstr "xyz%p"
157 # Invalid: type incompatibility
158 msgid  "abc%e"
159 msgstr "xyz%n"
160 # Invalid: type incompatibility
161 msgid  "abc%p"
162 msgstr "xyz%n"
163 # Invalid: size incompatibility
164 msgid  "abc%hd"
165 msgstr "xyz%d"
166 # Invalid: size incompatibility
167 msgid  "abc%hd"
168 msgstr "xyz%ld"
169 # Invalid: size incompatibility
170 msgid  "abc%hd"
171 msgstr "xyz%Vd"
172 # Invalid: size incompatibility
173 msgid  "abc%hd"
174 msgstr "xyz%qd"
175 # Invalid: size incompatibility
176 msgid  "abc%d"
177 msgstr "xyz%ld"
178 # Invalid: size incompatibility
179 msgid  "abc%d"
180 msgstr "xyz%Vd"
181 # Invalid: size incompatibility
182 msgid  "abc%d"
183 msgstr "xyz%qd"
184 # Invalid: size incompatibility
185 msgid  "abc%ld"
186 msgstr "xyz%Vd"
187 # Invalid: size incompatibility
188 msgid  "abc%ld"
189 msgstr "xyz%qd"
190 # Invalid: size incompatibility
191 msgid  "abc%Vd"
192 msgstr "xyz%qd"
193 # Invalid: size incompatibility
194 msgid  "abc%d"
195 msgstr "xyz%D"
196 # Invalid: size incompatibility
197 msgid  "abc%u"
198 msgstr "xyz%U"
199 # Invalid: size incompatibility
200 msgid  "abc%o"
201 msgstr "xyz%O"
202 # Invalid: type incompatibility for width
203 msgid  "abc%g%*g"
204 msgstr "xyz%*g%g"
205 EOF
206
207 : ${MSGFMT=msgfmt}
208 n=0
209 while read comment; do
210   read msgid_line
211   read msgstr_line
212   n=`expr $n + 1`
213   cat <<EOF > f-pl-2-$n.po
214 #, perl-format
215 ${msgid_line}
216 ${msgstr_line}
217 EOF
218   fail=
219   if echo "$comment" | grep 'Valid:' > /dev/null; then
220     if ${MSGFMT} --check-format -o f-pl-2-$n.mo f-pl-2-$n.po; then
221       :
222     else
223       fail=yes
224     fi
225   else
226     ${MSGFMT} --check-format -o f-pl-2-$n.mo f-pl-2-$n.po 2> /dev/null
227     if test $? = 1; then
228       :
229     else
230       fail=yes
231     fi
232   fi
233   if test -n "$fail"; then
234     echo "Format string checking error:" 1>&2
235     cat f-pl-2-$n.po 1>&2
236     exit 1
237   fi
238   rm -f f-pl-2-$n.po f-pl-2-$n.mo
239 done < f-pl-2.data
240
241 exit 0