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