Add -lm dependency for gettextlib to fix LTO build
[platform/upstream/gettext.git] / gettext-tools / tests / format-lisp-2
1 #! /bin/sh
2 . "${srcdir=.}/init.sh"; path_prepend_ . ../src
3
4 # Test checking of Lisp format strings.
5
6 cat <<\EOF > f-l-2.data
7 # Valid: ~~ doesn't count
8 msgid  "abc~~def"
9 msgstr "xyz"
10 # Invalid: invalid msgstr
11 msgid  "abc~~def"
12 msgstr "xyz~"
13 # Valid: same argument
14 msgid  "abc~Ddef"
15 msgstr "xyz~D"
16 # Valid: same arguments
17 msgid  "abc~1000000@*~Ddef"
18 msgstr "~1000000@*xyz~D"
19 # Valid: permutation
20 msgid  "abc~D~C~Fdef"
21 msgstr "xyz~2@*~F~2:*~C~2:*~D"
22 # Invalid: too few arguments
23 msgid  "abc~1@*~Sdef~0@*~S"
24 msgstr "xyz~S"
25 # Invalid: too many arguments
26 msgid  "abc~Ddef"
27 msgstr "xyz~Duvw~C"
28 # Invalid: missing non-final argument
29 msgid  "abc~1@*~Sdef~0@*~F"
30 msgstr "xyz~1@*~S"
31 # Invalid: added non-final argument
32 msgid  "abc~1@*~Ddef"
33 msgstr "xyz~F~D"
34 # Valid: formatting variations
35 msgid  "abc~Sdef"
36 msgstr "xyz~:S"
37 # Valid: formatting variations
38 msgid  "abc~4Sdef"
39 msgstr "xyz~7S"
40 # Valid: type compatibility
41 msgid  "abc~Sdef"
42 msgstr "xyz~W"
43 # Valid: type compatibility
44 msgid  "abc~Ddef"
45 msgstr "xyz~B"
46 # Valid: type compatibility
47 msgid  "abc~Ddef"
48 msgstr "xyz~O"
49 # Valid: type compatibility
50 msgid  "abc~Ddef"
51 msgstr "xyz~X"
52 # Valid: type compatibility
53 msgid  "abc~Ddef"
54 msgstr "xyz~R"
55 # Valid: optional plural
56 msgid  "~D egg~:P"
57 msgstr "~D Eier"
58 # Valid: type compatibility
59 msgid  "abc~Fdef"
60 msgstr "xyz~E"
61 # Valid: type compatibility
62 msgid  "abc~Fdef"
63 msgstr "xyz~G"
64 # Valid: type compatibility
65 msgid  "abc~Fdef"
66 msgstr "xyz~$"
67 # Invalid: type incompatibility
68 msgid  "abc~Fdef"
69 msgstr "xyz~D"
70 # Invalid: type incompatibility
71 msgid  "abc~Ddef"
72 msgstr "xyz~C"
73 # Invalid: type incompatibility
74 msgid  "abc~Fdef"
75 msgstr "xyz~C"
76 # Invalid: type incompatibility
77 msgid  "abc~Sdef"
78 msgstr "xyz~D"
79 # Invalid: type incompatibility
80 msgid  "abc~Sdef"
81 msgstr "xyz~F"
82 # Invalid: type incompatibility
83 msgid  "abc~Sdef"
84 msgstr "xyz~C"
85 # Valid: extra formatting
86 msgid  "abc~Ddef~S"
87 msgstr "xyz~D~_def~%~S"
88 # Valid: FORMAT-GOTO doesn't consume an argument by itself
89 msgid  "abc~5@*~Ddef~C"
90 msgstr "xyz~6@*~C~2@*uvw~5@*~R"
91 # Invalid: @ matters
92 msgid  "abc~?"
93 msgstr "xyz~@?"
94 # Valid: case conversion is optional
95 msgid  "abc~(~S~)"
96 msgstr "xyz~S"
97 # Valid: case conversion is optional
98 msgid  "abc~(~D~^ ~D~)"
99 msgstr "xyz~D~^ ~D"
100 # Invalid: ~^ matters
101 msgid  "abc~(~D~^ ~D~)"
102 msgstr "xyz~(~D ~D~)"
103 # Valid: case conversion is optional, and it doesn't catch ~^
104 msgid  "abc~(~D~^ ~D~)def~C"
105 msgstr "xyz~D~^ ~Duvw~C"
106 # Valid: synonymous conditionals
107 msgid  "abc~@[~D~]def~C"
108 msgstr "xyz~:[~;~:*~D~]~C"
109 # Valid: synonymous conditionals
110 msgid  "abc~Ddef"
111 msgstr "abc~[null~;eins~:;~:*~D~]def"
112 # Valid: conditionals are optional and don't catch ~^
113 msgid  "abc~:[~;~]~^~D~C"
114 msgstr "xyz~:[uvw~^~R~;~:*~S~^~D~]~C"
115 # Invalid: ~:[ requires an argument, ~1@* doesn't
116 msgid  "abc~1@*~^~D~C"
117 msgstr "xyz~:[uvw~^~R~;~:*~S~^~D~]~C"
118 # Invalid: ~{~} is special
119 msgid  "abc~{ ~}"
120 msgstr "xyz~{~}"
121 # Invalid: @ matters
122 msgid  "abc~{~S~}"
123 msgstr "xyz~@{~S~}"
124 # Invalid: @ matters
125 msgid  "abc~:{~S~}"
126 msgstr "xyz~@:{~S~}"
127 # Invalid: : matters
128 msgid  "abc~{~S~}"
129 msgstr "xyz~:{~S~}"
130 # Invalid: : matters
131 msgid  "abc~@{~S~}"
132 msgstr "xyz~@:{~S~}"
133 # Invalid: @: matters
134 msgid  "abc~{~S~}"
135 msgstr "xyz~@:{~S~}"
136 # Valid: permutation inside iteration
137 msgid  "abc~{~D ~C~}"
138 msgstr "xyz~{~1@*~C~2:*~D~1*~}"
139 # Invalid: permutation inside iteration, but wrong position at iteration end
140 msgid  "abc~{~D ~C~}"
141 msgstr "xyz~{~1@*~C~2:*~D~}"
142 # Invalid: ~^ inside iteration matters
143 msgid  "abc~{~D ~^~C~}"
144 msgstr "xyz~{~D ~C~}"
145 # Invalid: ~^ inside iteration depends on position
146 msgid  "abc~{~D ~^~C~}"
147 msgstr "xyz~{~1@*~C~^~2:*~D~1*~}"
148 # Invalid: ~^ inside iteration depends on position
149 msgid  "abc~{~D ~^~C~}"
150 msgstr "xyz~{~1@*~C~2:*~^~D~1*~}"
151 # Invalid: ~^ inside iteration depends on position
152 msgid  "abc~{~D ~^~C~}"
153 msgstr "xyz~{~1@*~C~2:*~D~^~1*~}"
154 # Invalid: ~^ inside iteration depends on position
155 msgid  "abc~{~D ~^~C~}"
156 msgstr "xyz~{~1@*~C~2:*~D~1*~^~}"
157 # Valid: justification is optional
158 msgid  "abc~<~D~;~C~>"
159 msgstr "xyz~D~C"
160 # Valid: justification with different segmentation
161 msgid  "abc~<~D ~D~;~C~;~S~S~>"
162 msgstr "xyz~<~D~;~D~C~S~;~S~>"
163 # Invalid: justification catches ~^
164 msgid  "abc~<~D~;~^~D~>~C"
165 msgstr "abc~D~^~D~C"
166 # Invalid: type compatibility with non-strict checking
167 msgid "abc~{~c~c~}"
168 msgid_plural "abc~{~c~c~}"
169 msgstr[0] "xyz~{~c~d~}"
170 msgstr[1] "xyz~{~c~d~}"
171 EOF
172
173 : ${MSGFMT=msgfmt}
174 n=0
175 while read comment; do
176   read msgid_line
177   read msgstr_line
178   msgid_plural_line=""
179   if echo "$msgstr_line" | grep '^msgid_plural' > /dev/null; then
180     msgid_plural_line="$msgstr_line"
181     read msgstr0_line
182     read msgstr1_line
183   fi
184   n=`expr $n + 1`
185   if test -z "$msgid_plural_line"; then
186     cat <<EOF > f-l-2-$n.po
187 #, lisp-format
188 ${msgid_line}
189 ${msgstr_line}
190 EOF
191   else
192     cat <<EOF > f-l-2-$n.po
193 #, lisp-format
194 ${msgid_line}
195 ${msgid_plural_line}
196 ${msgstr0_line}
197 ${msgstr1_line}
198 EOF
199   fi
200   fail=
201   if echo "$comment" | grep 'Valid:' > /dev/null; then
202     if ${MSGFMT} --check-format -o f-l-2-$n.mo f-l-2-$n.po; then
203       :
204     else
205       fail=yes
206     fi
207   else
208     ${MSGFMT} --check-format -o f-l-2-$n.mo f-l-2-$n.po 2> /dev/null
209     if test $? = 1; then
210       :
211     else
212       fail=yes
213     fi
214   fi
215   if test -n "$fail"; then
216     echo "Format string checking error:" 1>&2
217     cat f-l-2-$n.po 1>&2
218     exit 1
219   fi
220   rm -f f-l-2-$n.po f-l-2-$n.mo
221 done < f-l-2.data
222
223 exit 0