]> git.ipfire.org Git - thirdparty/gettext.git/commitdiff
Prepare for Rust support.
authorKévin Commaille <zecakeh@tedomum.fr>
Tue, 28 Jan 2025 10:08:52 +0000 (11:08 +0100)
committerBruno Haible <bruno@clisp.org>
Tue, 28 Jan 2025 20:55:22 +0000 (21:55 +0100)
* gettext-tools/tests/xgettext-rust-1: New file, based on
gettext-tools/tests/xgettext-csharp-1.
* gettext-tools/tests/xgettext-rust-2: New file, based on
gettext-tools/tests/xgettext-csharp-2.
* gettext-tools/tests/xgettext-rust-3: New file, based on
gettext-tools/tests/xgettext-csharp-3.
* gettext-tools/tests/xgettext-rust-4: New file, based on
gettext-tools/tests/xgettext-csharp-4.
* gettext-tools/tests/xgettext-rust-5: New file, based on
gettext-tools/tests/xgettext-csharp-7.

gettext-tools/tests/xgettext-rust-1 [new file with mode: 0755]
gettext-tools/tests/xgettext-rust-2 [new file with mode: 0755]
gettext-tools/tests/xgettext-rust-3 [new file with mode: 0755]
gettext-tools/tests/xgettext-rust-4 [new file with mode: 0755]
gettext-tools/tests/xgettext-rust-5 [new file with mode: 0755]

