]> git.ipfire.org Git - thirdparty/gettext.git/commitdiff
Test encoding recognition of Python extractor.
authorBruno Haible <bruno@clisp.org>
Mon, 26 Sep 2005 09:19:28 +0000 (09:19 +0000)
committerBruno Haible <bruno@clisp.org>
Tue, 23 Jun 2009 10:12:51 +0000 (12:12 +0200)
gettext-tools/tests/xgettext-python-3 [new file with mode: 0755]

diff --git a/gettext-tools/tests/xgettext-python-3 b/gettext-tools/tests/xgettext-python-3
new file mode 100755 (executable)
index 0000000..7acc806
--- /dev/null
@@ -0,0 +1,136 @@
+#!/bin/sh
+
+# Test Python support: --from-code option and encoding recognition.
+
+tmpfiles=""
+trap 'rm -fr $tmpfiles' 1 2 3 15
+
+tmpfiles="$tmpfiles xg-py-3a.py"
+cat <<\EOF > xg-py-3a.py
+#!/usr/bin/env python
+# TRANSLATORS: Fran\8f«®ois Pinard is a hero.
+print gettext.gettext("ÆüËܸì");
+EOF
+
+tmpfiles="$tmpfiles xg-py-3b.py"
+cat <<\EOF > xg-py-3b.py
+#!/usr/bin/env python
+                       # Hey Emacs! -*- coding: euc-jp -*-
+# TRANSLATORS: Fran\8f«®ois Pinard is a hero.
+print gettext.gettext("ÆüËܸì");
+EOF
+
+tmpfiles="$tmpfiles xg-py-3.ok"
+cat <<\EOF > xg-py-3.ok
+# SOME DESCRIPTIVE TITLE.
+# Copyright (C) YEAR THE PACKAGE'S COPYRIGHT HOLDER
+# This file is distributed under the same license as the PACKAGE package.
+# FIRST AUTHOR <EMAIL@ADDRESS>, YEAR.
+#
+#, fuzzy
+msgid ""
+msgstr ""
+"Project-Id-Version: PACKAGE VERSION\n"
+"Report-Msgid-Bugs-To: \n"
+"PO-Revision-Date: YEAR-MO-DA HO:MI+ZONE\n"
+"Last-Translator: FULL NAME <EMAIL@ADDRESS>\n"
+"Language-Team: LANGUAGE <LL@li.org>\n"
+"MIME-Version: 1.0\n"
+"Content-Type: text/plain; charset=UTF-8\n"
+"Content-Transfer-Encoding: 8bit\n"
+
+#. TRANSLATORS: François Pinard is a hero.
+msgid "日本語"
+msgstr ""
+EOF
+
+# Verify that if the source file has no magic coding comment, xgettext fails
+# if no --from-code option is given but succeeds if it is given.
+tmpfiles="$tmpfiles xg-py-3a.tmp xg-py-3a.pot"
+: ${XGETTEXT=xgettext}
+${XGETTEXT} --add-comments=TRANSLATORS: --no-location \
+  xg-py-3a.py -d xg-py-3a > /dev/null 2>&1
+test $? = 1 || { rm -fr $tmpfiles; exit 1; }
+${XGETTEXT} --add-comments=TRANSLATORS: --no-location --from-code=euc-jp \
+  xg-py-3a.py -o xg-py-3a.tmp
+test $? = 0 || { rm -fr $tmpfiles; exit 1; }
+grep -v 'POT-Creation-Date' < xg-py-3a.tmp > xg-py-3a.pot
+
+: ${DIFF=diff}
+${DIFF} xg-py-3.ok xg-py-3a.pot
+test $? = 0 || { rm -fr $tmpfiles; exit 1; }
+
+# Verify that if the source file has a magic coding comment, xgettext succeeds.
+
+tmpfiles="$tmpfiles xg-py-3b.tmp xg-py-3b.pot"
+${XGETTEXT} --add-comments=TRANSLATORS: --no-location \
+  xg-py-3b.py -o xg-py-3b.tmp
+test $? = 0 || { rm -fr $tmpfiles; exit 1; }
+grep -v 'POT-Creation-Date' < xg-py-3b.tmp > xg-py-3b.pot
+
+${DIFF} xg-py-3.ok xg-py-3b.pot
+test $? = 0 || { rm -fr $tmpfiles; exit 1; }
+
+# Verify that if the source file has a magic coding comment and a --from-code
+# option is given, the magic coding comment takes precedence over it.
+
+tmpfiles="$tmpfiles xg-py-3c.tmp xg-py-3c.pot"
+${XGETTEXT} --add-comments=TRANSLATORS: --no-location --from-code=iso-8859-1 \
+  xg-py-3b.py -o xg-py-3c.tmp
+test $? = 0 || { rm -fr $tmpfiles; exit 1; }
+grep -v 'POT-Creation-Date' < xg-py-3c.tmp > xg-py-3c.pot
+
+${DIFF} xg-py-3.ok xg-py-3c.pot
+test $? = 0 || { rm -fr $tmpfiles; exit 1; }
+
+# Verify that backslashes in and second bytes with value 0x5C are correctly
+# distinguished in weird encodings like BIG5.
+
+tmpfiles="$tmpfiles xg-py-3d.py"
+cat <<\EOF > xg-py-3d.py
+#!/usr/bin/env python
+                       # Hey Emacs! -*- coding: big5 -*-
+print gettext.gettext(u"¬\u0021");
+print gettext.gettext(u"¬\\u0021");
+EOF
+
+tmpfiles="$tmpfiles xg-py-3d.tmp xg-py-3d.pot"
+${XGETTEXT} --add-comments=TRANSLATORS: \
+  xg-py-3d.py -o xg-py-3d.tmp
+test $? = 0 || { rm -fr $tmpfiles; exit 1; }
+grep -v 'POT-Creation-Date' < xg-py-3d.tmp > xg-py-3d.pot
+
+tmpfiles="$tmpfiles xg-py-3d.ok"
+cat <<\EOF > xg-py-3d.ok
+# SOME DESCRIPTIVE TITLE.
+# Copyright (C) YEAR THE PACKAGE'S COPYRIGHT HOLDER
+# This file is distributed under the same license as the PACKAGE package.
+# FIRST AUTHOR <EMAIL@ADDRESS>, YEAR.
+#
+#, fuzzy
+msgid ""
+msgstr ""
+"Project-Id-Version: PACKAGE VERSION\n"
+"Report-Msgid-Bugs-To: \n"
+"PO-Revision-Date: YEAR-MO-DA HO:MI+ZONE\n"
+"Last-Translator: FULL NAME <EMAIL@ADDRESS>\n"
+"Language-Team: LANGUAGE <LL@li.org>\n"
+"MIME-Version: 1.0\n"
+"Content-Type: text/plain; charset=UTF-8\n"
+"Content-Transfer-Encoding: 8bit\n"
+
+#: xg-py-3d.py:3
+msgid "枯u0021"
+msgstr ""
+
+#: xg-py-3d.py:4
+msgid "枯!"
+msgstr ""
+EOF
+
+${DIFF} xg-py-3d.ok xg-py-3d.pot
+test $? = 0 || { rm -fr $tmpfiles; exit 1; }
+
+rm -fr $tmpfiles
+
+exit 0