]> git.ipfire.org Git - thirdparty/gettext.git/commitdiff
Tests for KDE format strings.
authorBruno Haible <bruno@clisp.org>
Mon, 1 Oct 2007 00:24:06 +0000 (00:24 +0000)
committerBruno Haible <bruno@clisp.org>
Tue, 23 Jun 2009 10:15:06 +0000 (12:15 +0200)
gettext-tools/tests/ChangeLog
gettext-tools/tests/Makefile.am
gettext-tools/tests/format-kde-1 [new file with mode: 0755]
gettext-tools/tests/format-kde-2 [new file with mode: 0755]

index 5f2161aae7b304715cf73cad00133ebd4eba159e..555c5c1a05a1f284a2c7d9f45d7ab62ab176ac29 100644 (file)
@@ -1,3 +1,11 @@
+2007-09-30  Bruno Haible  <bruno@clisp.org>
+
+       Add support for KDE 4 format strings.
+       * format-kde-1: New file.
+       * format-kde-2: New file.
+       * Makefile.am (TESTS): Add them.
+       Based on input by by Chusslove Illich <caslav.ilic@gmx.net>.
+
 2007-09-09  Bruno Haible  <bruno@clisp.org>
 
        Add support for Qt 4 format strings.
index 78a6e5e41b883ee8fd978df6bc9f2add8e5a2f81..ba2ca74d0c167de85d9134c174650abfa7c98377 100644 (file)
@@ -104,6 +104,7 @@ TESTS = gettext-1 gettext-2 gettext-3 gettext-4 gettext-5 gettext-6 gettext-7 \
        format-elisp-1 format-elisp-2 \
        format-gcc-internal-1 format-gcc-internal-2 \
        format-java-1 format-java-2 \
+       format-kde-1 format-kde-2 \
        format-librep-1 format-librep-2 \
        format-lisp-1 format-lisp-2 \
        format-php-1 format-php-2 \
