public inbox for glibc-cvs@sourceware.org help / color / mirror / Atom feed
From: Adhemerval Zanella <azanella@sourceware.org> To: glibc-cvs@sourceware.org Subject: [glibc/azanella/clang] stdio-common: Add tst-printf-width-i18n to cover numeric field width Date: Fri, 3 Jun 2022 14:12:52 +0000 (GMT) [thread overview] Message-ID: <20220603141252.4FBC43850846@sourceware.org> (raw) https://sourceware.org/git/gitweb.cgi?p=glibc.git;h=ada82e1aabc8d945cf49e56456aafbe3d129ce75 commit ada82e1aabc8d945cf49e56456aafbe3d129ce75 Author: Florian Weimer <fweimer@redhat.com> Date: Thu Mar 17 20:28:33 2022 +0100 stdio-common: Add tst-printf-width-i18n to cover numeric field width Related to bug 28943 and bug 28944. Diff: --- stdio-common/tst-printf-width-i18n.c | 95 ++++++++++++++++++++++++++++++++++++ 1 file changed, 95 insertions(+) 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>
reply other threads:[~2022-06-03 14:12 UTC|newest] Thread overview: [no followups] expand[flat|nested] mbox.gz Atom feed
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=20220603141252.4FBC43850846@sourceware.org \ --to=azanella@sourceware.org \ --cc=glibc-cvs@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: linkBe 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).