Blame gettext-tools/tests/format-tcl-2

Packit Bot 06c835
#! /bin/sh
Packit Bot 06c835
. "${srcdir=.}/init.sh"; path_prepend_ . ../src
Packit Bot 06c835
Packit Bot 06c835
# Test checking of Tcl format strings.
Packit Bot 06c835
Packit Bot 06c835
cat <<\EOF > f-t-2.data
Packit Bot 06c835
# Valid: %% doesn't count
Packit Bot 06c835
msgid  "abc%%def"
Packit Bot 06c835
msgstr "xyz"
Packit Bot 06c835
# Invalid: invalid msgstr
Packit Bot 06c835
msgid  "abc%%def"
Packit Bot 06c835
msgstr "xyz%"
Packit Bot 06c835
# Valid: same arguments
Packit Bot 06c835
msgid  "abc%s%gdef"
Packit Bot 06c835
msgstr "xyz%s%g"
Packit Bot 06c835
# Valid: same arguments, with different widths
Packit Bot 06c835
msgid  "abc%2sdef"
Packit Bot 06c835
msgstr "xyz%3s"
Packit Bot 06c835
# Valid: same arguments but in numbered syntax
Packit Bot 06c835
msgid  "abc%s%gdef"
Packit Bot 06c835
msgstr "xyz%1$s%2$g"
Packit Bot 06c835
# Valid: permutation
Packit Bot 06c835
msgid  "abc%s%g%cdef"
Packit Bot 06c835
msgstr "xyz%3$c%2$g%1$s"
Packit Bot 06c835
# Invalid: too few arguments
Packit Bot 06c835
msgid  "abc%2$udef%1$s"
Packit Bot 06c835
msgstr "xyz%1$s"
Packit Bot 06c835
# Invalid: too few arguments
Packit Bot 06c835
msgid  "abc%sdef%u"
Packit Bot 06c835
msgstr "xyz%s"
Packit Bot 06c835
# Invalid: too many arguments
Packit Bot 06c835
msgid  "abc%udef"
Packit Bot 06c835
msgstr "xyz%uvw%c"
Packit Bot 06c835
# Valid: same numbered arguments, with different widths
Packit Bot 06c835
msgid  "abc%2$5s%1$4s"
Packit Bot 06c835
msgstr "xyz%2$4s%1$5s"
Packit Bot 06c835
# Invalid: missing argument
Packit Bot 06c835
msgid  "abc%2$sdef%1$u"
Packit Bot 06c835
msgstr "xyz%1$u"
Packit Bot 06c835
# Invalid: missing argument
Packit Bot 06c835
msgid  "abc%1$sdef%2$u"
Packit Bot 06c835
msgstr "xyz%2$u"
Packit Bot 06c835
# Invalid: added argument
Packit Bot 06c835
msgid  "abc%1$udef"
Packit Bot 06c835
msgstr "xyz%1$uvw%2$c"
Packit Bot 06c835
# Valid: type compatibility
Packit Bot 06c835
msgid  "abc%i"
Packit Bot 06c835
msgstr "xyz%d"
Packit Bot 06c835
# Valid: type compatibility
Packit Bot 06c835
msgid  "abc%o"
Packit Bot 06c835
msgstr "xyz%u"
Packit Bot 06c835
# Valid: type compatibility
Packit Bot 06c835
msgid  "abc%u"
Packit Bot 06c835
msgstr "xyz%x"
Packit Bot 06c835
# Valid: type compatibility
Packit Bot 06c835
msgid  "abc%u"
Packit Bot 06c835
msgstr "xyz%X"
Packit Bot 06c835
# Valid: type compatibility
Packit Bot 06c835
msgid  "abc%e"
Packit Bot 06c835
msgstr "xyz%E"
Packit Bot 06c835
# Valid: type compatibility
Packit Bot 06c835
msgid  "abc%e"
Packit Bot 06c835
msgstr "xyz%f"
Packit Bot 06c835
# Valid: type compatibility
Packit Bot 06c835
msgid  "abc%e"
Packit Bot 06c835
msgstr "xyz%g"
Packit Bot 06c835
# Valid: type compatibility
Packit Bot 06c835
msgid  "abc%e"
Packit Bot 06c835
msgstr "xyz%G"
Packit Bot 06c835
# Invalid: type incompatibility
Packit Bot 06c835
msgid  "abc%c"
Packit Bot 06c835
msgstr "xyz%s"
Packit Bot 06c835
# Invalid: type incompatibility
Packit Bot 06c835
msgid  "abc%c"
Packit Bot 06c835
msgstr "xyz%i"
Packit Bot 06c835
# Invalid: type incompatibility
Packit Bot 06c835
msgid  "abc%c"
Packit Bot 06c835
msgstr "xyz%o"
Packit Bot 06c835
# Invalid: type incompatibility
Packit Bot 06c835
msgid  "abc%c"
Packit Bot 06c835
msgstr "xyz%e"
Packit Bot 06c835
# Invalid: type incompatibility
Packit Bot 06c835
msgid  "abc%s"
Packit Bot 06c835
msgstr "xyz%i"
Packit Bot 06c835
# Invalid: type incompatibility
Packit Bot 06c835
msgid  "abc%s"
Packit Bot 06c835
msgstr "xyz%o"
Packit Bot 06c835
# Invalid: type incompatibility
Packit Bot 06c835
msgid  "abc%s"
Packit Bot 06c835
msgstr "xyz%e"
Packit Bot 06c835
# Invalid: type incompatibility
Packit Bot 06c835
msgid  "abc%i"
Packit Bot 06c835
msgstr "xyz%o"
Packit Bot 06c835
# Invalid: type incompatibility
Packit Bot 06c835
msgid  "abc%i"
Packit Bot 06c835
msgstr "xyz%e"
Packit Bot 06c835
# Invalid: type incompatibility
Packit Bot 06c835
msgid  "abc%u"
Packit Bot 06c835
msgstr "xyz%e"
Packit Bot 06c835
# Invalid: type incompatibility for width
Packit Bot 06c835
msgid  "abc%g%*g"
Packit Bot 06c835
msgstr "xyz%*g%g"
Packit Bot 06c835
EOF
Packit Bot 06c835
Packit Bot 06c835
: ${MSGFMT=msgfmt}
Packit Bot 06c835
n=0
Packit Bot 06c835
while read comment; do
Packit Bot 06c835
  read msgid_line
