1#! /bin/sh
2
3# Test recognition of Emacs Lisp format strings.
4
5tmpfiles=""
6trap 'rm -fr $tmpfiles' 1 2 3 15
7
8tmpfiles="$tmpfiles f-el-1.data"
9cat <<\EOF > f-el-1.data
10# Valid: no argument
11"abc%%"
12# Valid: one character argument
13"abc%c"
14# Valid: one integer argument
15"abc%d"
16# Valid: one integer argument
17"abc%x"
18# Valid: one integer argument
19"abc%X"
20# Valid: one integer argument
21"abc%o"
22# Valid: one floating-point argument
23"abc%e"
24# Valid: one floating-point argument
25"abc%E"
26# Valid: one floating-point argument
27"abc%f"
28# Valid: one floating-point argument
29"abc%g"
30# Valid: one floating-point argument
31"abc%G"
32# Valid: one object argument
33"abc%s"
34# Valid: one object argument
35"abc%S"
36# Valid: one argument with flags
37"abc%0#g"
38# Valid: one argument with width
39"abc%2g"
40# Valid: one argument with width
41"abc%*g"
42# Valid: one argument with precision
43"abc%.4g"
44# Valid: one argument with precision
45"abc%.*g"
46# Valid: one argument with width and precision
47"abc%14.4g"
48# Valid: one argument with width and precision
49"abc%14.*g"
50# Valid: one argument with width and precision
51"abc%*.4g"
52# Valid: one argument with width and precision
53"abc%*.*g"
54# Invalid: unterminated
55"abc%"
56# Invalid: unknown format specifier
57"abc%y"
58# Invalid: flags after width
59"abc%2^d"
60# Invalid: twice precision
61"abc%.4.2d"
62# Valid: three arguments
63"abc%d%x%x"
64# Valid: a numbered argument
65"abc%1$d"
66# Invalid: zero
67"abc%0$d"
68# Valid: two-digit numbered arguments
69"abc%11$def%10$dgh%9$dij%8$dkl%7$dmn%6$dop%5$dqr%4$dst%3$duv%2$dwx%1$dyz"
70# Invalid: unterminated number
71"abc%1"
72# Invalid: flags before number
73"abc%^1$d"
74# Valid: three arguments, two with same number
75"abc%1$4x,%2$c,%1$X"
76# Invalid: argument with conflicting types
77"abc%1$4x,%2$c,%1$s"
78# Valid: no conflict
79"abc%1$4x,%2$c,%1$d"
80# Valid: mixing of numbered and unnumbered arguments
81"abc%d%2$x"
82# Valid: mixing of numbered and unnumbered arguments
83"abc%5$d%x"
84# Valid: numbered argument with constant precision
85"abc%1$.9x"
86# Valid: missing non-final argument
87"abc%2$x%3$s"
88# Valid: permutation
89"abc%2$ddef%1$d"
90# Valid: multiple uses of same argument
91"abc%2$xdef%1$Sghi%2$x"
92# Valid: one argument with width
93"abc%2$#*g"
94# Valid: one argument with width and precision
95"abc%3$*.*g"
96# Invalid: zero
97"abc%0$*.*g"
98EOF
99
100: ${XGETTEXT=xgettext}
101n=0
102while read comment; do
103  read string
104  n=`expr $n + 1`
105  tmpfiles="$tmpfiles f-el-1-$n.in f-el-1-$n.po"
106  cat <<EOF > f-el-1-$n.in
107(_ ${string});
108EOF
109  ${XGETTEXT} -L EmacsLisp -o f-el-1-$n.po f-el-1-$n.in || exit 1
110  test -f f-el-1-$n.po || exit 1
111  fail=
112  if echo "$comment" | grep 'Valid:' > /dev/null; then
113    if grep elisp-format f-el-1-$n.po > /dev/null; then
114      :
115    else
116      fail=yes
117    fi
118  else
119    if grep elisp-format f-el-1-$n.po > /dev/null; then
120      fail=yes
121    else
122      :
123    fi
124  fi
125  if test -n "$fail"; then
126    echo "Format string recognition error:" 1>&2
127    cat f-el-1-$n.in 1>&2
128    echo "Got:" 1>&2
129    cat f-el-1-$n.po 1>&2
130    exit 1
131  fi
132  rm -f f-el-1-$n.in f-el-1-$n.po
133done < f-el-1.data
134
135rm -fr $tmpfiles
136
137exit 0
138