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