1#! /bin/sh
2. "${srcdir=.}/init.sh"; path_prepend_ . ../src
3
4# Test checking of Python brace format strings.
5
6cat <<\EOF > f-pyb-2.data
7# Valid: same named arguments
8msgid  "abc{date}{time}"
9msgstr "xyz{date}{time}"
10# Valid: permutation
11msgid  "abc{x3}{x1}{x2}def"
12msgstr "xyz{x2}{x1}{x3}"
13# Invalid: missing argument
14msgid  "abc{x2}def{x1}"
15msgstr "xyz{x1}"
16# Invalid: missing argument
17msgid  "abc{x1}def{x2}"
18msgstr "xyz{x2}"
19# Invalid: added argument
20msgid  "abc{foo}def"
21msgstr "xyz{foo}uvw{zoo}"
22# Valid: multiple reuse of same argument
23msgid  "{foo} {bar} {baz}"
24msgstr "{baz} {bar} {foo} {bar}"
25# Valid: single reuse of same argument
26msgid  "{baz} {bar} {foo} {bar}"
27msgstr "{foo} {bar} {baz}"
28# Valid: "{{" is an escape of "{"
29msgid  "abc{{{x1}{x2}"
30msgstr "{x2}abc{x1}"
31EOF
32
33: ${MSGFMT=msgfmt}
34n=0
35while read comment; do
36  read msgid_line
37  read msgstr_line
38  n=`expr $n + 1`
39  cat <<EOF > f-pyb-2-$n.po
40#, python-brace-format
41${msgid_line}
42${msgstr_line}
43EOF
44  fail=
45  if echo "$comment" | grep 'Valid:' > /dev/null; then
46    if ${MSGFMT} --check-format -o f-pyb-2-$n.mo f-pyb-2-$n.po; then
47      :
48    else
49      fail=yes
50    fi
51  else
52    ${MSGFMT} --check-format -o f-pyb-2-$n.mo f-pyb-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-pyb-2-$n.po 1>&2
62    Exit 1
63  fi
64  rm -f f-pyb-2-$n.po f-pyb-2-$n.mo
65done < f-pyb-2.data
66
67Exit 0
68