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