• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1#! /bin/sh
2. "${srcdir=.}/init.sh"; path_prepend_ . ../src
3
4# Test recognition of JavaScript format strings.
5
6cat <<\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# Valid: a numbered argument
46"abc%1$d"
47# Invalid: zero
48"abc%0$d"
49# Valid: two-digit numbered arguments
50"abc%11$def%10$dgh%9$dij%8$dkl%7$dmn%6$dop%5$dqr%4$dst%3$duv%2$dwx%1$dyz"
51# Invalid: unterminated number
52"abc%1"
53# Invalid: flags before number
54"abc%+1$d"
55# Invalid: mixing of numbered and unnumbered arguments
56"abc%d%2$x"
57# Valid: multiple uses of same argument
58"abc%2$xdef%1$sghi%2$x"
59EOF
60
61: ${XGETTEXT=xgettext}
62n=0
63while read comment; do
64  read string
65  n=`expr $n + 1`
66  cat <<EOF > f-js-1-$n.in
67gettext(${string});
68EOF
69  # Hide xgettext's "The translator cannot reorder the arguments." warnings.
70  ${XGETTEXT} -L JavaScript -o f-js-1-$n.po f-js-1-$n.in 2> f-js-1.err \
71    || { cat f-js-1.err 1>&2; Exit 1; }
72  test -f f-js-1-$n.po || Exit 1
73  fail=
74  if echo "$comment" | grep 'Valid:' > /dev/null; then
75    if grep javascript-format f-js-1-$n.po > /dev/null; then
76      :
77    else
78      fail=yes
79    fi
80  else
81    if grep javascript-format f-js-1-$n.po > /dev/null; then
82      fail=yes
83    else
84      :
85    fi
86  fi
87  if test -n "$fail"; then
88    echo "Format string recognition error:" 1>&2
89    cat f-js-1-$n.in 1>&2
90    echo "Got:" 1>&2
91    cat f-js-1-$n.po 1>&2
92    Exit 1
93  fi
94  rm -f f-js-1-$n.in f-js-1-$n.po
95done < f-js-1.data
96
97Exit 0
98