Imported Upstream version 0.18.3.2
[platform/upstream/gettext.git] / gettext-tools / tests / format-javascript-1
1 #! /bin/sh
2
3 # Test recognition of JavaScript format strings.
4
5 tmpfiles=""
6 trap 'rm -fr $tmpfiles' 1 2 3 15
7
8 tmpfiles="$tmpfiles f-js-1.data"
9 cat <<\EOF > f-js-1.data
10 # Valid: no argument
11 "abc%%"
12 # Valid: one character argument
13 "abc%c"
14 # Valid: one string argument
15 "abc%s"
16 # Valid: one integer argument
17 "abc%b"
18 # Valid: one integer argument
19 "abc%d"
20 # Valid: one integer argument
21 "abc%o"
22 # Valid: one integer argument
23 "abc%x"
24 # Valid: one integer argument
25 "abc%X"
26 # Valid: one floating-point argument
27 "abc%f"
28 # Valid: one object argument
29 "abc%j"
30 # Valid: one argument with flags
31 "abc%Id"
32 # Valid: one argument with width
33 "abc%2d"
34 # Valid: one argument with precision
35 "abc%.4f"
36 # Valid: one argument with width and precision
37 "abc%14.4f"
38 # Invalid: unterminated
39 "abc%"
40 # Invalid: unknown format specifier
41 "abc%y"
42 # Invalid: flags after width
43 "abc%1Ig"
44 # Invalid: twice precision
45 "abc%.4.2f"
46 # Valid: three arguments
47 "abc%d%j%j"
48 EOF
49
50 tmpfiles="$tmpfiles f-js-1.err"
51 : ${XGETTEXT=xgettext}
52 n=0
53 while read comment; do
54   read string
55   n=`expr $n + 1`
56   tmpfiles="$tmpfiles f-js-1-$n.in f-js-1-$n.po"
57   cat <<EOF > f-js-1-$n.in
58 gettext(${string});
59 EOF
60   # Hide xgettext's "The translator cannot reorder the arguments." warnings.
61   ${XGETTEXT} -L JavaScript -o f-js-1-$n.po f-js-1-$n.in 2> f-js-1.err \
62     || { cat f-js-1.err 1>&2; exit 1; }
63   test -f f-js-1-$n.po || exit 1
64   fail=
65   if echo "$comment" | grep 'Valid:' > /dev/null; then
66     if grep javascript-format f-js-1-$n.po > /dev/null; then
67       :
68     else
69       fail=yes
70     fi
71   else
72     if grep javascript-format f-js-1-$n.po > /dev/null; then
73       fail=yes
74     else
75       :
76     fi
77   fi
78   if test -n "$fail"; then
79     echo "Format string recognition error:" 1>&2
80     cat f-js-1-$n.in 1>&2
81     echo "Got:" 1>&2
82     cat f-js-1-$n.po 1>&2
83     exit 1
84   fi
85   rm -f f-js-1-$n.in f-js-1-$n.po
86 done < f-js-1.data
87
88 rm -fr $tmpfiles
89
90 exit 0