blob: 2d9d54c944dccb23a11ae6d1a87977afac13d21a [file] [log] [blame]
lh9ed821d2023-04-07 01:36:19 -07001#include <locale.h>
2#include <stdio.h>
3#include <stdlib.h>
4#include <string.h>
5
6#define NBSP "\xc2\xa0"
7
8static const struct
9{
10 const char *in;
11 const char *out;
12 double expected;
13} tests[] =
14 {
15 { "000"NBSP"000"NBSP"000", "", 0.0 },
16 { "1"NBSP"000"NBSP"000,5x", "x", 1000000.5 }
17 };
18#define NTESTS (sizeof (tests) / sizeof (tests[0]))
19
20
21static int
22do_test (void)
23{
24 if (setlocale (LC_ALL, "cs_CZ.UTF-8") == NULL)
25 {
26 puts ("could not set locale");
27 return 1;
28 }
29
30 int status = 0;
31
32 for (int i = 0; i < NTESTS; ++i)
33 {
34 char *ep;
35 double r = __strtod_internal (tests[i].in, &ep, 1);
36
37 if (strcmp (ep, tests[i].out) != 0)
38 {
39 printf ("%d: got rest string \"%s\", expected \"%s\"\n",
40 i, ep, tests[i].out);
41 status = 1;
42 }
43
44 if (r != tests[i].expected)
45 {
46 printf ("%d: got wrong results %g, expected %g\n",
47 i, r, tests[i].expected);
48 status = 1;
49 }
50 }
51
52 return status;
53}
54
55#define TEST_FUNCTION do_test ()
56#include "../test-skeleton.c"