1#! /bin/sh 2. "${srcdir=.}/init.sh"; path_prepend_ . ../src 3 4# Test checking of Ruby format strings. 5 6cat <<\EOF > f-r-2.data 7# Valid: %% doesn't count 8msgid "abc%%def" 9msgstr "xyz" 10# Invalid: invalid msgstr 11msgid "abc%%def" 12msgstr "xyz%" 13# Valid: same arguments, with different widths (argument list) 14msgid "abc%2sdef" 15msgstr "xyz%3s" 16# Valid: same arguments, with different widths (argument list) 17msgid "abc%2sdef" 18msgstr "xyz%1$3s" 19# Valid: same arguments, with different widths (named) 20msgid "abc%<foo>2sdef" 21msgstr "xyz%<foo>3s" 22# Valid: same arguments, with different widths (named) 23msgid "abc%<date>5s%<time>4s" 24msgstr "xyz%<date>4s%<time>5s" 25# Invalid: too few arguments (argument list) 26msgid "abc%sdef%u" 27msgstr "xyz%s" 28# Invalid: too few arguments (named) 29msgid "abc%<foo>sdef%<bar>u" 30msgstr "xyz%<foo>s" 31# Invalid: too many arguments (argument list) 32msgid "abc%udef" 33msgstr "xyz%uvw%c" 34# Invalid: too many arguments (named) 35msgid "abc%<foo>udef" 36msgstr "xyz%<foo>uvw%<bar>c" 37# Valid: permutation (argument list) 38msgid "abc%3$d%1$c%2$sdef" 39msgstr "xyz%2$s%1$c%3$d" 40# Valid: permutation (named) 41msgid "abc%<3>d%<1>c%<2>sdef" 42msgstr "xyz%<2>s%<1>c%<3>d" 43# Invalid: missing argument (named) 44msgid "abc%<2>sdef%<1>u" 45msgstr "xyz%<1>u" 46# Invalid: missing argument (named) 47msgid "abc%<1>sdef%<2>u" 48msgstr "xyz%<2>u" 49# Invalid: added argument (named) 50msgid "abc%<foo>udef" 51msgstr "xyz%<foo>uvw%<char>c" 52# Invalid: added argument (named) 53msgid "abc%<foo>udef" 54msgstr "xyz%<zoo>cvw%<foo>u" 55# Invalid: unnamed vs. named arguments 56msgid "abc%sdef" 57msgstr "xyz%<value>s" 58# Invalid: named vs. unnamed arguments 59msgid "abc%{value}def" 60msgstr "xyz%s" 61# Valid: unnumbered vs. numbered arguments 62msgid "abc%sdef%d" 63msgstr "xyz%2$duvw%1$s" 64# Valid: numbered vs. unnumbered arguments 65msgid "abc%1$sdef%2$d" 66msgstr "xyz%suvw%d" 67# Valid: type compatibility (argument list) 68msgid "abc%d" 69msgstr "xyz%i" 70# Valid: type compatibility (argument list) 71msgid "abc%d" 72msgstr "xyz%u" 73# Valid: type compatibility (argument list) 74msgid "abc%d" 75msgstr "xyz%o" 76# Valid: type compatibility (argument list) 77msgid "abc%d" 78msgstr "xyz%x" 79# Valid: type compatibility (argument list) 80msgid "abc%d" 81msgstr "xyz%X" 82# Valid: type compatibility (argument list) 83msgid "abc%d" 84msgstr "xyz%b" 85# Valid: type compatibility (argument list) 86msgid "abc%d" 87msgstr "xyz%B" 88# Valid: type compatibility (argument list) 89msgid "abc%i" 90msgstr "xyz%u" 91# Valid: type compatibility (argument list) 92msgid "abc%i" 93msgstr "xyz%o" 94# Valid: type compatibility (argument list) 95msgid "abc%i" 96msgstr "xyz%x" 97# Valid: type compatibility (argument list) 98msgid "abc%i" 99msgstr "xyz%X" 100# Valid: type compatibility (argument list) 101msgid "abc%i" 102msgstr "xyz%b" 103# Valid: type compatibility (argument list) 104msgid "abc%i" 105msgstr "xyz%B" 106# Valid: type compatibility (argument list) 107msgid "abc%u" 108msgstr "xyz%o" 109# Valid: type compatibility (argument list) 110msgid "abc%u" 111msgstr "xyz%x" 112# Valid: type compatibility (argument list) 113msgid "abc%u" 114msgstr "xyz%X" 115# Valid: type compatibility (argument list) 116msgid "abc%u" 117msgstr "xyz%b" 118# Valid: type compatibility (argument list) 119msgid "abc%u" 120msgstr "xyz%B" 121# Valid: type compatibility (argument list) 122msgid "abc%o" 123msgstr "xyz%x" 124# Valid: type compatibility (argument list) 125msgid "abc%o" 126msgstr "xyz%X" 127# Valid: type compatibility (argument list) 128msgid "abc%o" 129msgstr "xyz%b" 130# Valid: type compatibility (argument list) 131msgid "abc%o" 132msgstr "xyz%B" 133# Valid: type compatibility (argument list) 134msgid "abc%x" 135msgstr "xyz%X" 136# Valid: type compatibility (argument list) 137msgid "abc%x" 138msgstr "xyz%b" 139# Valid: type compatibility (argument list) 140msgid "abc%x" 141msgstr "xyz%B" 142# Valid: type compatibility (argument list) 143msgid "abc%X" 144msgstr "xyz%b" 145# Valid: type compatibility (argument list) 146msgid "abc%X" 147msgstr "xyz%B" 148# Valid: type compatibility (argument list) 149msgid "abc%b" 150msgstr "xyz%B" 151# Valid: type compatibility (argument list) 152msgid "abc%f" 153msgstr "xyz%g" 154# Valid: type compatibility (argument list) 155msgid "abc%f" 156msgstr "xyz%G" 157# Valid: type compatibility (argument list) 158msgid "abc%f" 159msgstr "xyz%e" 160# Valid: type compatibility (argument list) 161msgid "abc%f" 162msgstr "xyz%E" 163# Valid: type compatibility (argument list) 164msgid "abc%f" 165msgstr "xyz%a" 166# Valid: type compatibility (argument list) 167msgid "abc%f" 168msgstr "xyz%A" 169# Valid: type compatibility (argument list) 170msgid "abc%g" 171msgstr "xyz%G" 172# Valid: type compatibility (argument list) 173msgid "abc%g" 174msgstr "xyz%e" 175# Valid: type compatibility (argument list) 176msgid "abc%g" 177msgstr "xyz%E" 178# Valid: type compatibility (argument list) 179msgid "abc%g" 180msgstr "xyz%a" 181# Valid: type compatibility (argument list) 182msgid "abc%g" 183msgstr "xyz%A" 184# Valid: type compatibility (argument list) 185msgid "abc%G" 186msgstr "xyz%e" 187# Valid: type compatibility (argument list) 188msgid "abc%G" 189msgstr "xyz%E" 190# Valid: type compatibility (argument list) 191msgid "abc%G" 192msgstr "xyz%a" 193# Valid: type compatibility (argument list) 194msgid "abc%G" 195msgstr "xyz%A" 196# Valid: type compatibility (argument list) 197msgid "abc%e" 198msgstr "xyz%E" 199# Valid: type compatibility (argument list) 200msgid "abc%e" 201msgstr "xyz%a" 202# Valid: type compatibility (argument list) 203msgid "abc%e" 204msgstr "xyz%A" 205# Valid: type compatibility (argument list) 206msgid "abc%E" 207msgstr "xyz%a" 208# Valid: type compatibility (argument list) 209msgid "abc%E" 210msgstr "xyz%A" 211# Valid: type compatibility (argument list) 212msgid "abc%a" 213msgstr "xyz%A" 214# Valid: type compatibility (named) 215msgid "abc%<foo>d" 216msgstr "xyz%<foo>x" 217# Valid: type compatibility (named) 218msgid "abc%<foo>s" 219msgstr "xyz%{foo}" 220# Valid: type compatibility (named) 221msgid "abc%{foo}" 222msgstr "xyz%<foo>s" 223# Invalid: type incompatibility (argument list) 224msgid "abc%c" 225msgstr "xyz%s" 226# Invalid: type incompatibility (argument list) 227msgid "abc%c" 228msgstr "xyz%.0s" 229# Invalid: type incompatibility (argument list) 230msgid "abc%c" 231msgstr "xyz%p" 232# Invalid: type incompatibility (argument list) 233msgid "abc%c" 234msgstr "xyz%i" 235# Invalid: type incompatibility (argument list) 236msgid "abc%c" 237msgstr "xyz%e" 238# Invalid: type incompatibility (argument list) 239msgid "abc%s" 240msgstr "xyz%p" 241# Invalid: type incompatibility (argument list) 242msgid "abc%s" 243msgstr "xyz%i" 244# Invalid: type incompatibility (argument list) 245msgid "abc%.0s" 246msgstr "xyz%i" 247# Invalid: type incompatibility (argument list) 248msgid "abc%s" 249msgstr "xyz%e" 250# Invalid: type incompatibility (argument list) 251msgid "abc%.0s" 252msgstr "xyz%e" 253# Invalid: type incompatibility (argument list) 254msgid "abc%p" 255msgstr "xyz%i" 256# Invalid: type incompatibility (argument list) 257msgid "abc%p" 258msgstr "xyz%e" 259# Invalid: type incompatibility (argument list) 260msgid "abc%i" 261msgstr "xyz%e" 262# Invalid: type incompatibility (named) 263msgid "abc%<foo>c" 264msgstr "xyz%<foo>s" 265# Invalid: type incompatibility (named) 266msgid "abc%<foo>c" 267msgstr "xyz%{foo}" 268# Invalid: type incompatibility (named) 269msgid "abc%<foo>c" 270msgstr "xyz%<foo>.0s" 271# Invalid: type incompatibility (named) 272msgid "abc%<foo>c" 273msgstr "xyz%.0{foo}" 274# Invalid: type incompatibility (named) 275msgid "abc%<foo>c" 276msgstr "xyz%<foo>p" 277# Invalid: type incompatibility (named) 278msgid "abc%<foo>c" 279msgstr "xyz%<foo>i" 280# Invalid: type incompatibility (named) 281msgid "abc%<foo>c" 282msgstr "xyz%<foo>e" 283# Invalid: type incompatibility (named) 284msgid "abc%<foo>s" 285msgstr "xyz%<foo>p" 286# Invalid: type incompatibility (named) 287msgid "abc%{foo}" 288msgstr "xyz%<foo>p" 289# Invalid: type incompatibility (named) 290msgid "abc%<foo>s" 291msgstr "xyz%<foo>i" 292# Invalid: type incompatibility (named) 293msgid "abc%{foo}" 294msgstr "xyz%<foo>i" 295# Invalid: type incompatibility (named) 296msgid "abc%<foo>.0s" 297msgstr "xyz%<foo>i" 298# Invalid: type incompatibility (named) 299msgid "abc%.0{foo}" 300msgstr "xyz%<foo>i" 301# Invalid: type incompatibility (named) 302msgid "abc%<foo>s" 303msgstr "xyz%<foo>e" 304# Invalid: type incompatibility (named) 305msgid "abc%{foo}" 306msgstr "xyz%<foo>e" 307# Invalid: type incompatibility (named) 308msgid "abc%<foo>.0s" 309msgstr "xyz%<foo>e" 310# Invalid: type incompatibility (named) 311msgid "abc%.0{foo}" 312msgstr "xyz%<foo>e" 313# Invalid: type incompatibility (named) 314msgid "abc%<foo>p" 315msgstr "xyz%<foo>i" 316# Invalid: type incompatibility (named) 317msgid "abc%<foo>p" 318msgstr "xyz%<foo>e" 319# Invalid: type incompatibility (named) 320msgid "abc%<foo>i" 321msgstr "xyz%<foo>e" 322# Invalid: type incompatibility for width (argument list) 323msgid "abc%g%*g" 324msgstr "xyz%*g%g" 325EOF 326 327: ${MSGFMT=msgfmt} 328n=0 329while read comment; do 330 read msgid_line 331 read msgstr_line 332 n=`expr $n + 1` 333 cat <<EOF > f-r-2-$n.po 334#, ruby-format 335${msgid_line} 336${msgstr_line} 337EOF 338 fail= 339 if echo "$comment" | grep 'Valid:' > /dev/null; then 340 if ${MSGFMT} --check-format -o f-r-2-$n.mo f-r-2-$n.po; then 341 : 342 else 343 fail=yes 344 fi 345 else 346 ${MSGFMT} --check-format -o f-r-2-$n.mo f-r-2-$n.po 2> /dev/null 347 if test $? = 1; then 348 : 349 else 350 fail=yes 351 fi 352 fi 353 if test -n "$fail"; then 354 echo "Format string checking error:" 1>&2 355 cat f-r-2-$n.po 1>&2 356 Exit 1 357 fi 358 rm -f f-r-2-$n.po f-r-2-$n.mo 359done < f-r-2.data 360 361Exit 0 362