Imported Upstream version 0.19.7
[platform/upstream/gettext.git] / gettext-tools / tests / format-tcl-2
1 #! /bin/sh
2 . "${srcdir=.}/init.sh"; path_prepend_ . ../src
3
4 # Test checking of Tcl format strings.
5
6 cat <<\EOF > f-t-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 arguments
14 msgid  "abc%s%gdef"
15 msgstr "xyz%s%g"
16 # Valid: same arguments, with different widths
17 msgid  "abc%2sdef"
18 msgstr "xyz%3s"
19 # Valid: same arguments but in numbered syntax
20 msgid  "abc%s%gdef"
21 msgstr "xyz%1$s%2$g"
22 # Valid: permutation
23 msgid  "abc%s%g%cdef"
24 msgstr "xyz%3$c%2$g%1$s"
25 # Invalid: too few arguments
26 msgid  "abc%2$udef%1$s"
27 msgstr "xyz%1$s"
28 # Invalid: too few arguments
29 msgid  "abc%sdef%u"
30 msgstr "xyz%s"
31 # Invalid: too many arguments
32 msgid  "abc%udef"
33 msgstr "xyz%uvw%c"
34 # Valid: same numbered arguments, with different widths
35 msgid  "abc%2$5s%1$4s"
36 msgstr "xyz%2$4s%1$5s"
37 # Invalid: missing argument
38 msgid  "abc%2$sdef%1$u"
39 msgstr "xyz%1$u"
40 # Invalid: missing argument
41 msgid  "abc%1$sdef%2$u"
42 msgstr "xyz%2$u"
43 # Invalid: added argument
44 msgid  "abc%1$udef"
45 msgstr "xyz%1$uvw%2$c"
46 # Valid: type compatibility
47 msgid  "abc%i"
48 msgstr "xyz%d"
49 # Valid: type compatibility
50 msgid  "abc%o"
51 msgstr "xyz%u"
52 # Valid: type compatibility
53 msgid  "abc%u"
54 msgstr "xyz%x"
55 # Valid: type compatibility
56 msgid  "abc%u"
57 msgstr "xyz%X"
58 # Valid: type compatibility
59 msgid  "abc%e"
60 msgstr "xyz%E"
61 # Valid: type compatibility
62 msgid  "abc%e"
63 msgstr "xyz%f"
64 # Valid: type compatibility
65 msgid  "abc%e"
66 msgstr "xyz%g"
67 # Valid: type compatibility
68 msgid  "abc%e"
69 msgstr "xyz%G"
70 # Invalid: type incompatibility
71 msgid  "abc%c"
72 msgstr "xyz%s"
73 # Invalid: type incompatibility
74 msgid  "abc%c"
75 msgstr "xyz%i"
76 # Invalid: type incompatibility
77 msgid  "abc%c"
78 msgstr "xyz%o"
79 # Invalid: type incompatibility
80 msgid  "abc%c"
81 msgstr "xyz%e"
82 # Invalid: type incompatibility
83 msgid  "abc%s"
84 msgstr "xyz%i"
85 # Invalid: type incompatibility
86 msgid  "abc%s"
87 msgstr "xyz%o"
88 # Invalid: type incompatibility
89 msgid  "abc%s"
90 msgstr "xyz%e"
91 # Invalid: type incompatibility
92 msgid  "abc%i"
93 msgstr "xyz%o"
94 # Invalid: type incompatibility
95 msgid  "abc%i"
96 msgstr "xyz%e"
97 # Invalid: type incompatibility
98 msgid  "abc%u"
99 msgstr "xyz%e"
100 # Invalid: type incompatibility for width
101 msgid  "abc%g%*g"
102 msgstr "xyz%*g%g"
103 EOF
104
105 : ${MSGFMT=msgfmt}
106 n=0
107 while read comment; do
108   read msgid_line
109   read msgstr_line
110   n=`expr $n + 1`
111   cat <<EOF > f-t-2-$n.po
112 #, tcl-format
113 ${msgid_line}
114 ${msgstr_line}
115 EOF
116   fail=
117   if echo "$comment" | grep 'Valid:' > /dev/null; then
118     if ${MSGFMT} --check-format -o f-t-2-$n.mo f-t-2-$n.po; then
119       :
120     else
121       fail=yes
122     fi
123   else
124     ${MSGFMT} --check-format -o f-t-2-$n.mo f-t-2-$n.po 2> /dev/null
125     if test $? = 1; then
126       :
127     else
128       fail=yes
129     fi
130   fi
131   if test -n "$fail"; then
132     echo "Format string checking error:" 1>&2
133     cat f-t-2-$n.po 1>&2
134     exit 1
135   fi
136   rm -f f-t-2-$n.po f-t-2-$n.mo
137 done < f-t-2.data
138
139 exit 0