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