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