Packit Bot 06c835
  read msgstr_line
Packit Bot 06c835
  n=`expr $n + 1`
Packit Bot 06c835
  cat <<EOF > f-t-2-$n.po
Packit Bot 06c835
#, tcl-format
Packit Bot 06c835
${msgid_line}
Packit Bot 06c835
${msgstr_line}
Packit Bot 06c835
EOF
Packit Bot 06c835
  fail=
Packit Bot 06c835
  if echo "$comment" | grep 'Valid:' > /dev/null; then
Packit Bot 06c835
    if ${MSGFMT} --check-format -o f-t-2-$n.mo f-t-2-$n.po; then
Packit Bot 06c835
      :
Packit Bot 06c835
    else
Packit Bot 06c835
      fail=yes
Packit Bot 06c835
    fi
Packit Bot 06c835
  else
Packit Bot 06c835
    ${MSGFMT} --check-format -o f-t-2-$n.mo f-t-2-$n.po 2> /dev/null
Packit Bot 06c835
    if test $? = 1; then
Packit Bot 06c835
      :
Packit Bot 06c835
    else
Packit Bot 06c835
      fail=yes
Packit Bot 06c835
    fi
Packit Bot 06c835
  fi
Packit Bot 06c835
  if test -n "$fail"; then
Packit Bot 06c835
    echo "Format string checking error:" 1>&2
Packit Bot 06c835
    cat f-t-2-$n.po 1>&2
Packit Bot 06c835
    exit 1
Packit Bot 06c835
  fi
Packit Bot 06c835
  rm -f f-t-2-$n.po f-t-2-$n.mo
Packit Bot 06c835
done < f-t-2.data
Packit Bot 06c835
Packit Bot 06c835
exit 0