#! /bin/sh
. "${srcdir=.}/init.sh"; path_prepend_ . ../src

# Test --for-msgfmt option.

cat <<\EOF > mm-test13.in1
#: fruits.c:14
msgid "cherry"
msgstr "cerise"

#: fruits.c:17
msgid "pear"
msgstr "poire"

#: fruits.c:19
msgid "orange"
msgstr ""

#, fuzzy
#: fruits.c:20
msgid "apple"
msgstr "pommes"
EOF

cat <<\EOF > mm-test13.in2
# Fuzzy already in the PO file.
#: fruits.c:10
msgid "apple"
msgstr ""

# Fuzzy match to fuzzy already in the PO file.
#: fruits.c:11
msgid "apples"
msgstr ""

# Translated.
#: fruits.c:16
msgid "pear"
msgstr ""

# Fuzzy match.
#: fruits.c:17
msgid "pears"
msgstr ""

# Untranslated, in the PO file.
#: fruits.c:18
msgid "orange"
msgstr ""

# Untranslated, not in the PO file.
#: fruits.c:20
msgid "banana"
msgstr ""

# Translated already in the POT file.
#: fruits.c:25
msgid "papaya"
msgstr "Papaya"
EOF

: ${MSGMERGE=msgmerge}
${MSGMERGE} --for-msgfmt -o mm-test13.tmp mm-test13.in1 mm-test13.in2 \
    || Exit 1
LC_ALL=C tr -d '\r' < mm-test13.tmp > mm-test13.out || Exit 1

cat << EOF > mm-test13.ok
msgid "pear"
msgstr "poire"

msgid "papaya"
msgstr "Papaya"
EOF

: ${DIFF=diff}
${DIFF} mm-test13.ok mm-test13.out || Exit 1

# Test with a PO file that has no translated messages.

cat <<\EOF > mm-test13a.in1
msgid ""
msgstr ""
"Content-Type: text/plain; charset=UTF-8\n"

msgid "Hello world"
msgstr "Hallo Welt"
EOF

cat <<\EOF > mm-test13a.in2
msgid ""
msgstr ""
"Content-Type: text/plain; charset=ASCII\n"

msgid "Hello, world!"
msgstr ""
EOF

: ${MSGMERGE=msgmerge}
${MSGMERGE} --for-msgfmt -o mm-test13a.tmp mm-test13a.in1 mm-test13a.in2 \
    || Exit 1
LC_ALL=C tr -d '\r' < mm-test13a.tmp > mm-test13a.out || Exit 1

cat <<\EOF > mm-test13a.ok
msgid ""
msgstr "Content-Type: text/plain; charset=UTF-8\n"
EOF

: ${DIFF=diff}
${DIFF} mm-test13a.ok mm-test13a.out || Exit 1
