Imported Upstream version 0.19.7
[platform/upstream/gettext.git] / gettext-tools / tests / format-qt-2
1 #! /bin/sh
2 . "${srcdir=.}/init.sh"; path_prepend_ . ../src
3
4 # Test checking of Qt format strings.
5
6 cat <<\EOF > f-qt-2.data
7 # Valid: %% doesn't count
8 msgid  "abc%%def"
9 msgstr "xyz"
10 # Valid: same arguments
11 msgid  "abc%2def"
12 msgstr "xyz%2"
13 # Valid: same arguments, msgstr may be simpler than msgid
14 msgid  "abc%L2def"
15 msgstr "xyz%2"
16 # Valid: same arguments, msgstr may be simpler than msgid
17 msgid  "abc%02def"
18 msgstr "xyz%2"
19 # Invalid: msgid is simple but msgstr is not
20 msgid  "abc%2def"
21 msgstr "xyz%L2"
22 # Invalid: msgid is simple but msgstr is not
23 msgid  "abc%2def"
24 msgstr "xyz%02"
25 # Valid: repetition of an argument in the translation
26 msgid  "abc%2def"
27 msgstr "xyz%2uvw%2"
28 # Valid: removing repeated argument in the translation
29 msgid  "abc%2def%2"
30 msgstr "xyz%2uvw"
31 # Valid: permutation
32 msgid  "abc%3%1%2def"
33 msgstr "xyz%2%1%3"
34 # Invalid: too few arguments
35 msgid  "abc%2def%1"
36 msgstr "xyz%1"
37 # Invalid: too many arguments
38 msgid  "abc%1def"
39 msgstr "xyz%1uvw%2"
40 # Invalid: missing non-final argument
41 msgid  "abc%2def%1"
42 msgstr "xyz%2"
43 # Invalid: added non-final argument
44 msgid  "abc%2def"
45 msgstr "xyz%1%2"
46 EOF
47
48 : ${MSGFMT=msgfmt}
49 n=0
50 while read comment; do
51   read msgid_line
52   read msgstr_line
53   n=`expr $n + 1`
54   cat <<EOF > f-qt-2-$n.po
55 #, qt-format
56 ${msgid_line}
57 ${msgstr_line}
58 EOF
59   fail=
60   if echo "$comment" | grep 'Valid:' > /dev/null; then
61     if ${MSGFMT} --check-format -o f-qt-2-$n.mo f-qt-2-$n.po; then
62       :
63     else
64       fail=yes
65     fi
66   else
67     ${MSGFMT} --check-format -o f-qt-2-$n.mo f-qt-2-$n.po 2> /dev/null
68     if test $? = 1; then
69       :
70     else
71       fail=yes
72     fi
73   fi
74   if test -n "$fail"; then
75     echo "Format string checking error:" 1>&2
76     cat f-qt-2-$n.po 1>&2
77     exit 1
78   fi
79   rm -f f-qt-2-$n.po f-qt-2-$n.mo
80 done < f-qt-2.data
81
82 exit 0