diff --git a/gettext-tools/tests/format-kde-1 b/gettext-tools/tests/format-kde-1
new file mode 100755 (executable)
index 0000000..f916b3f
--- /dev/null
@@ -0,0 +1,83 @@
+#! /bin/sh
+
+# Test recognition of KDE format strings.
+
+tmpfiles=""
+trap 'rm -fr $tmpfiles' 1 2 3 15
+
+tmpfiles="$tmpfiles f-kd-1.data"
+cat <<\EOF > f-kd-1.data
+# Unrecognized: no argument
+"abc%%def"
+# Valid: one argument
+"abc%1def"
+# Unrecognized: no argument (digit sequence starting with a zero)
+"abc%09def"
+# Valid: one argument, digit sequence starting with a zero
+"abc%1def%0"
+# Valid: one argument, digit sequence starting with a zero
+"abc%1def%00"
+# Valid: 9 arguments
+"abc%1%2%3%4%9%7%8%5%6def"
+# Valid: 9 arguments, missing one of them
+"abc%1%2%3%4%9%7%5%6def"
+# Invalid: one argument but missing arguments %1 ... %8
+"abc%9def"
+# Valid: more than ten arguments, missing one of them
+"abc%1%2%3%4%9%7%5%6%12%10%11def"
+# Invalid: one argument specified by two digits but missing arguments %1 ... %98
+"abc%99def"
+# Valid: unterminated
+"abc%1def%"
+# Valid: unterminated
+"abc%1def%L"
+# Valid: non-digit
+"abc%1def%x"
+# Valid: permutation
+"abc%2def%1"
+# Valid: multiple uses of same argument
+"abc%2def%1ghi%2"
+# Unrecognized: no argument
+"abc%L1def"
+# Unrecognized: no argument
+"abc%L12def"
+EOF
+
+: ${XGETTEXT=xgettext}
+n=0
+while read comment; do
+  read string
+  n=`expr $n + 1`
+  tmpfiles="$tmpfiles f-kd-1-$n.in f-kd-1-$n.po"
+  cat <<EOF > f-kd-1-$n.in
+_(${string});
+EOF
+  ${XGETTEXT} -L C++ --kde -k_ -o f-kd-1-$n.po f-kd-1-$n.in || exit 1
+  test -f f-kd-1-$n.po || exit 1
+  fail=
+  if echo "$comment" | grep 'Valid:' > /dev/null; then
+    if grep kde-format f-kd-1-$n.po > /dev/null; then
+      :
+    else
+      fail=yes
+    fi
+  else
+    if grep kde-format f-kd-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-kd-1-$n.in 1>&2
+    echo "Got:" 1>&2
+    cat f-kd-1-$n.po 1>&2
+    exit 1
+  fi
+  rm -f f-kd-1-$n.in f-kd-1-$n.po
+done < f-kd-1.data
+
+rm -fr $tmpfiles
+
+exit 0
diff --git a/gettext-tools/tests/format-kde-2 b/gettext-tools/tests/format-kde-2
new file mode 100755 (executable)
index 0000000..423fcef
--- /dev/null
@@ -0,0 +1,109 @@
+#! /bin/sh
+
+# Test checking of KDE format strings.
+
+tmpfiles=""
+trap 'rm -fr $tmpfiles' 1 2 3 15
+
+tmpfiles="$tmpfiles f-kd-2.data"
+cat <<\EOF > f-kd-2.data
+# Valid: %% doesn't count
+msgid  "abc%%def"
+msgstr "xyz"
+# Valid: digit sequence starting with 0 doesn't count
+msgid  "abc%09def"
+msgstr "xyz"
+# Valid: digit sequence starting with 0 doesn't count
+msgid  "abc%0"
+msgstr "xyz"
+# Valid: digit sequence starting with 0 doesn't count
+msgid  "abc%00"
+msgstr "xyz"
+# Valid: L is not a recognized flag
+msgid  "abc%L1def"
+msgstr "xyz"
+# Valid: same arguments
+msgid  "abc%2def"
+msgstr "xyz%2"
+# Invalid: different arguments
+msgid  "abc%2def"
+msgstr "xyz%1"
+# Invalid: different arguments
+msgid  "abc%1def"
+msgstr "xyz%2"
+# Valid: repetition of an argument in the translation
+msgid  "abc%2def"
+msgstr "xyz%2uvw%2"
+# Valid: removing repeated argument in the translation
+msgid  "abc%2def%2"
+msgstr "xyz%2uvw"
+# Valid: permutation
+msgid  "abc%3%1%2def"
+msgstr "xyz%2%1%3"
+# Invalid: too few arguments
+msgid  "abc%2def%1ghi%3"
+msgstr "xyz%1"
+# Invalid: only one argument removed (valid only in singular form)
+msgid  "abc%2def%1ghi%3"
+msgstr "xyz%1uvw%2"
+# Invalid: only one argument removed (valid only in singular form)
+msgid  "abc%2def%1ghi%3"
+msgstr "xyz%1uvw%3"
+# Invalid: only one argument removed (valid only in singular form)
+msgid  "abc%2def%1ghi%3"
+msgstr "xyz%3uvw%2"
+# Invalid: only one argument removed (valid only in singular form)
+msgid  "abc%1def%3"
+msgstr "xyz%1"
+# Invalid: wrong argument removed
+msgid  "abc%1def%3"
+msgstr "xyz%3"
+# Invalid: too many arguments
+msgid  "abc%1def"
+msgstr "xyz%1uvw%2"
+# Invalid: missing non-final argument (valid only in singular form)
+msgid  "abc%2def%1"
+msgstr "xyz%2"
+# Invalid: added non-final argument
+msgid  "abc%2def"
+msgstr "xyz%1%2"
+EOF
+
+: ${MSGFMT=msgfmt}
+n=0
+while read comment; do
+  read msgid_line
+  read msgstr_line
+  n=`expr $n + 1`
+  tmpfiles="$tmpfiles f-kd-2-$n.po f-kd-2-$n.mo"
+  cat <<EOF > f-kd-2-$n.po
+#, kde-format
+${msgid_line}
+${msgstr_line}
+EOF
+  fail=
+  if echo "$comment" | grep 'Valid:' > /dev/null; then
+    if ${MSGFMT} --check-format -o f-kd-2-$n.mo f-kd-2-$n.po; then
+      :
+    else
+      fail=yes
+    fi
+  else
+    ${MSGFMT} --check-format -o f-kd-2-$n.mo f-kd-2-$n.po 2> /dev/null
+    if test $? = 1; then
+      :
+    else
+      fail=yes
+    fi
+  fi
+  if test -n "$fail"; then
+    echo "Format string checking error:" 1>&2
+    cat f-kd-2-$n.po 1>&2
+    exit 1
+  fi
+  rm -f f-kd-2-$n.po f-kd-2-$n.mo
+done < f-kd-2.data
+
+rm -fr $tmpfiles
+
+exit 0