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