1#! /bin/sh
2. "${srcdir=.}/init.sh"; path_prepend_ . ../src
3
4# Test checking of Lisp format strings.
5
6cat <<\EOF > f-l-2.data
7# Valid: ~~ doesn't count
8msgid  "abc~~def"
9msgstr "xyz"
10# Invalid: invalid msgstr
11msgid  "abc~~def"
12msgstr "xyz~"
13# Valid: same argument
14msgid  "abc~Ddef"
15msgstr "xyz~D"
16# Valid: same arguments
17msgid  "abc~1000000@*~Ddef"
18msgstr "~1000000@*xyz~D"
19# Valid: permutation
20msgid  "abc~D~C~Fdef"
21msgstr "xyz~2@*~F~2:*~C~2:*~D"
22# Invalid: too few arguments
23msgid  "abc~1@*~Sdef~0@*~S"
24msgstr "xyz~S"
25# Invalid: too many arguments
26msgid  "abc~Ddef"
27msgstr "xyz~Duvw~C"
28# Invalid: missing non-final argument
29msgid  "abc~1@*~Sdef~0@*~F"
30msgstr "xyz~1@*~S"
31# Invalid: added non-final argument
32msgid  "abc~1@*~Ddef"
33msgstr "xyz~F~D"
34# Valid: formatting variations
35msgid  "abc~Sdef"
36msgstr "xyz~:S"
37# Valid: formatting variations
38msgid  "abc~4Sdef"
39msgstr "xyz~7S"
40# Valid: type compatibility
41msgid  "abc~Sdef"
42msgstr "xyz~W"
43# Valid: type compatibility
44msgid  "abc~Ddef"
45msgstr "xyz~B"
46# Valid: type compatibility
47msgid  "abc~Ddef"
48msgstr "xyz~O"
49# Valid: type compatibility
50msgid  "abc~Ddef"
51msgstr "xyz~X"
52# Valid: type compatibility
53msgid  "abc~Ddef"
54msgstr "xyz~R"
55# Valid: optional plural
56msgid  "~D egg~:P"
57msgstr "~D Eier"
58# Valid: type compatibility
59msgid  "abc~Fdef"
60msgstr "xyz~E"
61# Valid: type compatibility
62msgid  "abc~Fdef"
63msgstr "xyz~G"
64# Valid: type compatibility
65msgid  "abc~Fdef"
66msgstr "xyz~$"
67# Invalid: type incompatibility
68msgid  "abc~Fdef"
69msgstr "xyz~D"
70# Invalid: type incompatibility
71msgid  "abc~Ddef"
72msgstr "xyz~C"
73# Invalid: type incompatibility
74msgid  "abc~Fdef"
75msgstr "xyz~C"
76# Invalid: type incompatibility
77msgid  "abc~Sdef"
78msgstr "xyz~D"
79# Invalid: type incompatibility
80msgid  "abc~Sdef"
81msgstr "xyz~F"
82# Invalid: type incompatibility
83msgid  "abc~Sdef"
84msgstr "xyz~C"
85# Valid: extra formatting
86msgid  "abc~Ddef~S"
87msgstr "xyz~D~_def~%~S"
88# Valid: FORMAT-GOTO doesn't consume an argument by itself
89msgid  "abc~5@*~Ddef~C"
90msgstr "xyz~6@*~C~2@*uvw~5@*~R"
91# Invalid: @ matters
92msgid  "abc~?"
93msgstr "xyz~@?"
94# Valid: case conversion is optional
95msgid  "abc~(~S~)"
96msgstr "xyz~S"
97# Valid: case conversion is optional
98msgid  "abc~(~D~^ ~D~)"
99msgstr "xyz~D~^ ~D"
100# Invalid: ~^ matters
101msgid  "abc~(~D~^ ~D~)"
102msgstr "xyz~(~D ~D~)"
103# Valid: case conversion is optional, and it doesn't catch ~^
104msgid  "abc~(~D~^ ~D~)def~C"
105msgstr "xyz~D~^ ~Duvw~C"
106# Valid: synonymous conditionals
107msgid  "abc~@[~D~]def~C"
108msgstr "xyz~:[~;~:*~D~]~C"
109# Valid: synonymous conditionals
110msgid  "abc~Ddef"
111msgstr "abc~[null~;eins~:;~:*~D~]def"
112# Valid: conditionals are optional and don't catch ~^
113msgid  "abc~:[~;~]~^~D~C"
114msgstr "xyz~:[uvw~^~R~;~:*~S~^~D~]~C"
115# Invalid: ~:[ requires an argument, ~1@* doesn't
116msgid  "abc~1@*~^~D~C"
117msgstr "xyz~:[uvw~^~R~;~:*~S~^~D~]~C"
118# Invalid: ~{~} is special
119msgid  "abc~{ ~}"
120msgstr "xyz~{~}"
121# Invalid: @ matters
122msgid  "abc~{~S~}"
123msgstr "xyz~@{~S~}"
124# Invalid: @ matters
125msgid  "abc~:{~S~}"
126msgstr "xyz~@:{~S~}"
127# Invalid: : matters
128msgid  "abc~{~S~}"
129msgstr "xyz~:{~S~}"
130# Invalid: : matters
131msgid  "abc~@{~S~}"
132msgstr "xyz~@:{~S~}"
133# Invalid: @: matters
134msgid  "abc~{~S~}"
135msgstr "xyz~@:{~S~}"
136# Valid: permutation inside iteration
137msgid  "abc~{~D ~C~}"
138msgstr "xyz~{~1@*~C~2:*~D~1*~}"
139# Invalid: permutation inside iteration, but wrong position at iteration end
140msgid  "abc~{~D ~C~}"
141msgstr "xyz~{~1@*~C~2:*~D~}"
142# Invalid: ~^ inside iteration matters
143msgid  "abc~{~D ~^~C~}"
144msgstr "xyz~{~D ~C~}"
145# Invalid: ~^ inside iteration depends on position
146msgid  "abc~{~D ~^~C~}"
147msgstr "xyz~{~1@*~C~^~2:*~D~1*~}"
148# Invalid: ~^ inside iteration depends on position
149msgid  "abc~{~D ~^~C~}"
150msgstr "xyz~{~1@*~C~2:*~^~D~1*~}"
151# Invalid: ~^ inside iteration depends on position
152msgid  "abc~{~D ~^~C~}"
153msgstr "xyz~{~1@*~C~2:*~D~^~1*~}"
154# Invalid: ~^ inside iteration depends on position
155msgid  "abc~{~D ~^~C~}"
156msgstr "xyz~{~1@*~C~2:*~D~1*~^~}"
157# Valid: justification is optional
158msgid  "abc~<~D~;~C~>"
159msgstr "xyz~D~C"
160# Valid: justification with different segmentation
161msgid  "abc~<~D ~D~;~C~;~S~S~>"
162msgstr "xyz~<~D~;~D~C~S~;~S~>"
163# Invalid: justification catches ~^
164msgid  "abc~<~D~;~^~D~>~C"
165msgstr "abc~D~^~D~C"
166# Invalid: type compatibility with non-strict checking
167msgid "abc~{~c~c~}"
168msgid_plural "abc~{~c~c~}"
169msgstr[0] "xyz~{~c~d~}"
170msgstr[1] "xyz~{~c~d~}"
171EOF
172
173: ${MSGFMT=msgfmt}
174n=0
175while 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}
190EOF
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}
198EOF
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
221done < f-l-2.data
222
223Exit 0
224