1#! /bin/sh
2
3# Test recognition of Perl brace format strings.
4
5tmpfiles=""
6trap 'rm -fr $tmpfiles' 1 2 3 15
7
8tmpfiles="$tmpfiles f-pb-1.data"
9cat <<\EOF > f-pb-1.data
10# Invalid: no argument
11"abc"
12# Valid: a named argument
13"abc{value}"
14# Invalid: an empty name
15"abc{}"
16# Invalid: unterminated name
17"abc{value"
18# Valid: three arguments, two with equal names
19"abc{addr},{char},{addr}"
20# Invalid: place-holder contains a space.
21"{foo bar}"
22# Invalid: missing right angle bracket.
23"{foo bar"
24# Valid: not nested, but one single place-holder.
25"{foo{bar}baz}"
26# Valid: no nesting error, but one single place-holder.
27"{foo{bar}baz"
28# Valid: place-holder with spaces must be ignored, but still one remaining.
29"{foo bar} {baz}"
30# Invalid: percent sign not allowed.
31"{foo%bar}"
32EOF
33
34: ${XGETTEXT=xgettext}
35n=0
36while read comment; do
37  read string
38  n=`expr $n + 1`
39  tmpfiles="$tmpfiles f-pb-1-$n.in f-pb-1-$n.po"
40  cat <<EOF > f-pb-1-$n.in
41gettext(${string});
42EOF
43  ${XGETTEXT} -L Perl -o f-pb-1-$n.po f-pb-1-$n.in || exit 1
44  test -f f-pb-1-$n.po || exit 1
45  fail=
46  if echo "$comment" | grep 'Valid:' > /dev/null; then
47    if grep perl-brace-format f-pb-1-$n.po > /dev/null; then
48      :
49    else
50      fail=yes
51    fi
52  else
53    if grep perl-brace-format f-pb-1-$n.po > /dev/null; then
54      fail=yes
55    else
56      :
57    fi
58  fi
59  if test -n "$fail"; then
60    echo "Format string recognition error:" 1>&2
61    cat f-pb-1-$n.in 1>&2
62    echo "Got:" 1>&2
63    cat f-pb-1-$n.po 1>&2
64    exit 1
65  fi
66  rm -f f-pb-1-$n.in f-pb-1-$n.po
67done < f-pb-1.data
68
69rm -fr $tmpfiles
70
71exit 0
72