Imported Upstream version 0.19.7
[platform/upstream/gettext.git] / gettext-tools / tests / xgettext-perl-1
1 #!/bin/sh
2 . "${srcdir=.}/init.sh"; path_prepend_ . ../src
3
4 # Test of Perl support.
5
6 cat <<\EOF > xg-pl-1.pl
7 use Locale::Messages qw (textdomain bindtextdomain gettext ngettext dngettext);
8
9 textdomain "prog";
10 bindtextdomain "prog", "./";
11
12 s/foo/
13           # stress test for string extraction /xe;
14
15 print _"'Your command, please?', asked the waiter.";
16
17 printf ngettext ("a piece of cake", "%d pieces of cake", $n), $n;
18
19 printf _"%s is replaced by %s.", "FF", "EUR";
20
21 # Should be found.
22 printf dngettext prog => ("one file deleted", "%d files deleted"), $n, $n;
23
24 # Should not be found.
25 printf dngettext ("prog"), ("one file created", "%d files created"), $n, $n;
26
27 printf dngettext "prog", <<PERL, <<PERL;
28 Singular
29 PERL
30 Plural
31 PERL
32
33 print <<PERL
34 tied hash $__{   Bareword
35 }
36 tied hash $__->{"quoted string"}
37 tied hash $__->{  "weird
38 formatting"}
39 PERL
40
41 print $__  # Welcome
42    ->   # to the
43  { # Republic of
44  'Welcome to the Republic of Perl!' # 
45 # Perl!
46 }; 
47
48 $! ? ?$__{"pattern match"}? : s  # This is no delimiter.
49 {$__{substitution}}<$__-\>{"find me"}>;
50
51 # No interpolation!
52 m'$__{secret}';
53
54 # Multiple here documents invoked from the same line.
55 print gettext <<PERL; print gettext <<PERL;
56 First here document.
57 PERL
58 Second here document.
59 PERL
60
61 # These are not invalid interpolations, because the dollar is backslashed.
62 printf "%s\n", gettext "abc\$def";
63 printf "%s\n", gettext "abc\\\$def";
64
65 # These are not interpolations.
66 printf "%s\n", gettext 'abc$defg';
67 printf "%s\n", gettext 'abc\$defg';
68 printf "%s\n", gettext 'abc\\$defg';
69 printf "%s\n", gettext 'abc\\\$defg';
70
71 # Two consecutive backslashes count as one inside single-quote strings.
72 printf "%s\n", gettext 'ecs\tasy';
73 printf "%s\n", gettext 'ecs\\tasy';
74 printf "%s\n", gettext 'ecs\\\tasy';
75 printf "%s\n", gettext 'ecs\\\\tasy';
76 printf "%s\n", gettext 'ecs\\\\\tasy';
77 printf "%s\n", gettext q(ecs\tasy);
78 printf "%s\n", gettext q(ecs\\tasy);
79 printf "%s\n", gettext q(ecs\\\tasy);
80 printf "%s\n", gettext q(ecs\\\\tasy);
81 printf "%s\n", gettext q(ecs\\\\\tasy);
82
83 # Similarly, inside double-quote strings, two consecutive backslashes count
84 # as one, but the last backslash of a sequence is combined with the following
85 # character if possible.
86 printf "%s\n", gettext "ecs\tasy";
87 printf "%s\n", gettext "ecs\\tasy";
88 printf "%s\n", gettext "ecs\\\tasy";
89 printf "%s\n", gettext "ecs\\\\tasy";
90 printf "%s\n", gettext "ecs\\\\\tasy";
91 printf "%s\n", gettext qq(ecs\tasy);
92 printf "%s\n", gettext qq(ecs\\tasy);
93 printf "%s\n", gettext qq(ecs\\\tasy);
94 printf "%s\n", gettext qq(ecs\\\\tasy);
95 printf "%s\n", gettext qq(ecs\\\\\tasy);
96 printf "%s\n", gettext "mari\huana";
97 printf "%s\n", gettext "mari\\huana";
98 printf "%s\n", gettext "mari\\\huana";
99 printf "%s\n", gettext "mari\\\\huana";
100 printf "%s\n", gettext "mari\\\\\huana";
101 printf "%s\n", gettext qq(mari\huana);
102 printf "%s\n", gettext qq(mari\\huana);
103 printf "%s\n", gettext qq(mari\\\huana);
104 printf "%s\n", gettext qq(mari\\\\huana);
105 printf "%s\n", gettext qq(mari\\\\\huana);
106
107 # Recognition of format strings.
108 gettext "This is {only} a brace formatstring.";
109 gettext "This is %s {mixed}.";
110 gettext "This is only %c.";
111 gettext "This is nothing at all.";
112 gettext "And this is %l also no format at all.";
113
114 # xgettext: no-perl-format, perl-brace-format
115 gettext "The function '{func}' expects '%c' here.";
116
117 # This is a contradictory case: The same string three times,
118 # with different xgettext comments.
119 # xgettext: perl-brace-format, no-perl-format
120 gettext "Left as an %exercise to {maintainer}.";
121 # xgettext: no-perl-brace-format, perl-format
122 gettext "Left as an %exercise to {maintainer}.";
123 # No xgettext comment this time.
124 gettext "Left as an %exercise to {maintainer}.";
125
126 # Dollars inside sub argument lists have no effect.
127 sub testFunc($) { }
128 =item TestBug1
129 If you have gettext()'d foo bar test1'...
130 =cut
131
132 # Dollars inside sub argument lists have no effect.
133 testFunc = sub ($) { }
134 =item TestBug2
135 If you have gettext()'d foo bar test2'...
136 =cut
137
138 # Dollars inside sub argument lists have no effect.
139 sub testFunc($\$;*@) { }
140 =item TestBug3
141 If you have gettext()'d foo bar test3'...
142 =cut
143
144 gettext "Before slash-slash";
145 print $foo // 'undef';
146 gettext "After slash-slash";
147
148 __END__
149 gettext "Discarded!";
150 EOF
151
152 : ${XGETTEXT=xgettext}
153 ${XGETTEXT} --omit-header -n \
154   -k_ --flag=_:1:pass-perl-format --flag=_:1:pass-perl-brace-format \
155   -k%__ --flag=%__:1:pass-perl-format --flag=%__:1:pass-perl-brace-format \
156   -k\$__ --flag=\$__:1:pass-perl-format --flag=\$__:1:pass-perl-brace-format \
157   -d xg-pl-1.tmp xg-pl-1.pl || exit 1
158 LC_ALL=C tr -d '\r' < xg-pl-1.tmp.po > xg-pl-1.po || exit 1
159
160 cat <<\EOF > xg-pl-1.ok
161 #: xg-pl-1.pl:9
162 msgid "'Your command, please?', asked the waiter."
163 msgstr ""
164
165 #: xg-pl-1.pl:11
166 #, perl-format
167 msgid "a piece of cake"
168 msgid_plural "%d pieces of cake"
169 msgstr[0] ""
170 msgstr[1] ""
171
172 #: xg-pl-1.pl:13
173 #, perl-format
174 msgid "%s is replaced by %s."
175 msgstr ""
176
177 #: xg-pl-1.pl:16
178 #, perl-format
179 msgid "one file deleted"
180 msgid_plural "%d files deleted"
181 msgstr[0] ""
182 msgstr[1] ""
183
184 #: xg-pl-1.pl:22
185 #, perl-format
186 msgid "Singular\n"
187 msgid_plural "Plural\n"
188 msgstr[0] ""
189 msgstr[1] ""
190
191 #: xg-pl-1.pl:28
192 msgid "Bareword"
193 msgstr ""
194
195 #: xg-pl-1.pl:30
196 msgid "quoted string"
197 msgstr ""
198
199 #: xg-pl-1.pl:31
200 msgid ""
201 "weird\n"
202 "formatting"
203 msgstr ""
204
205 #: xg-pl-1.pl:38
206 msgid "Welcome to the Republic of Perl!"
207 msgstr ""
208
209 #: xg-pl-1.pl:42
210 msgid "pattern match"
211 msgstr ""
212
213 #: xg-pl-1.pl:43
214 msgid "substitution"
215 msgstr ""
216
217 #: xg-pl-1.pl:43
218 msgid "find me"
219 msgstr ""
220
221 #: xg-pl-1.pl:50
222 msgid "First here document.\n"
223 msgstr ""
224
225 #: xg-pl-1.pl:52
226 msgid "Second here document.\n"
227 msgstr ""
228
229 #: xg-pl-1.pl:56
230 msgid "abc$def"
231 msgstr ""
232
233 #: xg-pl-1.pl:57
234 msgid "abc\\$def"
235 msgstr ""
236
237 #: xg-pl-1.pl:60
238 msgid "abc$defg"
239 msgstr ""
240
241 #: xg-pl-1.pl:61 xg-pl-1.pl:62
242 msgid "abc\\$defg"
243 msgstr ""
244
245 #: xg-pl-1.pl:63
246 msgid "abc\\\\$defg"
247 msgstr ""
248
249 #: xg-pl-1.pl:66 xg-pl-1.pl:67 xg-pl-1.pl:71 xg-pl-1.pl:72 xg-pl-1.pl:81
250 #: xg-pl-1.pl:86
251 msgid "ecs\\tasy"
252 msgstr ""
253
254 #: xg-pl-1.pl:68 xg-pl-1.pl:69 xg-pl-1.pl:73 xg-pl-1.pl:74 xg-pl-1.pl:83
255 #: xg-pl-1.pl:88
256 msgid "ecs\\\\tasy"
257 msgstr ""
258
259 #: xg-pl-1.pl:70 xg-pl-1.pl:75
260 msgid "ecs\\\\\\tasy"
261 msgstr ""
262
263 #: xg-pl-1.pl:80 xg-pl-1.pl:85
264 msgid "ecs\tasy"
265 msgstr ""
266
267 #: xg-pl-1.pl:82 xg-pl-1.pl:87
268 msgid "ecs\\\tasy"
269 msgstr ""
270
271 #: xg-pl-1.pl:84 xg-pl-1.pl:89
272 msgid "ecs\\\\\tasy"
273 msgstr ""
274
275 #: xg-pl-1.pl:90 xg-pl-1.pl:95
276 msgid "marihuana"
277 msgstr ""
278
279 #: xg-pl-1.pl:91 xg-pl-1.pl:92 xg-pl-1.pl:96 xg-pl-1.pl:97
280 msgid "mari\\huana"
281 msgstr ""
282
283 #: xg-pl-1.pl:93 xg-pl-1.pl:94 xg-pl-1.pl:98 xg-pl-1.pl:99
284 msgid "mari\\\\huana"
285 msgstr ""
286
287 #: xg-pl-1.pl:102
288 #, perl-brace-format
289 msgid "This is {only} a brace formatstring."
290 msgstr ""
291
292 #: xg-pl-1.pl:103
293 #, perl-format, perl-brace-format
294 msgid "This is %s {mixed}."
295 msgstr ""
296
297 #: xg-pl-1.pl:104
298 #, perl-format
299 msgid "This is only %c."
300 msgstr ""
301
302 #: xg-pl-1.pl:105
303 msgid "This is nothing at all."
304 msgstr ""
305
306 #: xg-pl-1.pl:106
307 msgid "And this is %l also no format at all."
308 msgstr ""
309
310 #: xg-pl-1.pl:109
311 #, no-perl-format, perl-brace-format
312 msgid "The function '{func}' expects '%c' here."
313 msgstr ""
314
315 #: xg-pl-1.pl:114 xg-pl-1.pl:116 xg-pl-1.pl:118
316 #, perl-format, no-perl-brace-format
317 msgid "Left as an %exercise to {maintainer}."
318 msgstr ""
319
320 #: xg-pl-1.pl:138
321 msgid "Before slash-slash"
322 msgstr ""
323
324 #: xg-pl-1.pl:140
325 msgid "After slash-slash"
326 msgstr ""
327 EOF
328
329 : ${DIFF=diff}
330 ${DIFF} xg-pl-1.ok xg-pl-1.po
331 result=$?
332
333 exit $result