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 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-j-1.data"
      9  1.1  christos cat <<\EOF > f-j-1.data
     10  1.1  christos # Valid: one argument
     11  1.1  christos "abc{0}def"
     12  1.1  christos # Valid: ten arguments
     13  1.1  christos "abc{9}def"
     14  1.1  christos # Valid: two-digit argument numbers
     15  1.1  christos "abc{00}def"
     16  1.1  christos # Valid: huge argument numbers
     17  1.1  christos "abc{500000000}def"
     18  1.1  christos # Invalid: unterminated
     19  1.1  christos "abc{"
     20  1.1  christos # Invalid: unterminated
     21  1.1  christos "abc{0"
     22  1.1  christos # Invalid: missing number
     23  1.1  christos "abc{}def"
     24  1.1  christos # Invalid: non-digit
     25  1.1  christos "abc{number}def"
     26  1.1  christos # Invalid: non-digit
     27  1.1  christos "abc{-0}def"
     28  1.1  christos # Valid: two arguments
     29  1.1  christos "abc{1}def{0}"
     30  1.1  christos # Valid: multiple uses of same argument
     31  1.1  christos "abc{1}def{0}ghi{1}"
     32  1.1  christos # Invalid: broken elementFormat
     33  1.1  christos "abc{0,}def"
     34  1.1  christos # Invalid: invalid elementFormat
     35  1.1  christos "abc{1,string}def"
     36  1.1  christos # Valid: elementFormat of length 1
     37  1.1  christos "abc{1,number}def"
     38  1.1  christos # Valid: elementFormat of length 1
     39  1.1  christos "abc{1,date}def"
     40  1.1  christos # Valid: elementFormat of length 1
     41  1.1  christos "abc{1,time}def"
     42  1.1  christos # Valid: elementFormat of length 1
     43  1.1  christos "abc{1,choice}def"
     44  1.1  christos # Invalid: broken elementFormat
     45  1.1  christos "abc{1,number,}def"
     46  1.1  christos # Valid: builtin numberStyle
     47  1.1  christos "abc{1,number,currency}def"
     48  1.1  christos # Valid: builtin numberStyle
     49  1.1  christos "abc{1,number,percent}def"
     50  1.1  christos # Valid: builtin numberStyle
     51  1.1  christos "abc{1,number,integer}def"
     52  1.1  christos # Valid: builtin datetimeStyle
     53  1.1  christos "abc{1,date,short}def"
     54  1.1  christos # Valid: builtin datetimeStyle
     55  1.1  christos "abc{1,date,medium}def"
     56  1.1  christos # Valid: builtin datetimeStyle
     57  1.1  christos "abc{1,date,long}def"
     58  1.1  christos # Valid: builtin datetimeStyle
     59  1.1  christos "abc{1,date,full}def"
     60  1.1  christos # Valid: builtin datetimeStyle
     61  1.1  christos "abc{1,time,short}def"
     62  1.1  christos # Valid: builtin datetimeStyle
     63  1.1  christos "abc{1,time,medium}def"
     64  1.1  christos # Valid: builtin datetimeStyle
     65  1.1  christos "abc{1,time,long}def"
     66  1.1  christos # Valid: builtin datetimeStyle
     67  1.1  christos "abc{1,time,full}def"
     68  1.1  christos # Valid: dateFormatPattern
     69  1.1  christos "abc{1,date,foobar}"
     70  1.1  christos # Valid: dateFormatPattern
     71  1.1  christos "abc{1,time,foobar}"
     72  1.1  christos # Valid: dateFormatPattern with comma
     73  1.1  christos "abc{1,date,foo,bar}"
     74  1.1  christos # Valid: numberFormatPattern
     75  1.1  christos "abc{1,number,###,##0}def"
     76  1.1  christos # Invalid: numberFormatPattern
     77  1.1  christos "abc{1,number,foobar}"
     78  1.1  christos # Valid: empty choiceFormatPattern
     79  1.1  christos "abc{1,choice,}def"
     80  1.1  christos # Valid: choiceFormatPattern
     81  1.1  christos "abc{1,choice,0#zero|1#one|2#many}def"
     82  1.1  christos # Invalid: empty clause in choiceFormatPattern
     83  1.1  christos "abc{1,choice,|0#zero|1#one|2#many}def"
     84  1.1  christos # Valid: empty clause at end of choiceFormatPattern
     85  1.1  christos "abc{1,choice,0#zero|1#one|2#many|}def"
     86  1.1  christos # Invalid: short clause in choiceFormatPattern
     87  1.1  christos "abc{1,choice,-1|0#zero|1#one|2#many}def"
     88  1.1  christos # Valid: short clause at end of choiceFormatPattern
     89  1.1  christos "abc{1,choice,0#zero|1#one|2#many|3}def"
     90  1.1  christos # Valid: choiceFormatPattern with different argument
     91  1.1  christos "abc{1,choice,1#one|2#{0,date}}def"
     92  1.1  christos # Valid: choiceFormatPattern with same argument
     93  1.1  christos "abc{1,choice,1#one|2#{1}}def"
     94  1.1  christos # Valid: choiceFormatPattern with same argument
     95  1.1  christos "abc{1,choice,1#one|2#{1,number}}def"
     96  1.1  christos # Invalid: choiceFormatPattern with same argument, type conflict
     97  1.1  christos "abc{1,choice,1#one|2#{1,date}}def"
     98  1.1  christos # Invalid: missing opening brace
     99  1.1  christos "abc1}def{0}"
    100  1.1  christos # Valid: quoted brace
    101  1.1  christos "abc1'}'def{0}"
    102  1.1  christos # Invalid: quoted brace
    103  1.1  christos "abc{1'}'def"
    104  1.1  christos # Valid: unterminated quote
    105  1.1  christos "abc{0}1'}"
    106  1.1  christos # Valid: quoted brace, '' counts as a single quote
    107  1.1  christos "abc''1'}'def{0}"
    108  1.1  christos # Invalid: '' counts as a single quote
    109  1.1  christos "abc{1''}def"
    110  1.1  christos # Valid: quote inside elementFormat is hidden
    111  1.1  christos "abc{1,date,x'y}def"
    112  1.1  christos # Valid: numberFormatPattern with quote
    113  1.1  christos "abc{1,number,#0';'}def"
    114  1.1  christos # Invalid: numberFormatPattern with wrong number syntax
    115  1.1  christos "abc{1,number,#0;}def"
    116  1.1  christos # Valid: numberFormatPattern with quote
    117  1.1  christos "abc{1,number,0.##'E}def"
    118  1.1  christos # Valid: numberFormatPattern without quote
    119  1.1  christos "abc{1,number,0.##E}def"
    120  1.1  christos EOF
    121  1.1  christos 
    122  1.1  christos : ${XGETTEXT=xgettext}
    123  1.1  christos n=0
    124  1.1  christos while read comment; do
    125  1.1  christos   read string
    126  1.1  christos   n=`expr $n + 1`
    127  1.1  christos   tmpfiles="$tmpfiles f-j-1-$n.in f-j-1-$n.po"
    128  1.1  christos   cat <<EOF > f-j-1-$n.in
    129  1.1  christos gettext(${string});
    130  1.1  christos EOF
    131  1.1  christos   ${XGETTEXT} -L Java -o f-j-1-$n.po f-j-1-$n.in || exit 1
    132  1.1  christos   test -f f-j-1-$n.po || exit 1
    133  1.1  christos   fail=
    134  1.1  christos   if echo "$comment" | grep 'Valid:' > /dev/null; then
    135  1.1  christos     if grep java-format f-j-1-$n.po > /dev/null; then
    136  1.1  christos       :
    137  1.1  christos     else
    138  1.1  christos       fail=yes
    139  1.1  christos     fi
    140  1.1  christos   else
    141  1.1  christos     if grep java-format f-j-1-$n.po > /dev/null; then
    142  1.1  christos       fail=yes
    143  1.1  christos     else
    144  1.1  christos       :
    145  1.1  christos     fi
    146  1.1  christos   fi
    147  1.1  christos   if test -n "$fail"; then
    148  1.1  christos     echo "Format string recognition error:" 1>&2
    149  1.1  christos     cat f-j-1-$n.in 1>&2
    150  1.1  christos     echo "Got:" 1>&2
    151  1.1  christos     cat f-j-1-$n.po 1>&2
    152  1.1  christos     exit 1
    153  1.1  christos   fi
    154  1.1  christos   rm -f f-j-1-$n.in f-j-1-$n.po
    155  1.1  christos done < f-j-1.data
    156  1.1  christos 
    157  1.1  christos rm -fr $tmpfiles
    158  1.1  christos 
    159  1.1  christos exit 0
    160