]> git.ipfire.org Git - thirdparty/gettext.git/commitdiff
tests: Add xgettext tests regarding string concatenation.
authorBruno Haible <bruno@clisp.org>
Wed, 11 Sep 2024 12:20:57 +0000 (14:20 +0200)
committerBruno Haible <bruno@clisp.org>
Wed, 11 Sep 2024 12:20:57 +0000 (14:20 +0200)
* 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.

18 files changed:
gettext-tools/tests/Makefile.am
gettext-tools/tests/xgettext-csharp-5
gettext-tools/tests/xgettext-csharp-6
gettext-tools/tests/xgettext-java-5
gettext-tools/tests/xgettext-java-6
gettext-tools/tests/xgettext-javascript-3
gettext-tools/tests/xgettext-lua-1
gettext-tools/tests/xgettext-lua-2
gettext-tools/tests/xgettext-perl-7
gettext-tools/tests/xgettext-php-3
gettext-tools/tests/xgettext-python-1
gettext-tools/tests/xgettext-python-2
gettext-tools/tests/xgettext-python-4
gettext-tools/tests/xgettext-ruby-1
gettext-tools/tests/xgettext-ruby-2 [new file with mode: 0755]
gettext-tools/tests/xgettext-sh-1
gettext-tools/tests/xgettext-sh-5
gettext-tools/tests/xgettext-vala-1

index c27d4b390f99dc8fc9db83d8c90b6165030c10f8..d71b797ea1fea8b4497b38400fd3c9cbfb06b4bc 100644 (file)
@@ -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 \
index a3fd3ec44ecc7428f3ef82a38be78fae626b0a08..0fcb5224b967ae5399a4da0594696910bfa89eab 100755 (executable)
@@ -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.
index 84dc210cf238e3cde2b7120f2ff28e280f311bb4..440b1da9df908df33f0ea8646409a57428c26d27 100755 (executable)
@@ -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 */
index c7240f2c181374cb62ca88fe446180044b83accf..704c617bfa334958307ad600888f650c3dad6704 100755 (executable)
@@ -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.
index 47d7de3aec4e28a050096ed7139579080f32c71e..35ae948d4ddbf7d6566c6ed0f89f3fc6ac318f5a 100755 (executable)
@@ -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 */
index 313cff0415bc3358ebb85154d46cc6f4e01fd483..d93e935253447badbfa5a63b6928662f27745156 100755 (executable)
@@ -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
index 270d7e22434ce9eb380f467bfc70e1acf5eda1a4..a6009ef1cca1525632e468c31fe6972e47672ea6 100755 (executable)
@@ -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}
index df82135eff94248e98551ad38a3d678fb1e56be3..b5bb5ed8406e3ccf716903951e20197e2756b190 100755 (executable)
@@ -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.
index fafbef260ee0a6b6d1cd3343d12e9bdbe73c355c..88835a7ed3d6641c5e6b00e282a0a8f92f044cc2 100755 (executable)
@@ -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
index 127d3c6402f771dda2db7fd6b226df5195894122..cdc6bf52b5b739c0aa9c71616a69329cc57290c3 100755 (executable)
@@ -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
 <?
index abd3f996d8049bbf57f36b3c6a5cc83fd27a316b..4fc4e72c90c7d320c9f331aaf2533f160ef5d92e 100755 (executable)
@@ -1,7 +1,7 @@
 #!/bin/sh
 . "${srcdir=.}/init.sh"; path_prepend_ . ../src
 
-# Test of Python support.
+# Test of Python support: escape sequences, string concatenation.
 
 cat <<\EOF > xg-py-1.py
 # interpret_ansic = true, interpret_unicode = false, f_string = false
index 5aec46a50578a902fd249466a27e908d4bbe3cef..35b38ca0f4b1e45d6fcc931675893e30da4c5eab 100755 (executable)
@@ -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.
index f0599bb5f17fa2e30f2298991a9f71cd38a81c3f..798336ed7da4a5f48c2e43d0c33431fcfee5ea1b 100755 (executable)
@@ -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
index dd8e68b277ef20878c081ddf6cb163ea10591ec0..9b41a94fdb3a24c1e33f3bd9ae906ec61f0d44f9 100755 (executable)
@@ -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 (executable)
index 0000000..0b6ad26
--- /dev/null
@@ -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
index b7de75449d55c747e55181979e44659d60d95f02..743218117a5175a24a5572446a9a234c47bc891a 100755 (executable)
@@ -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}
index a5937b02483e3041a9f95a9dfdf138c98a4d8d5d..4db784340c0f1d41e2521f1c23610cc45dc0aee9 100755 (executable)
@@ -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')
index a3bb0aa8bd753638fd8d5f64815c87542e769e30..0cba95dd890572f4d689b31c7a81aa5ec2d7f2db 100755 (executable)
@@ -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