Imported Upstream version 0.19.7
[platform/upstream/gettext.git] / gettext-tools / tests / format-perl-brace-2
1 #! /bin/sh
2 . "${srcdir=.}/init.sh"; path_prepend_ . ../src
3
4 # Test checking of Perl brace format strings.
5
6 cat <<\EOF > f-pb-2.data
7 # Valid: same named arguments
8 msgid  "abc{date}{time}"
9 msgstr "xyz{date}{time}"
10 # Valid: permutation
11 msgid  "abc{x3}{x1}{x2}def"
12 msgstr "xyz{x2}{x1}{x3}"
13 # Invalid: missing argument
14 msgid  "abc{x2}def{x1}"
15 msgstr "xyz{x1}"
16 # Invalid: missing argument
17 msgid  "abc{x1}def{x2}"
18 msgstr "xyz{x2}"
19 # Valid: added argument (valid since "{zoo}" expands to itself)
20 msgid  "abc{foo}def"
21 msgstr "xyz{foo}uvw{zoo}"
22 # Valid: multiple reuse of same argument
23 msgid  "{foo} {bar} {baz}"
24 msgstr "{baz} {bar} {foo} {bar}"
25 # Valid: single reuse of same argument
26 msgid  "{baz} {bar} {foo} {bar}"
27 msgstr "{foo} {bar} {baz}"
28 EOF
29
30 : ${MSGFMT=msgfmt}
31 n=0
32 while read comment; do
33   read msgid_line
34   read msgstr_line
35   n=`expr $n + 1`
36   cat <<EOF > f-pb-2-$n.po
37 #, perl-brace-format
38 ${msgid_line}
39 ${msgstr_line}
40 EOF
41   fail=
42   if echo "$comment" | grep 'Valid:' > /dev/null; then
43     if ${MSGFMT} --check-format -o f-pb-2-$n.mo f-pb-2-$n.po; then
44       :
45     else
46       fail=yes
47     fi
48   else
49     ${MSGFMT} --check-format -o f-pb-2-$n.mo f-pb-2-$n.po 2> /dev/null
50     if test $? = 1; then
51       :
52     else
53       fail=yes
54     fi
55   fi
56   if test -n "$fail"; then
57     echo "Format string checking error:" 1>&2
58     cat f-pb-2-$n.po 1>&2
59     exit 1
60   fi
61   rm -f f-pb-2-$n.po f-pb-2-$n.mo
62 done < f-pb-2.data
63
64 exit 0