]> git.ipfire.org Git - thirdparty/gettext.git/commitdiff
tests: Add xgettext tests regarding strings with embedded expressions.
authorBruno Haible <bruno@clisp.org>
Tue, 17 Sep 2024 22:05:48 +0000 (00:05 +0200)
committerBruno Haible <bruno@clisp.org>
Tue, 17 Sep 2024 22:05:48 +0000 (00:05 +0200)
* gettext-tools/tests/xgettext-sh-1: Add tests of strings with embedded
expressions.
* gettext-tools/tests/xgettext-python-1: Likewise.
* gettext-tools/tests/xgettext-tcl-2: Likewise.
* gettext-tools/tests/xgettext-ruby-2: Likewise.
* gettext-tools/tests/xgettext-javascript-3: Likewise.

gettext-tools/tests/xgettext-javascript-3
gettext-tools/tests/xgettext-python-1
gettext-tools/tests/xgettext-ruby-2
gettext-tools/tests/xgettext-sh-1
gettext-tools/tests/xgettext-tcl-2

index d93e935253447badbfa5a63b6928662f27745156..f3cf2337febebf78f953e5e142e1d78df5b84f74 100755 (executable)
@@ -1,8 +1,8 @@
 #!/bin/sh
 . "${srcdir=.}/init.sh"; path_prepend_ . ../src
 
-# Test of JavaScript support: string concatenation.
-# Playing with concatenation of string literals within the gettext arguments.
+# Test of JavaScript support: string concatenation,
+# strings with embedded expressions.
 
 cat <<\EOF > xg-js-3.js
 // The usual way to concatenate strings is the plus '+' sign
@@ -14,6 +14,11 @@ var s3 = // b
          _("This" + " whole " // c
           + "string" + // d
          ' should' + " be " + 'extracted');
+// Strings with embedded expressions, a.k.a. template literals.
+var t = "";
+var e1 = _(`embedded_1_${foo}_bar`);
+var e2 = _(`embedded_2_${_("embedded_2_sub1")}_bar_${_('embedded_2_sub2')}_baz`);
+var e3 = _(`embedded_3`);
 EOF
 
 : ${XGETTEXT=xgettext}
@@ -50,6 +55,15 @@ msgstr ""
 #. b
 msgid "This whole string should be extracted"
 msgstr ""
+
+msgid "embedded_2_sub1"
+msgstr ""
+
+msgid "embedded_2_sub2"
+msgstr ""
+
+msgid "embedded_3"
+msgstr ""
 EOF
 
 : ${DIFF=diff}
index 4fc4e72c90c7d320c9f331aaf2533f160ef5d92e..23e4fe14f5bec5a994af5a38474af90f8bc2c78b 100755 (executable)
@@ -1,7 +1,8 @@
 #!/bin/sh
 . "${srcdir=.}/init.sh"; path_prepend_ . ../src
 
-# Test of Python support: escape sequences, string concatenation.
+# Test of Python support: escape sequences, string concatenation,
+# strings with embedded expressions.
 
 cat <<\EOF > xg-py-1.py
 # interpret_ansic = true, interpret_unicode = false, f_string = false
@@ -38,6 +39,11 @@ _(CATEGORIES["default"]["name"]);
 # string concatenation
 _("abc" "def" + "ghi"
 "jkl" + mno)
+
+# strings with embedded expressions
+_(f"embedded_1_{foo}_bar");
+_(f"embedded_2_{_('embedded_2_sub1')}_bar_{_('embedded_2_sub2')}_baz");
+_(f"embedded_3");
 EOF
 
 : ${XGETTEXT=xgettext}
@@ -102,6 +108,15 @@ msgstr ""
 #. string concatenation
 msgid "abcdefghijkl"
 msgstr ""
+
+msgid "embedded_2_sub1"
+msgstr ""
+
+msgid "embedded_2_sub2"
+msgstr ""
+
+msgid "embedded_3"
+msgstr ""
 EOF
 
 : ${DIFF=diff}
index 26160b9d6ee3d983f49e736c6cbb783210dcae5d..ca6d406e18265c0415987276be9211f024bc90e3 100755 (executable)
@@ -1,7 +1,8 @@
 #!/bin/sh
 . "${srcdir=.}/init.sh"; path_prepend_ . ../src
 
