mirror of
https://gitlab.gnome.org/GNOME/glib.git
synced 2025-05-25 06:50:40 +02:00
tests: Add a basic test for GScanner’s int_2_float
configuration
I can see why use of `GScanner` is discouraged. Eww. See https://gitlab.gnome.org/GNOME/glib/-/merge_requests/4387/diffs#note_2269329 Choose a large enough int to cause problems if `long` storage isn’t used throughout the parse chain. Signed-off-by: Philip Withnall <pwithnall@gnome.org>
This commit is contained in:
parent
8e39ad2660
commit
d4245f70d4
@ -156,6 +156,28 @@ test_scanner_multiline_comment (void)
|
||||
g_scanner_destroy (scanner);
|
||||
}
|
||||
|
||||
static void
|
||||
test_scanner_int_to_float (void)
|
||||
{
|
||||
GScanner *scanner = NULL;
|
||||
const char buf[] = "4294967295";
|
||||
const size_t buflen = strlen (buf);
|
||||
|
||||
scanner = g_scanner_new (NULL);
|
||||
scanner->config->int_2_float = TRUE;
|
||||
|
||||
g_scanner_input_text (scanner, buf, buflen);
|
||||
|
||||
g_assert_cmpint (g_scanner_cur_token (scanner), ==, G_TOKEN_NONE);
|
||||
g_scanner_get_next_token (scanner);
|
||||
g_assert_cmpint (g_scanner_cur_token (scanner), ==, G_TOKEN_FLOAT);
|
||||
g_assert_cmpint (g_scanner_cur_line (scanner), ==, 1);
|
||||
g_assert_cmpfloat (g_scanner_cur_value (scanner).v_float, ==, 4294967295.0);
|
||||
g_assert_cmpint (g_scanner_get_next_token (scanner), ==, G_TOKEN_EOF);
|
||||
|
||||
g_scanner_destroy (scanner);
|
||||
}
|
||||
|
||||
static void
|
||||
test_scanner_fd_input (void)
|
||||
{
|
||||
@ -286,6 +308,7 @@ main (int argc,
|
||||
g_test_add ("/scanner/symbols", ScannerFixture, 0, scanner_fixture_setup, test_scanner_symbols, scanner_fixture_teardown);
|
||||
g_test_add ("/scanner/tokens", ScannerFixture, 0, scanner_fixture_setup, test_scanner_tokens, scanner_fixture_teardown);
|
||||
g_test_add_func ("/scanner/multiline-comment", test_scanner_multiline_comment);
|
||||
g_test_add_func ("/scanner/int-to-float", test_scanner_int_to_float);
|
||||
g_test_add_func ("/scanner/fd-input", test_scanner_fd_input);
|
||||
g_test_add_func ("/scanner/fd-input/rewind", test_scanner_fd_input_rewind);
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user