From: Florian Weimer <fweimer@redhat.com>
To: libc-alpha@sourceware.org
Subject: [PATCH 04/26] stdio-common: Add tst-printf-width-i18n to cover numeric field width
Date: Thu, 17 Mar 2022 20:28:33 +0100 [thread overview]
Message-ID: <f0f166cc7b0b3bef7cd51cdf1788ff429e560396.1647544751.git.fweimer@redhat.com> (raw)
In-Reply-To: <cover.1647544751.git.fweimer@redhat.com>
Related to bug 28943 and bug 28944.
---
stdio-common/Makefile | 1 +
stdio-common/tst-printf-width-i18n.c | 95 ++++++++++++++++++++++++++++
2 files changed, 96 insertions(+)
create mode 100644 stdio-common/tst-printf-width-i18n.c
diff --git a/stdio-common/Makefile b/stdio-common/Makefile
index 435cd8904f..f0e65f0dcd 100644
--- a/stdio-common/Makefile
+++ b/stdio-common/Makefile
@@ -250,6 +250,7 @@ LOCALES := \
de_DE.ISO-8859-1 \
de_DE.UTF-8 \
en_US.ISO-8859-1 \
+ hi_IN.UTF-8 \
ja_JP.EUC-JP \
ps_AF.UTF-8 \
# LOCALES
diff --git a/stdio-common/tst-printf-width-i18n.c b/stdio-common/tst-printf-width-i18n.c
new file mode 100644
index 0000000000..2355f30d67
--- /dev/null
+++ b/stdio-common/tst-printf-width-i18n.c
@@ -0,0 +1,95 @@
+/* Test for width of non-ASCII digit sequences.
+ Copyright (C) 2022 Free Software Foundation, Inc.
+ This file is part of the GNU C Library.
+
+ The GNU C Library is free software; you can redistribute it and/or
+ modify it under the terms of the GNU Lesser General Public
+ License as published by the Free Software Foundation; either
+ version 2.1 of the License, or (at your option) any later version.
+
+ The GNU C Library is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ Lesser General Public License for more details.
+
+ You should have received a copy of the GNU Lesser General Public
+ License along with the GNU C Library; if not, see
+ <https://www.gnu.org/licenses/>. */
+
+/* Behavior is currently inconsistent between %d and %f (bug 28943,
+ bug 28944). This test intends to capture the status quo. */
+
+#include <monetary.h>
+#include <stdio.h>
+#include <support/support.h>
+#include <support/check.h>
+
+static int
+do_test (void)
+{
+ char buf[40];
+
+ xsetlocale (LC_ALL, "hi_IN.UTF-8");
+
+ /* Ungrouped, not translated. */
+ TEST_COMPARE (sprintf (buf, "%7d", 12345), 7);
+ TEST_COMPARE_STRING (buf, " 12345");
+ TEST_COMPARE (sprintf (buf, "%10.2f", 12345.67), 10);
+ TEST_COMPARE_STRING (buf, " 12345.67");
+ TEST_COMPARE (strfmon (buf, sizeof (buf), "%^13i", 12345.67), 13);
+ TEST_COMPARE_STRING (buf, " INR12345.67");
+
+ /* Grouped. */
+ TEST_COMPARE (sprintf (buf, "%'8d", 12345), 8);
+ TEST_COMPARE_STRING (buf, " 12,345");
+ TEST_COMPARE (sprintf (buf, "%'11.2f", 12345.67), 11);
+ TEST_COMPARE_STRING (buf, " 12,345.67");
+ TEST_COMPARE (strfmon (buf, sizeof (buf), "%13i", 12345.67), 13);
+ TEST_COMPARE_STRING (buf, " INR12,345.67");
+
+ /* Translated. */
+ TEST_COMPARE (sprintf (buf, "%I16d", 12345), 16);
+ TEST_COMPARE_STRING (buf, " १२३४५");
+ TEST_COMPARE (sprintf (buf, "%I12.2f", 12345.67), 26);
+ TEST_COMPARE_STRING (buf, " १२३४५.६७");
+
+ /* Translated and grouped. */
+ TEST_COMPARE (sprintf (buf, "%'I17d", 12345), 17);
+ TEST_COMPARE_STRING (buf, " १२,३४५");
+ TEST_COMPARE (sprintf (buf, "%'I12.2f", 12345.67), 26);
+ TEST_COMPARE_STRING (buf, " १२,३४५.६७");
+
+ xsetlocale (LC_ALL, "ps_AF.UTF-8");
+
+ /* Ungrouped, not translated. */
+ TEST_COMPARE (sprintf (buf, "%7d", 12345), 7);
+ TEST_COMPARE_STRING (buf, " 12345");
+ TEST_COMPARE (sprintf (buf, "%10.2f", 12345.67), 11);
+ TEST_COMPARE_STRING (buf, " 12345٫67");
+ TEST_COMPARE (strfmon (buf, sizeof (buf), "%^13i", 12345.67), 13);
+ TEST_COMPARE_STRING (buf, " 12346 AFN");
+
+ /* Grouped. */
+ TEST_COMPARE (sprintf (buf, "%'8d", 12345), 8);
+ TEST_COMPARE_STRING (buf, " 12٬345");
+ TEST_COMPARE (sprintf (buf, "%'11.2f", 12345.67), 13);
+ TEST_COMPARE_STRING (buf, " 12٬345٫67"); /* Counts characters. */
+ TEST_COMPARE (strfmon (buf, sizeof (buf), "%13i", 12345.67), 13);
+ TEST_COMPARE_STRING (buf, " 12٬346 AFN"); /* Counts bytes. */
+
+ /* Translated. */
+ TEST_COMPARE (sprintf (buf, "%I11d", 12345), 11);
+ TEST_COMPARE_STRING (buf, " ١٢٣۴٥");
+ TEST_COMPARE (sprintf (buf, "%I12.2f", 12345.67), 20);
+ TEST_COMPARE_STRING (buf, " ١٢٣۴٥٫٦٧");
+
+ /* Translated and grouped. */
+ TEST_COMPARE (sprintf (buf, "%'I13d", 12345), 13);
+ TEST_COMPARE_STRING (buf, " ١٢٬٣۴٥");
+ TEST_COMPARE (sprintf (buf, "%'I12.2f", 12345.67), 21);
+ TEST_COMPARE_STRING (buf, " ١٢٬٣۴٥٫٦٧");
+
+ return 0;
+}
+
+#include <support/test-driver.c>
--
2.35.1
next prev parent reply other threads:[~2022-03-17 19:28 UTC|newest]
Thread overview: 49+ messages / expand[flat|nested] mbox.gz Atom feed top
2022-03-17 19:28 [PATCH 00/26] vfprintf rework to remove vtables Florian Weimer
2022-03-17 19:28 ` [PATCH 01/26] libio: Convert tst_swprintf to the test framework Florian Weimer
2022-03-18 17:40 ` Adhemerval Zanella
2022-03-17 19:28 ` [PATCH 02/26] libio: Flush-only _IO_str_overflow must not return EOF (bug 28949) Florian Weimer
2022-03-18 18:11 ` Adhemerval Zanella
2022-03-17 19:28 ` [PATCH 03/26] stdio-common: Add wide stream coverage to tst-vfprintf-user-type Florian Weimer
2022-03-18 18:30 ` Adhemerval Zanella
2022-03-18 19:19 ` Florian Weimer
2022-03-17 19:28 ` Florian Weimer [this message]
2022-05-20 13:22 ` [PATCH 04/26] stdio-common: Add tst-printf-width-i18n to cover numeric field width Adhemerval Zanella
2022-05-20 13:33 ` Adhemerval Zanella
2022-05-23 6:39 ` Florian Weimer
2022-03-17 19:28 ` [PATCH 05/26] vfprintf: Move argument processing into vfprintf-process-arg.c Florian Weimer
2022-05-20 13:28 ` Adhemerval Zanella
2022-03-17 19:28 ` [PATCH 06/26] vfprintf: Consolidate some multibyte/wide character processing Florian Weimer
2022-05-20 14:16 ` Adhemerval Zanella
2022-03-17 19:29 ` [PATCH 07/26] __printf_fphex always uses LC_NUMERIC Florian Weimer
2022-05-20 14:21 ` Adhemerval Zanella
2022-05-23 6:55 ` Florian Weimer
2022-03-17 19:29 ` [PATCH 08/26] stdio-common: Add tst-memstream-string for open_memstream overflow Florian Weimer
2022-05-20 17:44 ` Adhemerval Zanella
2022-05-23 7:03 ` Florian Weimer
2022-03-17 19:29 ` [PATCH 09/26] stdio-common: Add printf specifier registry to <printf.h> Florian Weimer
2022-05-20 17:49 ` Adhemerval Zanella
2022-03-17 19:30 ` [PATCH 10/26] stdio-common: Move union printf_arg int <printf.h> Florian Weimer
2022-05-20 17:51 ` Adhemerval Zanella
2022-03-17 19:30 ` [PATCH 11/26] stdio-common: Simplify printf_unknown interface in vfprintf-internal.c Florian Weimer
2022-05-20 18:07 ` Adhemerval Zanella
2022-03-17 19:30 ` [PATCH 12/26] locale: Call _nl_unload_locale from _nl_archive_subfreeres Florian Weimer
2022-05-20 18:09 ` Adhemerval Zanella
2022-05-23 7:14 ` Florian Weimer
2022-03-17 19:30 ` [PATCH 13/26] locale: Remove cleanup function pointer from struct __localedata Florian Weimer
2022-05-20 18:16 ` Adhemerval Zanella
2022-03-17 19:30 ` [PATCH 14/26] locale: Remove private union from struct __locale_data Florian Weimer
2022-05-20 18:22 ` Adhemerval Zanella
2022-03-17 19:30 ` [PATCH 15/26] locale: Add more cached data to LC_CTYPE Florian Weimer
2022-05-20 18:29 ` Adhemerval Zanella
2022-05-23 7:20 ` Florian Weimer
2022-03-17 19:31 ` [PATCH 16/26] locale: Implement struct grouping_iterator Florian Weimer
2022-03-17 19:31 ` [PATCH 17/26] stdio-common: Introduce buffers for implementing printf Florian Weimer
2022-03-17 19:31 ` [PATCH 18/26] stdio-common: Add __printf_function_invoke Florian Weimer
2022-03-17 19:31 ` [PATCH 19/26] stdio-common: Add __translated_number_width Florian Weimer
2022-03-17 19:31 ` [PATCH 20/26] stdio-common: Convert vfprintf and related functions to buffers Florian Weimer
2022-03-17 19:31 ` [PATCH 21/26] stdio-common: Add lock optimization to vfprintf and vfwprintf Florian Weimer
2022-03-17 19:31 ` [PATCH 22/26] libio: Convert __vsprintf_internal to buffers Florian Weimer
2022-03-17 19:31 ` [PATCH 23/26] libio: Convert __vasprintf_internal " Florian Weimer
2022-03-17 19:31 ` [PATCH 24/26] libio: Convert __vdprintf_internal " Florian Weimer
2022-03-17 19:32 ` [PATCH 25/26] libio: Convert __obstack_vprintf_internal to buffers (bug 27124) Florian Weimer
2022-03-17 19:32 ` [PATCH 26/26] libio: Convert __vswprintf_internal to buffers (bug 27857) Florian Weimer
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=f0f166cc7b0b3bef7cd51cdf1788ff429e560396.1647544751.git.fweimer@redhat.com \
--to=fweimer@redhat.com \
--cc=libc-alpha@sourceware.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).