diff --git a/gettext-tools/tests/xgettext-rust-1 b/gettext-tools/tests/xgettext-rust-1
new file mode 100755 (executable)
index 0000000..1c707cd
--- /dev/null
@@ -0,0 +1,75 @@
+#!/bin/sh
+. "${srcdir=.}/init.sh"; path_prepend_ . ../src
+
+# Some tests for Rust support
+
+cat <<EOF > xg-rs-1.rs
+use gettext_rs::gettext;
+
+pub trait TestCase {
+  fn TestCase() {
+    GettextResourceManager rm = new GettextResourceManager("test");
+    // standard usage
+    String test1 = gettext("Test String 1");
+    /* C style comment */
+    String test2 = gettext("Test String 2");
+    // "multiline" string
+    String test3 = gettext("Test " +
+    "String " +
+    "3");
+    // macro
+    String test2 = gettext!("Test String 4");
+    // empty string
+    String test4 = gettext("");
+    // byte string
+    String test2 = gettext(b"Test String 5");
+    // raw string
+    String test5 = gettext(r#"first line
+second line
+third line"#);
+  }
+}
+EOF
+
+: ${XGETTEXT=xgettext}
+${XGETTEXT} --omit-header --no-location -c -d xg-rs-1.tmp xg-rs-1.rs || Exit 1
+LC_ALL=C tr -d '\r' < xg-rs-1.tmp.po > xg-rs-1.po || Exit 1
+
+cat <<EOF > xg-rs-1.ok
+#. standard usage
+msgid "Test String 1"
+msgstr ""
+
+#. C style comment
+msgid "Test String 2"
+msgstr ""
+
+#. "multiline" string
+msgid "Test String 3"
+msgstr ""
+
+#. macro
+msgid "Test String 4"
+msgstr ""
+
+#. empty string
+msgid ""
+msgstr ""
+
+#. byte string
+msgid "Test String 5"
+msgstr ""
+
+#. raw string
+msgid ""
+"first line\n"
+"second line\n"
+"third line"
+msgstr ""
+EOF
+
+: ${DIFF=diff}
+${DIFF} xg-rs-1.ok xg-rs-1.po
+result=$?
+
+exit $result
diff --git a/gettext-tools/tests/xgettext-rust-2 b/gettext-tools/tests/xgettext-rust-2
new file mode 100755 (executable)
index 0000000..1f861c2
--- /dev/null
@@ -0,0 +1,82 @@
+#!/bin/sh
+. "${srcdir=.}/init.sh"; path_prepend_ . ../src
+
+# More tests for Rust support: UTF-8 characters
+
+cat <<\EOF > xg-rs-2.rs
+pub trait TestCase {
+  fn main () {
+    catalog.gettext("Russian (Русский): Здравствуйте"));
+    catalog.gettext("Vietnamese (Tiếng Việt): Chào bạn"));
+    catalog.gettext("Japanese (日本語): こんにちは"));
+    catalog.gettext("Thai (ภาษาไทย): สวัสดีครับ"));
+    catalog.gettext("Script: 𝒞"));
+    catalog.gettext("Russian (\u{0420}\u{0443}\u{0441}\u{0441}\u{043a}\u{0438}\u{0439}): \u{0417}\u{0434}\u{0440}\u{0430}\u{0432}\u{0441}\u{0442}\u{0432}\u{0443}\u{0439}\u{0442}\u{0435}"));
+    catalog.gettext("Vietnamese (Ti\u{1ebf}ng Vi\u{1ec7}t): Ch\u{00e0}o b\u{1ea1}n"));
+    catalog.gettext("Japanese (\u{65e5}\u{672c}\u{8a9e}): \u{3053}\u{3093}\u{306b}\u{3061}\u{306f}"));
+    catalog.gettext("Thai (\u{0e20}\u{0e32}\u{0e29}\u{0e32}\u{0e44}\u{0e17}\u{0e22}): \u{0e2a}\u{0e27}\u{0e31}\u{0e2a}\u{0e14}\u{0e35}\u{0e04}\u{0e23}\u{0e31}\u{0e1a}"));
+    catalog.gettext("Script: \u{1d49e}"));
+    // And now a comment with Русский and 日本語 and Unicode escapes: B\u{00f6}se B\u{00fc}bchen
+    catalog.gettext("This string has a multilingual comment"));
+    // Unicode identifiers.
+    String あ = "";
+    String 𐀀 = "";
+  }
+}
+EOF
+
+: ${XGETTEXT=xgettext}
+# delete POT-Creation-Date: line because the date depends on local time.
+${XGETTEXT} --output xg-rs-2.tmp --add-location -c xg-rs-2.rs || Exit 1
+sed -e '/\"POT-Creation-Date:.*/d' < xg-rs-2.tmp | LC_ALL=C tr -d '\r' > xg-rs-2.po || Exit 1
+
+cat <<\EOF > xg-rs-2.ok
+# SOME DESCRIPTIVE TITLE.
+# Copyright (C) YEAR THE PACKAGE'S COPYRIGHT HOLDER
+# This file is distributed under the same license as the PACKAGE package.
+# FIRST AUTHOR <EMAIL@ADDRESS>, YEAR.
+#
+#, fuzzy
+msgid ""
+msgstr ""
+"Project-Id-Version: PACKAGE VERSION\n"
+"Report-Msgid-Bugs-To: \n"
+"PO-Revision-Date: YEAR-MO-DA HO:MI+ZONE\n"
+"Last-Translator: FULL NAME <EMAIL@ADDRESS>\n"
+"Language-Team: LANGUAGE <LL@li.org>\n"
+"Language: \n"
+"MIME-Version: 1.0\n"
+"Content-Type: text/plain; charset=UTF-8\n"
+"Content-Transfer-Encoding: 8bit\n"
+
+#: xg-rs-2.rs:3 xg-rs-2.rs:8
+msgid "Russian (Русский): Здравствуйте"
+msgstr ""
+
+#: xg-rs-2.rs:4 xg-rs-2.rs:9
+msgid "Vietnamese (Tiếng Việt): Chào bạn"
+msgstr ""
+
+#: xg-rs-2.rs:5 xg-rs-2.rs:10
+msgid "Japanese (日本語): こんにちは"
+msgstr ""
+
+#: xg-rs-2.rs:6 xg-rs-2.rs:11
+msgid "Thai (ภาษาไทย): สวัสดีครับ"
+msgstr ""
+
+#: xg-rs-2.rs:7 xg-rs-2.rs:12
+msgid "Script: 𝒞"
+msgstr ""
+
+#. And now a comment with Русский and 日本語 and Unicode escapes: B\u{00f6}se B\u{00fc}bchen
+#: xg-rs-2.rs:14
+msgid "This string has a multilingual comment"
+msgstr ""
+EOF
+
+: ${DIFF=diff}
+${DIFF} xg-rs-2.ok xg-rs-2.po
+result=$?
+
+exit $result
diff --git a/gettext-tools/tests/xgettext-rust-3 b/gettext-tools/tests/xgettext-rust-3
new file mode 100755 (executable)
index 0000000..85d453e
--- /dev/null
@@ -0,0 +1,165 @@
+#!/bin/sh
+. "${srcdir=.}/init.sh"; path_prepend_ . ../src
+
+# More tests for Rust support: string syntax
+
+LC_ALL=C tr '%' '\015' <<\EOF > xg-rs-3.rs
+pub trait TestCase {
+  fn main () {
+    // Test recognition of \u escapes.
+    gettext("B\u{00f6}se B\u{00fc}bchen");
+    // \u escapes with more than one u are invalid.
+    gettext("Japanese: \uu{6585}\uuu{6723}\u{8A9e}");
+    gettext("embedded\nnewline");
+    // Two backslashes (unlike in Java, where this is just one backslash).
+    gettext("\u{005c}\u{005c}");
+    // A 6-character string (unlike in Java, where this is just one backslash).
+    gettext("\\u005c");
+    // A single backslash.
+    gettext("\\");
+    // Escape sequences in strings.
+    gettext("t -> \t, n -> \n, dquote -> \", squote -> \' ...");
+    // Hex escapes are recognized.
+    gettext("bel: \x07\n");
+    gettext // Recognized despite comments
+       ( /* Even across multiline
+comment! */ "this is a single " /* now comes the concatenation! */ + // after +
+         "long line");
+    // Byte string literals are extracted.
+    gettext(b"byte 1");
+    // In byte string literals, escape sequences are recognized.
+    gettext(b"byte 2 \u{005c} \\ \t \n");
+    // Raw string literals are extracted.
+    gettext(r"raw 1");
+    // In raw string literals, no escape sequences are recognized.
+    gettext(r"raw 2 \u{005c} \\ \t \n \'");
+    // In raw string literals, only delimiters without the proper number of
+    // hashes are recognized.
+    gettext (r##"raw 3 ""test"##);
+    // Normal and raw string literals can be concatenated.
+    gettext("left - \"quot" + r#"ation"" - right"#);
+    // Character literals are not extracted.
+    gettext('x');
+    // Invalid concatenations are not concatenated.
+    gettext("fooba"+'r');
+  }
+}
+EOF
+
+: ${XGETTEXT=xgettext}
+# delete POT-Creation-Date: line because the date depends on local time.
+${XGETTEXT} --output xg-rs-3.tmp --add-location -c -kmygettext:2 xg-rs-3.rs 2>/dev/null || Exit 1
+sed -e '/\"POT-Creation-Date:.*/d' < xg-rs-3.tmp | LC_ALL=C tr -d '\r' > xg-rs-3.po || Exit 1
+
+cat <<\EOF > xg-rs-3.ok
+# SOME DESCRIPTIVE TITLE.
+# Copyright (C) YEAR THE PACKAGE'S COPYRIGHT HOLDER
+# This file is distributed under the same license as the PACKAGE package.
+# FIRST AUTHOR <EMAIL@ADDRESS>, YEAR.
+#
+#, fuzzy
+msgid ""
+msgstr ""
+"Project-Id-Version: PACKAGE VERSION\n"
+"Report-Msgid-Bugs-To: \n"
+"PO-Revision-Date: YEAR-MO-DA HO:MI+ZONE\n"
+"Last-Translator: FULL NAME <EMAIL@ADDRESS>\n"
+"Language-Team: LANGUAGE <LL@li.org>\n"
+"Language: \n"
+"MIME-Version: 1.0\n"
+"Content-Type: text/plain; charset=UTF-8\n"
+"Content-Transfer-Encoding: 8bit\n"
+
+#. Test recognition of \u escapes.
+#: xg-rs-3.rs:4
+msgid "Böse Bübchen"
+msgstr ""
+
+#. \u escapes with more than one u are invalid.
+#: xg-rs-3.rs:6
+#, rust-format
+msgid "Japanese: \\uu{6585}\\uuu{6723}語"
+msgstr ""
+
+#: xg-rs-3.rs:7
+msgid ""
+"embedded\n"
+"newline"
+msgstr ""
+
+#. Two backslashes (unlike in Java, where this is just one backslash).
+#: xg-rs-3.rs:9
+msgid "\\\\"
+msgstr ""
+
+#. A 6-character string (unlike in Java, where this is just one backslash).
+#: xg-rs-3.rs:11
+msgid "\\u005c"
+msgstr ""
+
+#. A single backslash.
+#: xg-rs-3.rs:13
+msgid "\\"
+msgstr ""
+
+#. Escape sequences in strings.
+#: xg-rs-3.rs:15
+msgid ""
+"t -> \t, n -> \n"
+", dquote -> \", squote -> ' ..."
+msgstr ""
+
+#. Hex escapes are recognized.
+#: xg-rs-3.rs:17
+msgid "bel: \a\n"
+msgstr ""
+
+#. Recognized despite comments
+#. Even across multiline
+#. comment!
+#: xg-rs-3.rs:20
+msgid "this is a single long line"
+msgstr ""
+
+#. Byte string literals are extracted.
+#: xg-rs-3.rs:23
+msgid "byte 1"
+msgstr ""
+
+#. In byte string literals, escape sequences are recognized.
+#: xg-rs-3.rs:25
+msgid "byte 2 \\ \\ \t \n"
+msgstr ""
+
+#. Raw string literals are extracted.
+#: xg-rs-3.rs:27
+msgid "raw 1"
+msgstr ""
+
+#. In raw string literals, no escape sequences are recognized.
+#: xg-rs-3.rs:29
+msgid "raw 2 \\u{005c} \\\\ \\t \\n \\'"
+msgstr ""
+
+#. In raw string literals, only delimiters without the proper number of
+#. hashes are recognized.
+#: xg-rs-3.rs:32
+msgid "raw 3 \"test"
+msgstr ""
+
+#. Normal and raw string literals can be concatenated.
+#: xg-rs-3.rs:34
+msgid "left - \"quotation\" - right"
+msgstr ""
+
+#. Invalid concatenations are not concatenated.
+#: xg-rs-3.rs:38
+msgid "fooba"
+msgstr ""
+EOF
+
+: ${DIFF=diff}
+${DIFF} xg-rs-3.ok xg-rs-3.po
+result=$?
+
+exit $result
diff --git a/gettext-tools/tests/xgettext-rust-4 b/gettext-tools/tests/xgettext-rust-4
new file mode 100755 (executable)
index 0000000..3ed0ed1
--- /dev/null
@@ -0,0 +1,36 @@
+#!/bin/sh
+. "${srcdir=.}/init.sh"; path_prepend_ . ../src
+
+# Tests for Rust plural keyword support
+
+cat <<EOF > xg-rs-4.rs
+pub trait TestCase {
+  fn main () {
+    ngettext("test 1", "plural test");
+    myngettext(context, "I've 1", "you've lost");
+  }
+}
+EOF
+
+: ${XGETTEXT=xgettext}
+${XGETTEXT} --omit-header --no-location --keyword=myngettext:2,3 \
+  -d xg-rs-4.tmp xg-rs-4.rs || Exit 1
+LC_ALL=C tr -d '\r' < xg-rs-4.tmp.po > xg-rs-4.po || Exit 1
+
+cat <<EOF > xg-rs-4.ok
+msgid "test 1"
+msgid_plural "plural test"
+msgstr[0] ""
+msgstr[1] ""
+
+msgid "I've 1"
+msgid_plural "you've lost"
+msgstr[0] ""
+msgstr[1] ""
+EOF
+
+: ${DIFF=diff}
+${DIFF} xg-rs-4.ok xg-rs-4.po
+result=$?
+
+exit $result
diff --git a/gettext-tools/tests/xgettext-rust-5 b/gettext-tools/tests/xgettext-rust-5
new file mode 100755 (executable)
index 0000000..edd98a2
--- /dev/null
@@ -0,0 +1,28 @@
+#! /bin/sh
+. "${srcdir=.}/init.sh"; path_prepend_ . ../src
+
+# Test Rust support: extraction of contexts.
+
+cat <<\EOF > xg-rs-7.rs
+println!(gettext("help"));
+println!(pgettext("Help", "about"));
+EOF
+
+: ${XGETTEXT=xgettext}
+${XGETTEXT} --omit-header --no-location -d xg-rs-7.tmp xg-rs-7.rs || Exit 1
+LC_ALL=C tr -d '\r' < xg-rs-7.tmp.po > xg-rs-7.po || Exit 1
+
+cat <<EOF > xg-rs-7.ok
+msgid "help"
+msgstr ""
+
+msgctxt "Help"
+msgid "about"
+msgstr ""
+EOF
+
+: ${DIFF=diff}
+${DIFF} xg-rs-7.ok xg-rs-7.po
+result=$?
+
+exit $result