diff options
author | djcb <djcb@djcbsoftware.nl> | 2015-08-18 16:18:02 +0300 |
---|---|---|
committer | Emmanuele Bassi <ebassi@gnome.org> | 2017-03-13 09:20:45 +0000 |
commit | b9007d48d0a3f3d819d727d825fa589fa9cc9557 (patch) | |
tree | 032de0364912a52287c26593b50e334ef91e43e7 /json-glib/tests/generator.c | |
parent | 41dbbd6fd7b45c850e2942c2259f2bb23bfe52ef (diff) | |
download | json-glib-b9007d48d0a3f3d819d727d825fa589fa9cc9557.tar.gz |
Don't loose decimal in whole-double -> string conversion
When converting json to its string representation, whole-doubles (such
as 1.0) would be converted into strings without decimals ("1"). That can
be inconvenient e.g. when converting from/to GVariants.
To avoid this, append '.0' to the string representation for doubles if
they lost their decimals in the conversion.
Also add / update unit tests for this.
https://bugzilla.gnome.org/show_bug.cgi?id=753763
Diffstat (limited to 'json-glib/tests/generator.c')
-rw-r--r-- | json-glib/tests/generator.c | 22 |
1 files changed, 22 insertions, 0 deletions
diff --git a/json-glib/tests/generator.c b/json-glib/tests/generator.c index 79b6887..e7dabff 100644 --- a/json-glib/tests/generator.c +++ b/json-glib/tests/generator.c @@ -335,6 +335,27 @@ test_decimal_separator (void) json_node_free (node); } + +static void +test_double_stays_double (void) +{ + gchar *str; + JsonNode *node = json_node_new (JSON_NODE_VALUE); + JsonGenerator *generator = json_generator_new (); + + json_node_set_double (node, 1.0); + + json_generator_set_root (generator, node); + + str = json_generator_to_data (generator, NULL); + g_assert_cmpstr (str, ==, "1.0"); + + g_free (str); + g_object_unref (generator); + json_node_free (node); +} + + static void test_pretty (void) { @@ -427,6 +448,7 @@ main (int argc, g_test_add_func ("/generator/simple-object", test_simple_object); g_test_add_func ("/generator/nested-object", test_nested_object); g_test_add_func ("/generator/decimal-separator", test_decimal_separator); + g_test_add_func ("/generator/double-stays-double", test_double_stays_double); g_test_add_func ("/generator/pretty", test_pretty); for (i = 0; i < G_N_ELEMENTS (string_fixtures); i++) |