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