summaryrefslogtreecommitdiffstats
path: root/gettext-tools/tests/format-javascript-1
blob: 0b8db0c9252bab6539d2c856e57a3a30ad992fe3 (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
84
85
86
87
88
89
90
91
92
93
94
95
96
97
#! /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"
# Valid: a numbered argument
"abc%1$d"
# Invalid: zero
"abc%0$d"
# Valid: two-digit numbered arguments
"abc%11$def%10$dgh%9$dij%8$dkl%7$dmn%6$dop%5$dqr%4$dst%3$duv%2$dwx%1$dyz"
# Invalid: unterminated number
"abc%1"
# Invalid: flags before number
"abc%+1$d"
# Invalid: mixing of numbered and unnumbered arguments
"abc%d%2$x"
# Valid: multiple uses of same argument
"abc%2$xdef%1$sghi%2$x"
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