Add some tests involving leading whitespace.

2006-06-05  Matthias Clasen  <mclasen@redhat.com>

	* tests/strtod-test.c: Add some tests involving
	leading whitespace.

	* glib/gstrfuncs.c (g_ascii_formatd): Skip leading
	whitespace.  (#343899, Øystein Johansen)
This commit is contained in:
Matthias Clasen 2006-06-05 14:16:47 +00:00 committed by Matthias Clasen
parent ef3d67bbec
commit c3d19b850f
4 changed files with 61 additions and 3 deletions

View File

@ -1,3 +1,11 @@
2006-06-05 Matthias Clasen <mclasen@redhat.com>
* tests/strtod-test.c: Add some tests involving
leading whitespace.
* glib/gstrfuncs.c (g_ascii_formatd): Skip leading
whitespace. (#343899, Øystein Johansen)
2006-06-01 Matthias Clasen <mclasen@redhat.com>
* glib/gmain.h:

View File

@ -1,3 +1,11 @@
2006-06-05 Matthias Clasen <mclasen@redhat.com>
* tests/strtod-test.c: Add some tests involving
leading whitespace.
* glib/gstrfuncs.c (g_ascii_formatd): Skip leading
whitespace. (#343899, Øystein Johansen)
2006-06-01 Matthias Clasen <mclasen@redhat.com>
* glib/gmain.h:

View File

@ -30,6 +30,7 @@
#include "config.h"
#define __G_STRFUNCS_C__
#define _GNU_SOURCE /* For stpcpy */
#include <stdarg.h>
@ -94,6 +95,7 @@ g_strdup (const gchar *str)
else
new_str = NULL;
g_mem_mark_type (new_str, G_MEM_TYPE_STRING, 0);
return new_str;
}
@ -129,6 +131,7 @@ g_strndup (const gchar *str,
else
new_str = NULL;
g_mem_mark_type (new_str, G_MEM_TYPE_STRING, 0);
return new_str;
}
@ -187,6 +190,7 @@ g_strdup_vprintf (const gchar *format,
g_vasprintf (&string, format, args);
g_mem_mark_type (string, G_MEM_TYPE_STRING, 0);
return string;
}
@ -355,6 +359,7 @@ g_ascii_strtod (const gchar *nptr,
decimal_point[1] != 0)
{
p = nptr;
/* Skip leading space */
while (g_ascii_isspace (*p))
p++;
@ -568,6 +573,9 @@ g_ascii_formatd (gchar *buffer,
{
p = buffer;
while (g_ascii_isspace (*p))
p++;
if (*p == '+' || *p == '-')
p++;
@ -1582,7 +1590,8 @@ g_ascii_strdown (const gchar *str,
result = g_strndup (str, len);
for (s = result; *s; s++)
*s = g_ascii_tolower (*s);
g_mem_mark_type (result, G_MEM_TYPE_STRING, 0);
return result;
}
@ -1614,6 +1623,7 @@ g_ascii_strup (const gchar *str,
for (s = result; *s; s++)
*s = g_ascii_toupper (*s);
g_mem_mark_type (result, G_MEM_TYPE_STRING, 0);
return result;
}

View File

@ -10,11 +10,12 @@
#include <stdlib.h>
#include <math.h>
static char *locales[] = {"sv_SE", "en_US", "fa_IR", "C", "ru_RU"};
void
test_string (char *number, double res, gboolean check_end, int correct_len)
{
double d;
char *locales[] = {"sv_SE", "en_US", "fa_IR", "C", "ru_RU"};
int l;
char *dummy;
@ -59,6 +60,19 @@ test_string (char *number, double res, gboolean check_end, int correct_len)
}
static void
test_number (gdouble num, gchar *fmt, gchar *str)
{
int l;
gchar buf[G_ASCII_DTOSTR_BUF_SIZE];
for (l = 0; l < G_N_ELEMENTS (locales); l++)
{
g_ascii_formatd (buf, G_ASCII_DTOSTR_BUF_SIZE, fmt, num);
g_assert (strcmp (buf, str) == 0);
}
}
int
main ()
{
@ -108,7 +122,25 @@ main ()
d = -pow (2.0, -1024.1);
g_assert (d == g_ascii_strtod (g_ascii_dtostr (buffer, sizeof (buffer), d), NULL));
/* for #343899 */
test_string (" 0.75", 0.75, FALSE, 0);
test_string (" +0.75", 0.75, FALSE, 0);
test_string (" -0.75", -0.75, FALSE, 0);
test_string ("\f0.75", 0.75, FALSE, 0);
test_string ("\n0.75", 0.75, FALSE, 0);
test_string ("\r0.75", 0.75, FALSE, 0);
test_string ("\t0.75", 0.75, FALSE, 0);
#if 0
/* g_ascii_isspace() returns FALSE for vertical tab, see #59388 */
test_string ("\v0.75", 0.75, FALSE, 0);
#endif
/* for #343899 */
test_number (0.75, "%0.2f", "0.75");
test_number (0.75, "%5.2f", " 0.75");
test_number (-0.75, "%0.2f", "-0.75");
test_number (-0.75, "%5.2f", "-0.75");
test_number (1e99, "%.0e", "1e+99");
return 0;
}