xref: /netbsd-src/external/gpl2/gettext/dist/gettext-tools/tests/format-csharp-2 (revision 181254a7b1bdde6873432bffef2d2decc4b5c22f)
1#! /bin/sh
2
3# Test checking of Java format strings.
4
5tmpfiles=""
6trap 'rm -fr $tmpfiles' 1 2 3 15
7
8tmpfiles="$tmpfiles f-cs-2.data"
9cat <<\EOF > f-cs-2.data
10# Invalid: invalid msgstr
11msgid  "abc{0}def"
12msgstr "abc{"
13# Valid: same arguments
14msgid  "abc{1}def"
15msgstr "xyz{1}"
16# Valid: same arguments, differently written
17msgid  "abc{1}def"
18msgstr "xyz{01}"
19# Valid: permutation
20msgid  "abc{2}{0}{1}def"
21msgstr "xyz{1}{0}{2}"
22# Invalid: too few arguments
23msgid  "abc{1}def{0}"
24msgstr "xyz{0}"
25# Invalid: too many arguments
26msgid  "abc{0}def"
27msgstr "xyz{0}uvw{1}"
28# Valid: missing non-final argument
29msgid  "abc{1}def{0}"
30msgstr "xyz{1}"
31# Valid: added non-final argument
32msgid  "abc{1}def"
33msgstr "xyz{0}{1}"
34# Invalid: different number of arguments
35msgid  "abc{500000000}def"
36msgstr "xyz{500000001}"
37# Valid: type compatibility
38msgid  "abc{1:X}"
39msgstr "xyz{1:g}"
40EOF
41
42: ${MSGFMT=msgfmt}
43n=0
44while read comment; do
45  read msgid_line
46  read msgstr_line
47  n=`expr $n + 1`
48  tmpfiles="$tmpfiles f-cs-2-$n.po f-cs-2-$n.mo"
49  cat <<EOF > f-cs-2-$n.po
50#, csharp-format
51${msgid_line}
52${msgstr_line}
53EOF
54  fail=
55  if echo "$comment" | grep 'Valid:' > /dev/null; then
56    if ${MSGFMT} --check-format -o f-cs-2-$n.mo f-cs-2-$n.po; then
57      :
58    else
59      fail=yes
60    fi
61  else
62    ${MSGFMT} --check-format -o f-cs-2-$n.mo f-cs-2-$n.po 2> /dev/null
63    if test $? = 1; then
64      :
65    else
66      fail=yes
67    fi
68  fi
69  if test -n "$fail"; then
70    echo "Format string checking error:" 1>&2
71    cat f-cs-2-$n.po 1>&2
72    exit 1
73  fi
74  rm -f f-cs-2-$n.po f-cs-2-$n.mo
75done < f-cs-2.data
76
77rm -fr $tmpfiles
78
79exit 0
80