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