1/* Test for width of non-ASCII digit sequences.
2 Copyright (C) 2022-2024 Free Software Foundation, Inc.
3 This file is part of the GNU C Library.
4
5 The GNU C Library is free software; you can redistribute it and/or
6 modify it under the terms of the GNU Lesser General Public
7 License as published by the Free Software Foundation; either
8 version 2.1 of the License, or (at your option) any later version.
9
10 The GNU C Library is distributed in the hope that it will be useful,
11 but WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 Lesser General Public License for more details.
14
15 You should have received a copy of the GNU Lesser General Public
16 License along with the GNU C Library; if not, see
17 <https://www.gnu.org/licenses/>. */
18
19/* Behavior is currently inconsistent between %d and %f (bug 28943,
20 bug 28944). This test intends to capture the status quo. */
21
22#include <monetary.h>
23#include <stdio.h>
24#include <support/support.h>
25#include <support/check.h>
26
27static int
28do_test (void)
29{
30 char buf[40];
31
32 xsetlocale (LC_ALL, locale: "hi_IN.UTF-8");
33
34 /* Ungrouped, not translated. */
35 TEST_COMPARE (sprintf (buf, "%7d", 12345), 7);
36 TEST_COMPARE_STRING (buf, " 12345");
37 TEST_COMPARE (sprintf (buf, "%10.2f", 12345.67), 10);
38 TEST_COMPARE_STRING (buf, " 12345.67");
39 TEST_COMPARE (strfmon (buf, sizeof (buf), "%^13i", 12345.67), 13);
40 TEST_COMPARE_STRING (buf, " INR12345.67");
41
42 /* Grouped. */
43 TEST_COMPARE (sprintf (buf, "%'8d", 12345), 8);
44 TEST_COMPARE_STRING (buf, " 12,345");
45 TEST_COMPARE (sprintf (buf, "%'11.2f", 12345.67), 11);
46 TEST_COMPARE_STRING (buf, " 12,345.67");
47 TEST_COMPARE (strfmon (buf, sizeof (buf), "%13i", 12345.67), 13);
48 TEST_COMPARE_STRING (buf, " INR12,345.67");
49
50 /* Translated. */
51 TEST_COMPARE (sprintf (buf, "%I16d", 12345), 16);
52 TEST_COMPARE_STRING (buf, " १२३४५");
53 TEST_COMPARE (sprintf (buf, "%I12.2f", 12345.67), 26);
54 TEST_COMPARE_STRING (buf, " १२३४५.६७");
55
56 /* Translated and grouped. */
57 TEST_COMPARE (sprintf (buf, "%'I17d", 12345), 17);
58 TEST_COMPARE_STRING (buf, " १२,३४५");
59 TEST_COMPARE (sprintf (buf, "%'I12.2f", 12345.67), 26);
60 TEST_COMPARE_STRING (buf, " १२,३४५.६७");
61
62 xsetlocale (LC_ALL, locale: "ps_AF.UTF-8");
63
64 /* Ungrouped, not translated. */
65 TEST_COMPARE (sprintf (buf, "%7d", 12345), 7);
66 TEST_COMPARE_STRING (buf, " 12345");
67 TEST_COMPARE (sprintf (buf, "%10.2f", 12345.67), 11);
68 TEST_COMPARE_STRING (buf, " 12345٫67");
69 TEST_COMPARE (strfmon (buf, sizeof (buf), "%^13i", 12345.67), 13);
70 TEST_COMPARE_STRING (buf, " 12346 AFN");
71
72 /* Grouped. */
73 TEST_COMPARE (sprintf (buf, "%'8d", 12345), 8);
74 TEST_COMPARE_STRING (buf, " 12٬345");
75 TEST_COMPARE (sprintf (buf, "%'11.2f", 12345.67), 13);
76 TEST_COMPARE_STRING (buf, " 12٬345٫67"); /* Counts characters. */
77 TEST_COMPARE (strfmon (buf, sizeof (buf), "%13i", 12345.67), 13);
78 TEST_COMPARE_STRING (buf, " 12٬346 AFN"); /* Counts bytes. */
79
80 /* Translated. */
81 TEST_COMPARE (sprintf (buf, "%I11d", 12345), 11);
82 TEST_COMPARE_STRING (buf, " ١٢٣۴٥");
83 TEST_COMPARE (sprintf (buf, "%I12.2f", 12345.67), 20);
84 TEST_COMPARE_STRING (buf, " ١٢٣۴٥٫٦٧");
85
86 /* Translated and grouped. */
87 TEST_COMPARE (sprintf (buf, "%'I13d", 12345), 13);
88 TEST_COMPARE_STRING (buf, " ١٢٬٣۴٥");
89 TEST_COMPARE (sprintf (buf, "%'I12.2f", 12345.67), 21);
90 TEST_COMPARE_STRING (buf, " ١٢٬٣۴٥٫٦٧");
91
92 return 0;
93}
94
95#include <support/test-driver.c>
96

source code of glibc/stdio-common/tst-vfprintf-width-i18n.c