gettext/gettext-tools/tests/xgettext-java-1
Bruno Haible 7546f94840 xgettext: Java: Remove unjustified warning "'}' found where ')' was expected".
Reported by Alexander Hubmann-Haidvogel <ahubmann@gmail.com> in
<https://lists.gnu.org/archive/html/bug-gettext/2025-09/msg00000.html>
and by Bjoern Voigt <bjoernv@arcor.de> in
<https://lists.gnu.org/archive/html/bug-gettext/2025-09/msg00023.html>.

* gettext-tools/src/x-java.c (extract_parenthesized): When a semicolon is seen
inside braces, start a new argparser instead of returning.
* gettext-tools/tests/xgettext-java-1: Add test cases with inner classes.
2025-10-01 00:04:45 +02:00

82 lines
1.7 KiB
Bash
Executable File

#!/bin/sh
. "${srcdir=.}/init.sh"; path_prepend_ . ../src
#
# Some tests for java support
#
cat <<\EOF > xg-j-1.java
class TestCase {
public TestCase() {
ResourceBundle b = ResourceBundle.getBundle("test");
GetTextBundle b2 = (GetTextBundle)b;
// standard usage
String test1 = b.getString("Test String 1");
// gettext usage
String test2 = b2.gettext("Test String 2");
/* C style comment */
String test3 = b.getString("Test String 3");
// java "multiline" string
String test4 = b.getString("Test " +
"String " +
"4");
// empty string
String test5 = b.getString("");
// An inner class.
addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent e) {
System.out.println(translate("Click!"));
}
});
// An anonymous inner class (Java 8 or newer).
Collections.emptySet().stream().filter(item -> {
return item != null;
});
}
}
}
EOF
: ${XGETTEXT=xgettext}
${XGETTEXT} --omit-header --no-location -c -d xg-j-1.tmp xg-j-1.java 2>xg-j-1.tmq || Exit 1
grep -v '^==' xg-j-1.tmq > xg-j-1.err
# Expect no warning here.
if test -s xg-j-1.err; then
cat xg-j-1.err
Exit 1
fi
LC_ALL=C tr -d '\r' < xg-j-1.tmp.po > xg-j-1.po || Exit 1
cat <<\EOF > xg-j-1.ok
#. standard usage
msgid "Test String 1"
msgstr ""
#. gettext usage
msgid "Test String 2"
msgstr ""
#. C style comment
msgid "Test String 3"
msgstr ""
#. java "multiline" string
msgid "Test String 4"
msgstr ""
#. empty string
msgid ""
msgstr ""
EOF
: ${DIFF=diff}
${DIFF} xg-j-1.ok xg-j-1.po
result=$?
exit $result