Home | History | Annotate | Line # | Download | only in tests
      1  1.1  christos #! /bin/sh
      2  1.1  christos 
      3  1.1  christos # Test recognition of Object Pascal 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-op-1.data"
      9  1.1  christos cat <<\EOF > f-op-1.data
     10  1.1  christos # Valid: no argument
     11  1.1  christos "abc%%"
     12  1.1  christos # Valid: one string argument
     13  1.1  christos "abc%s"
     14  1.1  christos # Valid: one integer argument
     15  1.1  christos "abc%d"
     16  1.1  christos # Valid: one integer argument
     17  1.1  christos "abc%X"
     18  1.1  christos # Valid: one floating-point argument
     19  1.1  christos "abc%e"
     20  1.1  christos # Valid: one floating-point argument
     21  1.1  christos "abc%f"
     22  1.1  christos # Valid: one floating-point argument
     23  1.1  christos "abc%g"
     24  1.1  christos # Valid: one floating-point argument
     25  1.1  christos "abc%n"
     26  1.1  christos # Valid: one floating-point argument
     27  1.1  christos "abc%m"
     28  1.1  christos # Valid: one pointer argument
     29  1.1  christos "abc%p"
     30  1.1  christos # Valid: one argument with flags
     31  1.1  christos "abc%-g"
     32  1.1  christos # Valid: one argument with width
     33  1.1  christos "abc%2g"
     34  1.1  christos # Valid: one argument with width
     35  1.1  christos "abc%*g"
     36  1.1  christos # Valid: one argument with precision
     37  1.1  christos "abc%.4g"
     38  1.1  christos # Valid: one argument with precision
     39  1.1  christos "abc%.*g"
     40  1.1  christos # Valid: one argument with width and precision
     41  1.1  christos "abc%14.4g"
     42  1.1  christos # Valid: one argument with width and precision
     43  1.1  christos "abc%14.*g"
     44  1.1  christos # Valid: one argument with width and precision
     45  1.1  christos "abc%*.4g"
     46  1.1  christos # Valid: one argument with width and precision
     47  1.1  christos "abc%*.*g"
     48  1.1  christos # Invalid: unterminated
     49  1.1  christos "abc%"
     50  1.1  christos # Invalid: unknown format specifier
     51  1.1  christos "abc%y"
     52  1.1  christos # Invalid: flags after width
     53  1.1  christos "abc%*-g"
     54  1.1  christos # Invalid: twice precision
     55  1.1  christos "abc%.4.2g"
     56  1.1  christos # Valid: three arguments
     57  1.1  christos "abc%d%x%x"
     58  1.1  christos # Valid: a numbered argument
     59  1.1  christos "abc%0:d"
     60  1.1  christos # Valid: two-digit numbered arguments
     61  1.1  christos "abc%10:def%9:dgh%8:dij%7:dkl%6:dmn%5:dop%4:dqr%3:dst%2:duv%1:dwx%0:dyz"
     62  1.1  christos # Invalid: unterminated number
     63  1.1  christos "abc%1"
     64  1.1  christos # Invalid: flags before number
     65  1.1  christos "abc%-0:d"
     66  1.1  christos # Valid: three arguments, two with same number
     67  1.1  christos "abc%0:4e,%1:p,%0:g"
     68  1.1  christos # Invalid: argument with conflicting types
     69  1.1  christos "abc%0:4x,%1:p,%0:s"
     70  1.1  christos # Invalid: argument with conflicting types
     71  1.1  christos "abc%0:4e,%1:p,%0:d"
     72  1.1  christos # Valid: argument with different but not conflicting types
     73  1.1  christos "abc%0:4x,%1:p,%0:d"
     74  1.1  christos # Valid: mixing of numbered and unnumbered arguments
     75  1.1  christos "abc%d%1:x"
     76  1.1  christos # Valid: numbered argument with constant precision
     77  1.1  christos "abc%0:.9x"
     78  1.1  christos # Valid: mixing of numbered and unnumbered arguments
     79  1.1  christos "abc%3:.*x"
     80  1.1  christos # Valid: missing non-final argument
     81  1.1  christos "abc%1:x%3:s"
     82  1.1  christos # Valid: permutation
     83  1.1  christos "abc%1:ddef%0:d"
     84  1.1  christos # Valid: multiple uses of same argument
     85  1.1  christos "abc%2:xdef%1:pghi%2:x"
     86  1.1  christos # Valid: one argument with width
     87  1.1  christos "abc%1:*g"
     88  1.1  christos # Valid: one argument with width and precision
     89  1.1  christos "abc%2:*.*g"
     90  1.1  christos EOF
     91  1.1  christos 
     92  1.1  christos : ${XGETTEXT=xgettext}
     93  1.1  christos n=0
     94  1.1  christos while read comment; do
     95  1.1  christos   read string
     96  1.1  christos   n=`expr $n + 1`
     97  1.1  christos   tmpfiles="$tmpfiles f-op-1-$n.in f-op-1-$n.po"
     98  1.1  christos   echo "x.y=${string}" | sed -e "s/\"/'/g" > f-op-1-$n.in
     99  1.1  christos   ${XGETTEXT} -L RST -o f-op-1-$n.po f-op-1-$n.in || exit 1
    100  1.1  christos   test -f f-op-1-$n.po || exit 1
    101  1.1  christos   fail=
    102  1.1  christos   if echo "$comment" | grep 'Valid:' > /dev/null; then
    103  1.1  christos     if grep object-pascal-format f-op-1-$n.po > /dev/null; then
    104  1.1  christos       :
    105  1.1  christos     else
    106  1.1  christos       fail=yes
    107  1.1  christos     fi
    108  1.1  christos   else
    109  1.1  christos     if grep object-pascal-format f-op-1-$n.po > /dev/null; then
    110  1.1  christos       fail=yes
    111  1.1  christos     else
    112  1.1  christos       :
    113  1.1  christos     fi
    114  1.1  christos   fi
    115  1.1  christos   if test -n "$fail"; then
    116  1.1  christos     echo "Format string recognition error:" 1>&2
    117  1.1  christos     cat f-op-1-$n.in 1>&2
    118  1.1  christos     echo "Got:" 1>&2
    119  1.1  christos     cat f-op-1-$n.po 1>&2
    120  1.1  christos     exit 1
    121  1.1  christos   fi
    122  1.1  christos   rm -f f-op-1-$n.in f-op-1-$n.po
    123  1.1  christos done < f-op-1.data
    124  1.1  christos 
    125  1.1  christos rm -fr $tmpfiles
    126  1.1  christos 
    127  1.1  christos exit 0
    128