1 #! /bin/sh 2 3 # Test checking of Java format strings. 4 5 tmpfiles="" 6 trap 'rm -fr $tmpfiles' 1 2 3 15 7 8 tmpfiles="$tmpfiles f-j-2.data" 9 cat <<\EOF > f-j-2.data 10 # Invalid: invalid msgstr 11 msgid "abc{0}def" 12 msgstr "abc{" 13 # Valid: same arguments 14 msgid "abc{1}def" 15 msgstr "xyz{1}" 16 # Valid: same arguments, differently written 17 msgid "abc{1}def" 18 msgstr "xyz{01}" 19 # Valid: permutation 20 msgid "abc{2}{0}{1}def" 21 msgstr "xyz{1}{0}{2}" 22 # Invalid: too few arguments 23 msgid "abc{1}def{0}" 24 msgstr "xyz{0}" 25 # Invalid: too many arguments 26 msgid "abc{0}def" 27 msgstr "xyz{0}uvw{1}" 28 # Invalid: missing non-final argument 29 msgid "abc{1}def{0}" 30 msgstr "xyz{1}" 31 # Invalid: added non-final argument 32 msgid "abc{1}def" 33 msgstr "xyz{0}{1}" 34 # Invalid: different number of arguments 35 msgid "abc{500000000}def" 36 msgstr "xyz{500000001}" 37 # Valid: type compatibility 38 msgid "abc{1,number}" 39 msgstr "xyz{1,choice,0#zero|1#{1,number}}" 40 # Valid: type compatibility 41 msgid "abc{1,number}" 42 msgstr "xyz{1,number,currency}" 43 # Valid: type compatibility 44 msgid "abc{1,number}" 45 msgstr "xyz{1,number,percent}" 46 # Valid: type compatibility 47 msgid "abc{1,number}" 48 msgstr "xyz{1,number,integer}" 49 # Valid: type compatibility 50 msgid "abc{1,number}" 51 msgstr "xyz{1,number,###,##0}" 52 # Valid: type compatibility 53 msgid "abc{1,date}" 54 msgstr "xyz{1,time}" 55 # Valid: type compatibility 56 msgid "abc{1,date}" 57 msgstr "xyz{1,date,short}" 58 # Valid: type compatibility 59 msgid "abc{1,date}" 60 msgstr "xyz{1,date,medium}" 61 # Valid: type compatibility 62 msgid "abc{1,date}" 63 msgstr "xyz{1,date,long}" 64 # Valid: type compatibility 65 msgid "abc{1,date}" 66 msgstr "xyz{1,date,full}" 67 # Valid: type compatibility 68 msgid "abc{1,date}" 69 msgstr "xyz{1,date,yyyy-MM-dd}" 70 # Valid: type compatibility 71 msgid "abc{1,time}" 72 msgstr "xyz{1,time,short}" 73 # Valid: type compatibility 74 msgid "abc{1,time}" 75 msgstr "xyz{1,time,medium}" 76 # Valid: type compatibility 77 msgid "abc{1,time}" 78 msgstr "xyz{1,time,long}" 79 # Valid: type compatibility 80 msgid "abc{1,time}" 81 msgstr "xyz{1,time,full}" 82 # Valid: type compatibility 83 msgid "abc{1,time}" 84 msgstr "xyz{1,time,}" 85 # Valid: type compatibility 86 msgid "abc{1,time}" 87 msgstr "xyz{1,time,hh:mm:ss}" 88 # Invalid: type incompatibility 89 msgid "abc{1}" 90 msgstr "xyz{1,number}" 91 # Invalid: type incompatibility 92 msgid "abc{1}" 93 msgstr "xyz{1,date}" 94 # Invalid: type incompatibility 95 msgid "abc{1,time}" 96 msgstr "xyz{1,number}" 97 # Invalid: type incompatibility 98 msgid "abc{1,number}" 99 msgstr "xyz{1,date}" 100 # Invalid: type incompatibility 101 msgid "abc{1}" 102 msgstr "xyz{1,choice,0#zero|1#{1,number}}" 103 # Invalid: type incompatibility 104 msgid "abc{1}" 105 msgstr "xyz{1,choice,0#zero|1#{0,number}}" 106 # Invalid: type incompatibility 107 msgid "abc{0,number}{1}" 108 msgstr "xyz{0,choice,0#zero|1#{1,number}}" 109 EOF 110 111 : ${MSGFMT=msgfmt} 112 n=0 113 while read comment; do 114 read msgid_line 115 read msgstr_line 116 n=`expr $n + 1` 117 tmpfiles="$tmpfiles f-j-2-$n.po f-j-2-$n.mo" 118 cat <<EOF > f-j-2-$n.po 119 #, java-format 120 ${msgid_line} 121 ${msgstr_line} 122 EOF 123 fail= 124 if echo "$comment" | grep 'Valid:' > /dev/null; then 125 if ${MSGFMT} --check-format -o f-j-2-$n.mo f-j-2-$n.po; then 126 : 127 else 128 fail=yes 129 fi 130 else 131 ${MSGFMT} --check-format -o f-j-2-$n.mo f-j-2-$n.po 2> /dev/null 132 if test $? = 1; then 133 : 134 else 135 fail=yes 136 fi 137 fi 138 if test -n "$fail"; then 139 echo "Format string checking error:" 1>&2 140 cat f-j-2-$n.po 1>&2 141 exit 1 142 fi 143 rm -f f-j-2-$n.po f-j-2-$n.mo 144 done < f-j-2.data 145 146 rm -fr $tmpfiles 147 148 exit 0 149