summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDaiki Ueno <ueno@gnu.org>2013-02-28 18:29:29 +0900
committerDaiki Ueno <ueno@gnu.org>2013-02-28 19:01:47 +0900
commitd0ea5ee79cea236bbefbcacd8fb35b0e35b04b9c (patch)
treefe5077d5235837a093e0fd4e8b5c4da4d4354890
parent948d674ae3bfb1571cbe54c82390c5d9be9eb140 (diff)
downloadgettext-d0ea5ee79cea236bbefbcacd8fb35b0e35b04b9c.tar.gz
Tests for python-brace-format.
-rw-r--r--gettext-tools/tests/ChangeLog5
-rw-r--r--gettext-tools/tests/Makefile.am4
-rwxr-xr-xgettext-tools/tests/format-python-brace-167
-rwxr-xr-xgettext-tools/tests/xgettext-python-541
4 files changed, 115 insertions, 2 deletions
diff --git a/gettext-tools/tests/ChangeLog b/gettext-tools/tests/ChangeLog
index 65b6b9c55..08aa25e73 100644
--- a/gettext-tools/tests/ChangeLog
+++ b/gettext-tools/tests/ChangeLog
@@ -1,3 +1,8 @@
+2013-02-28 Daiki Ueno <ueno@gnu.org>
+
+ * format-python-brace-1: New test.
+ * xgettext-python-5: New test.
+
2012-12-25 Daiki Ueno <ueno@gnu.org>
* gettext-0.18.2 released.
diff --git a/gettext-tools/tests/Makefile.am b/gettext-tools/tests/Makefile.am
index f8759135e..d07e4605a 100644
--- a/gettext-tools/tests/Makefile.am
+++ b/gettext-tools/tests/Makefile.am
@@ -91,7 +91,7 @@ TESTS = gettext-1 gettext-2 gettext-3 gettext-4 gettext-5 gettext-6 gettext-7 \
xgettext-po-1 \
xgettext-properties-1 \
xgettext-python-1 xgettext-python-2 xgettext-python-3 \
- xgettext-python-4 \
+ xgettext-python-4 xgettext-python-5 \
xgettext-scheme-1 xgettext-scheme-2 xgettext-scheme-3 \
xgettext-sh-1 xgettext-sh-2 xgettext-sh-3 xgettext-sh-4 xgettext-sh-5 \
xgettext-sh-6 \
@@ -111,7 +111,7 @@ TESTS = gettext-1 gettext-2 gettext-3 gettext-4 gettext-5 gettext-6 gettext-7 \
format-librep-1 format-librep-2 \
format-lisp-1 format-lisp-2 \
format-php-1 format-php-2 \
- format-python-1 format-python-2 \
+ format-python-1 format-python-2 format-python-brace-1 \
format-pascal-1 format-pascal-2 \
format-perl-1 format-perl-2 \
format-perl-brace-1 format-perl-brace-2 \
diff --git a/gettext-tools/tests/format-python-brace-1 b/gettext-tools/tests/format-python-brace-1
new file mode 100755
index 000000000..a79e74d0f
--- /dev/null
+++ b/gettext-tools/tests/format-python-brace-1
@@ -0,0 +1,67 @@
+#! /bin/sh
+
+# Test recognition of Python brace format strings.
+
+tmpfiles=""
+trap 'rm -fr $tmpfiles' 1 2 3 15
+
+tmpfiles="$tmpfiles f-pyb-1.data"
+cat <<\EOF > f-pyb-1.data
+# Invalid: no argument
+"abc"
+# Valid: a named argument
+"abc{value}"
+# Valid: a number argument
+"abc{0}"
+# Invalid: an empty name
+"abc{}"
+# Invalid: unterminated name
+"abc{value"
+# Valid: three arguments, two with equal names
+"abc{addr},{char},{addr}"
+# Invalid: place-holder contains a space.
+"{foo bar}"
+# Invalid: missing right angle bracket.
+"{foo bar"
+# Invalid: percent sign not allowed.
+"{foo%bar}"
+EOF
+
+: ${XGETTEXT=xgettext}
+n=0
+while read comment; do
+ read string
+ n=`expr $n + 1`
+ tmpfiles="$tmpfiles f-pyb-1-$n.in f-pyb-1-$n.po"
+ cat <<EOF > f-pyb-1-$n.in
+gettext(${string});
+EOF
+ ${XGETTEXT} -L Python -o f-pyb-1-$n.po f-pyb-1-$n.in || exit 1
+ test -f f-pyb-1-$n.po || exit 1
+ fail=
+ if echo "$comment" | grep 'Valid:' > /dev/null; then
+ if grep python-brace-format f-pyb-1-$n.po > /dev/null; then
+ :
+ else
+ fail=yes
+ fi
+ else
+ if grep python-brace-format f-pyb-1-$n.po > /dev/null; then
+ fail=yes
+ else
+ :
+ fi
+ fi
+ if test -n "$fail"; then
+ echo "Format string recognition error:" 1>&2
+ cat f-pyb-1-$n.in 1>&2
+ echo "Got:" 1>&2
+ cat f-pyb-1-$n.po 1>&2
+ exit 1
+ fi
+ rm -f f-pyb-1-$n.in f-pyb-1-$n.po
+done < f-pyb-1.data
+
+rm -fr $tmpfiles
+
+exit 0
diff --git a/gettext-tools/tests/xgettext-python-5 b/gettext-tools/tests/xgettext-python-5
new file mode 100755
index 000000000..d56d87ad1
--- /dev/null
+++ b/gettext-tools/tests/xgettext-python-5
@@ -0,0 +1,41 @@
+#!/bin/sh
+
+# Test Python support: recognition of format strings
+
+tmpfiles=""
+trap 'rm -fr $tmpfiles' 1 2 3 15
+
+tmpfiles="$tmpfiles xg-py-5.py"
+cat <<\EOF > xg-py-5.py
+# Recognition of format strings.
+_("This is {only} a brace formatstring.").format(only = "only")
+_("This is %s." % "a format");
+EOF
+
+tmpfiles="$tmpfiles xg-py-5.tmp.po xg-py-5.po"
+: ${XGETTEXT=xgettext}
+${XGETTEXT} --add-comments --omit-header --no-location --keyword=_ \
+ -d xg-py-5.tmp xg-py-5.py
+test $? = 0 || { rm -fr $tmpfiles; exit 1; }
+LC_ALL=C tr -d '\r' < xg-py-5.tmp.po > xg-py-5.po
+test $? = 0 || { rm -fr $tmpfiles; exit 1; }
+
+tmpfiles="$tmpfiles xg-py-5.ok"
+cat <<EOF > xg-py-5.ok
+#. Recognition of format strings.
+#, python-brace-format
+msgid "This is {only} a brace formatstring."
+msgstr ""
+
+#, python-format
+msgid "This is %s."
+msgstr ""
+EOF
+
+: ${DIFF=diff}
+${DIFF} xg-py-5.ok xg-py-5.po
+result=$?
+
+rm -fr $tmpfiles
+
+exit $result