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