From: Bruno Haible Date: Wed, 11 Sep 2024 12:20:57 +0000 (+0200) Subject: tests: Add xgettext tests regarding string concatenation. X-Git-Tag: v0.23~135 X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=71de71cc5477c11a02c0ddb780a94ebb1dc710a6;p=thirdparty%2Fgettext.git tests: Add xgettext tests regarding string concatenation. * gettext-tools/tests/xgettext-sh-1: Add string concatenation tests. * gettext-tools/tests/xgettext-lua-1: Add a string concatenation test. * gettext-tools/tests/xgettext-vala-1: Likewise. * gettext-tools/tests/xgettext-javascript-3: Enhance the string concatenation test. * gettext-tools/tests/xgettext-csharp-5: Update comment. * gettext-tools/tests/xgettext-csharp-6: Likewise. * gettext-tools/tests/xgettext-java-5: Likewise. * gettext-tools/tests/xgettext-java-6: Likewise. * gettext-tools/tests/xgettext-lua-2: Likewise. * gettext-tools/tests/xgettext-perl-7: Likewise. * gettext-tools/tests/xgettext-php-3: Likewise. * gettext-tools/tests/xgettext-python-1: Likewise. * gettext-tools/tests/xgettext-python-2: Likewise. * gettext-tools/tests/xgettext-python-4: Likewise. * gettext-tools/tests/xgettext-ruby-1: Likewise. * gettext-tools/tests/xgettext-sh-5: Likewise. * gettext-tools/tests/xgettext-ruby-2: New file, based on gettext-tools/tests/xgettext-csharp-6. * gettext-tools/tests/Makefile.am (TESTS): Add it. --- diff --git a/gettext-tools/tests/Makefile.am b/gettext-tools/tests/Makefile.am index c27d4b390..d71b797ea 100644 --- a/gettext-tools/tests/Makefile.am +++ b/gettext-tools/tests/Makefile.am @@ -151,7 +151,7 @@ TESTS = gettext-1 gettext-2 \ xgettext-python-7 xgettext-python-8 \ xgettext-python-stackovfl-1 xgettext-python-stackovfl-2 \ xgettext-python-stackovfl-3 xgettext-python-stackovfl-4 \ - xgettext-ruby-1 \ + xgettext-ruby-1 xgettext-ruby-2 \ xgettext-scheme-1 xgettext-scheme-2 xgettext-scheme-3 \ xgettext-scheme-4 xgettext-scheme-5 xgettext-scheme-6 \ xgettext-scheme-7 xgettext-scheme-8 \ diff --git a/gettext-tools/tests/xgettext-csharp-5 b/gettext-tools/tests/xgettext-csharp-5 index a3fd3ec44..0fcb5224b 100755 --- a/gettext-tools/tests/xgettext-csharp-5 +++ b/gettext-tools/tests/xgettext-csharp-5 @@ -1,7 +1,7 @@ #!/bin/sh . "${srcdir=.}/init.sh"; path_prepend_ . ../src -# Test C# support: --add-comments option. +# Test C# support: --add-comments option, string concatenation. cat <<\EOF > xg-cs-5.cs // This comment will not be extracted. diff --git a/gettext-tools/tests/xgettext-csharp-6 b/gettext-tools/tests/xgettext-csharp-6 index 84dc210cf..440b1da9d 100755 --- a/gettext-tools/tests/xgettext-csharp-6 +++ b/gettext-tools/tests/xgettext-csharp-6 @@ -1,7 +1,7 @@ #!/bin/sh . "${srcdir=.}/init.sh"; path_prepend_ . ../src -# Test C# support: --add-comments option. +# Test C# support: --add-comments option, string concatenation. cat <<\EOF > xg-cs-6.cs /* a */ diff --git a/gettext-tools/tests/xgettext-java-5 b/gettext-tools/tests/xgettext-java-5 index c7240f2c1..704c617bf 100755 --- a/gettext-tools/tests/xgettext-java-5 +++ b/gettext-tools/tests/xgettext-java-5 @@ -1,7 +1,7 @@ #!/bin/sh . "${srcdir=.}/init.sh"; path_prepend_ . ../src -# Test Java support: --add-comments option. +# Test Java support: --add-comments option, string concatenation. cat <<\EOF > xg-j-5.java // This comment will not be extracted. diff --git a/gettext-tools/tests/xgettext-java-6 b/gettext-tools/tests/xgettext-java-6 index 47d7de3ae..35ae948d4 100755 --- a/gettext-tools/tests/xgettext-java-6 +++ b/gettext-tools/tests/xgettext-java-6 @@ -1,7 +1,7 @@ #!/bin/sh . "${srcdir=.}/init.sh"; path_prepend_ . ../src -# Test Java support: --add-comments option. +# Test Java support: --add-comments option, string concatenation. cat <<\EOF > xg-j-6.java /* a */ diff --git a/gettext-tools/tests/xgettext-javascript-3 b/gettext-tools/tests/xgettext-javascript-3 index 313cff041..d93e93525 100755 --- a/gettext-tools/tests/xgettext-javascript-3 +++ b/gettext-tools/tests/xgettext-javascript-3 @@ -1,20 +1,23 @@ #!/bin/sh . "${srcdir=.}/init.sh"; path_prepend_ . ../src -# Test of JavaScript support. -# Playing with concatenation of string literals within the gettext function +# Test of JavaScript support: string concatenation. +# Playing with concatenation of string literals within the gettext arguments. cat <<\EOF > xg-js-3.js // The usual way to concatenate strings is the plus '+' sign +var s0; var s1 = _("Concatenation #1 " + "- String part added"); var s2 = _('Concatenation #2 ' + '- String part added'); -var s3 = _("This" + " whole " - + "string" + +// a +var s3 = // b + _("This" + " whole " // c + + "string" + // d ' should' + " be " + 'extracted'); EOF : ${XGETTEXT=xgettext} -${XGETTEXT} --add-comments=TRANSLATORS: --no-location -o xg-js-3.tmp xg-js-3.js 2>xg-js-3.err +${XGETTEXT} --add-comments --no-location -o xg-js-3.tmp xg-js-3.js 2>xg-js-3.err test $? = 0 || { cat xg-js-3.err; Exit 1; } func_filter_POT_Creation_Date xg-js-3.tmp xg-js-3.pot @@ -43,6 +46,8 @@ msgstr "" msgid "Concatenation #2 - String part added" msgstr "" +#. a +#. b msgid "This whole string should be extracted" msgstr "" EOF diff --git a/gettext-tools/tests/xgettext-lua-1 b/gettext-tools/tests/xgettext-lua-1 index 270d7e224..a6009ef1c 100755 --- a/gettext-tools/tests/xgettext-lua-1 +++ b/gettext-tools/tests/xgettext-lua-1 @@ -29,7 +29,11 @@ print(_["nope"]) print(_("\097")) print(_("\x3F\z \x2a")) +-- String concatenation in regular contexts. print(_("abc" .. "def")) +-- String concatenation *not* happening when the parentheses are omitted. +print(_"hello" " world") + print(speed / 1000 .. 'Mbps') EOF @@ -93,6 +97,9 @@ msgstr "" msgid "abcdef" msgstr "" + +msgid "hello" +msgstr "" EOF : ${DIFF=diff} diff --git a/gettext-tools/tests/xgettext-lua-2 b/gettext-tools/tests/xgettext-lua-2 index df82135ef..b5bb5ed84 100755 --- a/gettext-tools/tests/xgettext-lua-2 +++ b/gettext-tools/tests/xgettext-lua-2 @@ -1,7 +1,7 @@ #!/bin/sh . "${srcdir=.}/init.sh"; path_prepend_ . ../src -# Test Lua comment syntax +# Test Lua support: comment syntax, string concatenation cat <<\EOF > xg-lu-2.lua -- This comment won't be extracted. diff --git a/gettext-tools/tests/xgettext-perl-7 b/gettext-tools/tests/xgettext-perl-7 index fafbef260..88835a7ed 100755 --- a/gettext-tools/tests/xgettext-perl-7 +++ b/gettext-tools/tests/xgettext-perl-7 @@ -1,7 +1,7 @@ #!/bin/sh . "${srcdir=.}/init.sh"; path_prepend_ . ../src -# Test Perl support: --add-comments option. +# Test Perl support: --add-comments option, string concatenation. cat <<\EOF > xg-pl-7.pl # a diff --git a/gettext-tools/tests/xgettext-php-3 b/gettext-tools/tests/xgettext-php-3 index 127d3c640..cdc6bf52b 100755 --- a/gettext-tools/tests/xgettext-php-3 +++ b/gettext-tools/tests/xgettext-php-3 @@ -1,7 +1,7 @@ #!/bin/sh . "${srcdir=.}/init.sh"; path_prepend_ . ../src -# Test PHP support: --add-comments option. +# Test PHP support: --add-comments option, string concatenation. cat <<\EOF > xg-ph-3.php xg-py-1.py # interpret_ansic = true, interpret_unicode = false, f_string = false diff --git a/gettext-tools/tests/xgettext-python-2 b/gettext-tools/tests/xgettext-python-2 index 5aec46a50..35b38ca0f 100755 --- a/gettext-tools/tests/xgettext-python-2 +++ b/gettext-tools/tests/xgettext-python-2 @@ -1,7 +1,7 @@ #!/bin/sh . "${srcdir=.}/init.sh"; path_prepend_ . ../src -# Test Python support: --add-comments option. +# Test Python support: --add-comments option, string concatenation. cat <<\EOF > xg-py-2.py # This comment will not be extracted. diff --git a/gettext-tools/tests/xgettext-python-4 b/gettext-tools/tests/xgettext-python-4 index f0599bb5f..798336ed7 100755 --- a/gettext-tools/tests/xgettext-python-4 +++ b/gettext-tools/tests/xgettext-python-4 @@ -1,7 +1,7 @@ #!/bin/sh . "${srcdir=.}/init.sh"; path_prepend_ . ../src -# Test Python support: --add-comments option. +# Test Python support: --add-comments option, string concatenation. cat <<\EOF > xg-py-4.py # a diff --git a/gettext-tools/tests/xgettext-ruby-1 b/gettext-tools/tests/xgettext-ruby-1 index dd8e68b27..9b41a94fd 100755 --- a/gettext-tools/tests/xgettext-ruby-1 +++ b/gettext-tools/tests/xgettext-ruby-1 @@ -1,7 +1,7 @@ #!/bin/sh . "${srcdir=.}/init.sh"; path_prepend_ . ../src -# Test of Ruby support. +# Test of Ruby support: --add-comments option. (rxgettext --version) >/dev/null 2>/dev/null \ || { echo "Skipping test: rxgettext not found"; Exit 77; } diff --git a/gettext-tools/tests/xgettext-ruby-2 b/gettext-tools/tests/xgettext-ruby-2 new file mode 100755 index 000000000..0b6ad2631 --- /dev/null +++ b/gettext-tools/tests/xgettext-ruby-2 @@ -0,0 +1,32 @@ +#!/bin/sh +. "${srcdir=.}/init.sh"; path_prepend_ . ../src + +# Test Ruby support: --add-comments option, string concatenation. + +cat <<\EOF > xg-ru-2.rb +# a +s = # b +# c +_( "hello " + # d + "world" # e + ); +EOF + +: ${XGETTEXT=xgettext} +${XGETTEXT} --add-comments --omit-header --no-location --keyword=_ \ + -d xg-ru-2.tmp xg-ru-2.rb || Exit 1 +LC_ALL=C tr -d '\r' < xg-ru-2.tmp.po > xg-ru-2.po || Exit 1 + +cat <<\EOF > xg-ru-2.ok +#. a +#. b +#. c +msgid "hello world" +msgstr "" +EOF + +: ${DIFF=diff} +${DIFF} xg-ru-2.ok xg-ru-2.po +result=$? + +exit $result diff --git a/gettext-tools/tests/xgettext-sh-1 b/gettext-tools/tests/xgettext-sh-1 index b7de75449..743218117 100755 --- a/gettext-tools/tests/xgettext-sh-1 +++ b/gettext-tools/tests/xgettext-sh-1 @@ -1,7 +1,7 @@ #!/bin/sh . "${srcdir=.}/init.sh"; path_prepend_ . ../src -# Test of Shell support. +# Test of Shell support: escape sequences, string concatenation. cat <<\EOF > xg-sh-1.sh # Test escape sequences expansion. @@ -477,6 +477,19 @@ echo "`echo "\`ngettext 'depth_2_11_squote_5_semi \\\\\;'\`"`" echo "`echo "\`ngettext 'depth_2_11_squote_6_semi \\\\\\;'\`"`" echo "`echo "\`ngettext 'depth_2_11_squote_7_semi \\\\\\\;'\`"`" echo "`echo "\`ngettext 'depth_2_11_squote_8_semi \\\\\\\\;'\`"`" + +# Test string concatenation. + +gettext "concat_0_""part2" +gettext "concat_1_"'part2' +gettext "concat_2_"part2 +gettext 'concat_3_'"part2" +gettext 'concat_4_''part2' +gettext 'concat_5_'part2 +gettext concat_6_"part2" +gettext concat_7_'part2' +gettext concat_8_ part2 +gettext "concat_9_"'part2'"part3" EOF : ${XGETTEXT=xgettext} @@ -1848,6 +1861,36 @@ msgstr "" msgid "depth_2_11_squote_8_semi \\\\;" msgstr "" + +msgid "concat_0_part2" +msgstr "" + +msgid "concat_1_part2" +msgstr "" + +msgid "concat_2_part2" +msgstr "" + +msgid "concat_3_part2" +msgstr "" + +msgid "concat_4_part2" +msgstr "" + +msgid "concat_5_part2" +msgstr "" + +msgid "concat_6_part2" +msgstr "" + +msgid "concat_7_part2" +msgstr "" + +msgid "concat_8_" +msgstr "" + +msgid "concat_9_part2part3" +msgstr "" EOF : ${DIFF=diff} diff --git a/gettext-tools/tests/xgettext-sh-5 b/gettext-tools/tests/xgettext-sh-5 index a5937b024..4db784340 100755 --- a/gettext-tools/tests/xgettext-sh-5 +++ b/gettext-tools/tests/xgettext-sh-5 @@ -1,7 +1,7 @@ #!/bin/sh . "${srcdir=.}/init.sh"; path_prepend_ . ../src -# Test of Shell support: bash $(...) syntax. +# Test of Shell support: POSIX $(...) syntax. cat <<\EOF > xg-sh-5.sh echo $(gettext 'Simple string') diff --git a/gettext-tools/tests/xgettext-vala-1 b/gettext-tools/tests/xgettext-vala-1 index a3bb0aa8b..0cba95dd8 100755 --- a/gettext-tools/tests/xgettext-vala-1 +++ b/gettext-tools/tests/xgettext-vala-1 @@ -74,7 +74,13 @@ int main (string[] args) { multiline C style comment */ var s7 = _("Extract this //sixth string"); - var s8 = _(@"This is a template string, which cannot be extracted!"); + // a + var s8 = /* b */ + _("This" + " whole " // c + + "string" + // d + """ should""" + " be " + """extracted"""); + + var s9 = _(@"This is a template string, which cannot be extracted!"); /* /= shouldn't start a regex literal */ var i5 = 1000; @@ -137,6 +143,11 @@ msgstr "" #. multiline C style comment msgid "Extract this //sixth string" msgstr "" + +#. a +#. b +msgid "This whole string should be extracted" +msgstr "" EOF : ${DIFF=diff} @@ -200,6 +211,11 @@ msgstr "" #. multiline C style comment msgid "Extract this //sixth string" msgstr "" + +#. a +#. b +msgid "This whole string should be extracted" +msgstr "" EOF ${DIFF} xg-vala-1.all.ok xg-vala-1.pot