-# Test Ruby support: --add-comments option, string concatenation.
+# Test Ruby support: --add-comments option, string concatenation,
+# strings with embedded expressions.
 
 (rxgettext --version) >/dev/null 2>/dev/null \
   || { echo "Skipping test: rxgettext not found"; Exit 77; }
@@ -13,6 +14,11 @@ s = # b
 _( "hello " + # d
    "world" # e
  );
+# Strings with embedded expressions, a.k.a. interpolated strings.
+t = "";
+_("embedded_1_#{foo}_bar");
+_("embedded_2_#{_("embedded_2_sub1")}_bar_#{_("embedded_2_sub2")}_baz");
+_("embedded_3");
 EOF
 
 : ${XGETTEXT=xgettext}
@@ -26,6 +32,15 @@ cat <<\EOF > xg-ru-2.ok
 #. c
 msgid "hello world"
 msgstr ""
+
+msgid "embedded_2_sub1"
+msgstr ""
+
+msgid "embedded_2_sub2"
+msgstr ""
+
+msgid "embedded_3"
+msgstr ""
 EOF
 
 : ${DIFF=diff}
index 743218117a5175a24a5572446a9a234c47bc891a..8178d7baa50aa92e4ce98cfae4058050c9ae564d 100755 (executable)
@@ -1,7 +1,8 @@
 #!/bin/sh
 . "${srcdir=.}/init.sh"; path_prepend_ . ../src
 
-# Test of Shell support: escape sequences, string concatenation.
+# Test of Shell support: escape sequences, string concatenation,
+# strings with embedded expressions.
 
 cat <<\EOF > xg-sh-1.sh
 # Test escape sequences expansion.
@@ -490,6 +491,13 @@ gettext  concat_6_"part2"
 gettext  concat_7_'part2'
 gettext  concat_8_ part2
 gettext "concat_9_"'part2'"part3"
+
+# Test strings with embedded expressions.
+
+gettext "embedded_1_${foo}_bar"
+gettext "embedded_2_${foo-`gettext embedded_2_sub1`}_bar_${foo-`gettext embedded_2_sub2`}_baz"
+gettext "embedded_3_${foo:-`gettext embedded_3_sub1`}_bar_${foo:-`gettext embedded_3_sub2`}_baz"
+gettext "embedded_4"
 EOF
 
 : ${XGETTEXT=xgettext}
@@ -1891,6 +1899,21 @@ msgstr ""
 
 msgid "concat_9_part2part3"
 msgstr ""
+
+msgid "embedded_2_sub1"
+msgstr ""
+
+msgid "embedded_2_sub2"
+msgstr ""
+
+msgid "embedded_3_sub1"
+msgstr ""
+
+msgid "embedded_3_sub2"
+msgstr ""
+
+msgid "embedded_4"
+msgstr ""
 EOF
 
 : ${DIFF=diff}
index 13aa9830544076890259fde93a25f25794948c8a..d4a41dfa1c06763e5b3f9a2f8ac118f32148393d 100755 (executable)
@@ -1,7 +1,7 @@
 #!/bin/sh
 . "${srcdir=.}/init.sh"; path_prepend_ . ../src
 
-# Test Tcl support: --add-comments option.
+# Test Tcl support: --add-comments option, strings with embedded expressions.
 
 cat <<\EOF > xg-t-2.tcl
 # This comment will not be extracted.
@@ -13,6 +13,10 @@ puts [_ "Hey Jude"]
 # TRANSLATORS:
 #    Nickname of the Beatles
 puts [_ "The Fabulous Four"]
+# Strings with embedded expressions, a.k.a. variable substitution.
+puts [_ "embedded_1_$foo_bar"]
+puts [_ "embedded_2_$myArray([$myFunction [_ "embedded_2_sub1"]])_bar_$myArray($myIndices([$myFunction [_ "embedded_2_sub2"]]))_baz"];
+puts [_ "embedded_3"]
 EOF
 
 : ${XGETTEXT=xgettext}
@@ -35,6 +39,15 @@ msgstr ""
 #. Nickname of the Beatles
 msgid "The Fabulous Four"
 msgstr ""
+
+msgid "embedded_2_sub1"
+msgstr ""
+
+msgid "embedded_2_sub2"
+msgstr ""
+
+msgid "embedded_3"
+msgstr ""
 EOF
 
 : ${DIFF=diff}