Imported Upstream version 0.19.7
[platform/upstream/gettext.git] / gettext-tools / tests / xgettext-vala-1
1 #!/bin/sh
2 . "${srcdir=.}/init.sh"; path_prepend_ . ../src
3
4 # Test of Vala support.
5
6 : ${XGETTEXT=xgettext}
7
8 cat <<\EOF > xg-vala-1.err.vala
9 int main (string[] args) {
10   var r1 = /a
11 EOF
12
13 (LANGUAGE= LC_ALL=C ${XGETTEXT} --no-location -o - xg-vala-1.err.vala 2>&1; exit) | grep 'regular expression literal terminated too early' || exit 1
14
15 cat <<\EOF > xg-vala-1.vala
16 int main (string[] args) {
17     var s1 = "Simple string, " + " no gettext needed";
18     var c1 = '\'';
19     var empty = "";
20     // This is a C++ style comment
21     var s2 = _("Extract this first string");
22     var s3 = "Prefix _(" + _("Extract this second string") + ") Postfix";
23
24     var empty_verbatim = """""";
25     if (args[0] == _("Extract this thirth string")) {
26       /* _("This is a comment and must not be extracted!") */
27     }
28
29     var s4 = _("""Extract this
30     ""\a
31     fourth string""");
32
33     var s5 = _("Extract this \u2464th string");
34
35     var s6 = /_("This is a regex literal and must not be extracted!")\|/i;
36
37     var i1 = 1000;
38     i1 = 1 + /_("Regex literal after '+'")/.get_capture_count ();
39     i1 = 1 - /_("Regex literal after '-'")/.get_capture_count ();
40     i1 = 1 & /_("Regex literal after '-'")/.get_capture_count ();
41     i1 = 1 ^ /_("Regex literal after '^'")/.get_capture_count ();
42     if (1 < /_("Regex literal after '<'")/.get_capture_count ())
43       return 1;
44     if (1 <= /_("Regex literal after '<='")/.get_capture_count ())
45       return 1;
46     if (1 != /_("Regex literal after '!='")/.get_capture_count ())
47       return 1;
48     if (! /_("Regex literal after '!'")/.match(s1))
49       return 1;
50     if (true && /_("Regex literal after '&&'")/.match(s1))
51       return 1;
52     if (false || /_("Regex literal after '||'")/.match(s1))
53       return 1;
54
55     var r1 = true ? /_("Regex literal after '?'")/ :
56         /_("Regex literal after ':'")/;
57     var r2 = true ?? /_("Regex literal after '??'")/;
58     i1 += 1 << /_("Regex literal after '+='")/.get_capture_count ();
59     i1 *= /_("Regex literal after '*='")/.get_capture_count ();
60     i1 /= /_("Regex literal after '/='")/.get_capture_count ();
61     i1 %= /_("Regex literal after '%='")/.get_capture_count ();
62     i1 <<= /_("Regex literal after '<<='")/.get_capture_count ();
63     i1 |= /_("Regex literal after '|='")/.get_capture_count ();
64
65     i1++;
66     i1--;
67     i1 = i1 / i1;
68     GLib.Timeout.add (10, () => { return false; });
69
70     var d1 = 10e-1;
71     var d2 = 10E-1;
72
73     /* This is a
74        multiline C style comment */
75     var s7 = _("Extract this //sixth string");
76
77     var s8 = _(@"This is a template string, which cannot be extracted!");
78
79     /* /= shouldn't start a regex literal */
80     var i5 = 1000;
81     i5 /= 10;
82     
83     return 0;
84 }
85
86 class Foo : Object {
87   // @ isn't always followed by a template string.
88   public static Foo @new (void) {
89     return null;
90   }
91 }
92 EOF
93
94 ${XGETTEXT} --add-comments --no-location -o xg-vala-1.tmp xg-vala-1.vala 2>xg-vala-1.err
95 test $? = 0 || { cat xg-vala-1.err; exit 1; }
96 # Don't simplify this to "grep ... < xg-vala-1.tmp", otherwise OpenBSD 4.0 grep
97 # only outputs "Binary file (standard input) matches".
98 cat xg-vala-1.tmp | grep -v 'POT-Creation-Date' | LC_ALL=C tr -d '\r' > xg-vala-1.pot
99
100 cat <<\EOF > xg-vala-1.ok
101 # SOME DESCRIPTIVE TITLE.
102 # Copyright (C) YEAR THE PACKAGE'S COPYRIGHT HOLDER
103 # This file is distributed under the same license as the PACKAGE package.
104 # FIRST AUTHOR <EMAIL@ADDRESS>, YEAR.
105 #
106 #, fuzzy
107 msgid ""
108 msgstr ""
109 "Project-Id-Version: PACKAGE VERSION\n"
110 "Report-Msgid-Bugs-To: \n"
111 "PO-Revision-Date: YEAR-MO-DA HO:MI+ZONE\n"
112 "Last-Translator: FULL NAME <EMAIL@ADDRESS>\n"
113 "Language-Team: LANGUAGE <LL@li.org>\n"
114 "Language: \n"
115 "MIME-Version: 1.0\n"
116 "Content-Type: text/plain; charset=UTF-8\n"
117 "Content-Transfer-Encoding: 8bit\n"
118
119 #. This is a C++ style comment
120 msgid "Extract this first string"
121 msgstr ""
122
123 msgid "Extract this second string"
124 msgstr ""
125
126 msgid "Extract this thirth string"
127 msgstr ""
128
129 msgid ""
130 "Extract this\n"
131 "    \"\"\\a\n"
132 "    fourth string"
133 msgstr ""
134
135 msgid "Extract this ⑤th string"
136 msgstr ""
137
138 #. This is a
139 #. multiline C style comment
140 msgid "Extract this //sixth string"
141 msgstr ""
142 EOF
143
144 : ${DIFF=diff}
145 ${DIFF} xg-vala-1.ok xg-vala-1.pot
146 result=$?
147 test $result = 0 || exit $result
148
149 # Test --extract-all option.
150 ${XGETTEXT} --extract-all --add-comments --no-location -o xg-vala-1.tmp xg-vala-1.vala 2>xg-vala-1.err
151 test $? = 0 || { cat xg-vala-1.err; exit 1; }
152 # Don't simplify this to "grep ... < xg-vala-1.tmp", otherwise OpenBSD 4.0 grep
153 # only outputs "Binary file (standard input) matches".
154 cat xg-vala-1.tmp | grep -v 'POT-Creation-Date' | LC_ALL=C tr -d '\r' > xg-vala-1.pot
155
156 cat <<\EOF > xg-vala-1.all.ok
157 # SOME DESCRIPTIVE TITLE.
158 # Copyright (C) YEAR THE PACKAGE'S COPYRIGHT HOLDER
159 # This file is distributed under the same license as the PACKAGE package.
160 # FIRST AUTHOR <EMAIL@ADDRESS>, YEAR.
161 #
162 #, fuzzy
163 msgid ""
164 msgstr ""
165 "Project-Id-Version: PACKAGE VERSION\n"
166 "Report-Msgid-Bugs-To: \n"
167 "PO-Revision-Date: YEAR-MO-DA HO:MI+ZONE\n"
168 "Last-Translator: FULL NAME <EMAIL@ADDRESS>\n"
169 "Language-Team: LANGUAGE <LL@li.org>\n"
170 "Language: \n"
171 "MIME-Version: 1.0\n"
172 "Content-Type: text/plain; charset=UTF-8\n"
173 "Content-Transfer-Encoding: 8bit\n"
174
175 msgid "Simple string,  no gettext needed"
176 msgstr ""
177
178 #. This is a C++ style comment
179 msgid "Extract this first string"
180 msgstr ""
181
182 msgid "Prefix _("
183 msgstr ""
184
185 msgid "Extract this second string"
186 msgstr ""
187
188 msgid ") Postfix"
189 msgstr ""
190
191 msgid "Extract this thirth string"
192 msgstr ""
193
194 msgid ""
195 "Extract this\n"
196 "    \"\"\\a\n"
197 "    fourth string"
198 msgstr ""
199
200 msgid "Extract this ⑤th string"
201 msgstr ""
202
203 #. This is a
204 #. multiline C style comment
205 msgid "Extract this //sixth string"
206 msgstr ""
207 EOF
208
209 ${DIFF} xg-vala-1.all.ok xg-vala-1.pot
210 result=$?
211 test $result = 0 || exit $result