Imported Upstream version 0.18.3.2
[platform/upstream/gettext.git] / gettext-tools / tests / format-javascript-2
1 #! /bin/sh
2
3 # Test checking of JavaScript format strings.
4
5 tmpfiles=""
6 trap 'rm -fr $tmpfiles' 1 2 3 15
7
8 tmpfiles="$tmpfiles f-js-2.data"
9 cat <<\EOF > f-js-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%o"
27 msgstr "xyz%d"
28 # Valid: type compatibility
29 msgid  "abc%o"
30 msgstr "xyz%x"
31 # Valid: type compatibility
32 msgid  "abc%o"
33 msgstr "xyz%X"
34 # Valid: type compatibility
35 msgid  "abc%d"
36 msgstr "xyz%x"
37 # Valid: type compatibility
38 msgid  "abc%d"
39 msgstr "xyz%X"
40 # Invalid: type incompatibility
41 msgid  "abc%c"
42 msgstr "xyz%s"
43 # Invalid: type incompatibility
44 msgid  "abc%c"
45 msgstr "xyz%d"
46 # Invalid: type incompatibility
47 msgid  "abc%s"
48 msgstr "xyz%d"
49 EOF
50
51 : ${MSGFMT=msgfmt}
52 n=0
53 while read comment; do
54   read msgid_line
55   read msgstr_line
56   n=`expr $n + 1`
57   tmpfiles="$tmpfiles f-js-2-$n.po f-js-2-$n.mo"
58   cat <<EOF > f-js-2-$n.po
59 #, python-format
60 ${msgid_line}
61 ${msgstr_line}
62 EOF
63   fail=
64   if echo "$comment" | grep 'Valid:' > /dev/null; then
65     if ${MSGFMT} --check-format -o f-js-2-$n.mo f-js-2-$n.po; then
66       :
67     else
68       fail=yes
69     fi
70   else
71     ${MSGFMT} --check-format -o f-js-2-$n.mo f-js-2-$n.po 2> /dev/null
72     if test $? = 1; then
73       :
74     else
75       fail=yes
76     fi
77   fi
78   if test -n "$fail"; then
79     echo "Format string checking error:" 1>&2
80     cat f-js-2-$n.po 1>&2
81     exit 1
82   fi
83   rm -f f-js-2-$n.po f-js-2-$n.mo
84 done < f-js-2.data
85
86 rm -fr $tmpfiles
87
88 exit 0