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