summaryrefslogtreecommitdiffstats
path: root/gettext-tools/tests/format-javascript-1
blob: d53df2936fb5ff9ecc590f61467723a3449bc7a0 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
#! /bin/sh
. "${srcdir=.}/init.sh"; path_prepend_ . ../src

# Test recognition of JavaScript format strings.

cat <<\EOF > f-js-1.data
# Valid: no argument
"abc%%"
# Valid: one character argument
"abc%c"
# Valid: one string argument
"abc%s"
# Valid: one integer argument
"abc%b"
# Valid: one integer argument
"abc%d"
# Valid: one integer argument
"abc%o"
# Valid: one integer argument
"abc%x"
# Valid: one integer argument
"abc%X"
# Valid: one floating-point argument
"abc%f"
# Valid: one object argument
"abc%j"
# Valid: one argument with flags
"abc%Id"
# Valid: one argument with width
"abc%2d"
# Valid: one argument with precision
"abc%.4f"
# Valid: one argument with width and precision
"abc%14.4f"
# Invalid: unterminated
"abc%"
# Invalid: unknown format specifier
"abc%y"
# Invalid: flags after width
"abc%1Ig"
# Invalid: twice precision
"abc%.4.2f"
# Valid: three arguments
"abc%d%j%j"
EOF

: ${XGETTEXT=xgettext}
n=0
while read comment; do
  read string
  n=`expr $n + 1`
  cat <<EOF > f-js-1-$n.in
gettext(${string});
EOF
  # Hide xgettext's "The translator cannot reorder the arguments." warnings.
  ${XGETTEXT} -L JavaScript -o f-js-1-$n.po f-js-1-$n.in 2> f-js-1.err \
    || { cat f-js-1.err 1>&2; exit 1; }
  test -f f-js-1-$n.po || exit 1
  fail=
  if echo "$comment" | grep 'Valid:' > /dev/null; then
    if grep javascript-format f-js-1-$n.po > /dev/null; then
      :
    else
      fail=yes
    fi
  else
    if grep javascript-format f-js-1-$n.po > /dev/null; then
      fail=yes
    else
      :
    fi
  fi
  if test -n "$fail"; then
    echo "Format string recognition error:" 1>&2
    cat f-js-1-$n.in 1>&2
    echo "Got:" 1>&2
    cat f-js-1-$n.po 1>&2
    exit 1
  fi
  rm -f f-js-1-$n.in f-js-1-$n.po
done < f-js-1.data

exit 0