summaryrefslogtreecommitdiff
path: root/tests/basic-types
diff options
context:
space:
mode:
authorRico Tzschichholz <ricotz@ubuntu.com>2017-03-10 08:05:48 +0100
committerRico Tzschichholz <ricotz@ubuntu.com>2017-11-20 15:34:31 +0100
commit1eb5044ff3be0546fa6fee64ae250323204ded5c (patch)
tree371e387d6e5ad4dba514a1b6404b146b5619c6e1 /tests/basic-types
parent78a92305831911b27c2e962fdd41fc12771d5ffa (diff)
downloadvala-1eb5044ff3be0546fa6fee64ae250323204ded5c.tar.gz
glib-2.0: Add optional 'unparsed' parameter to *.try_parse ()
This reintroduces a dropped feature of string.to_*() while returning the maybe available unparsed part of the string. https://bugzilla.gnome.org/show_bug.cgi?id=774124
Diffstat (limited to 'tests/basic-types')
-rw-r--r--tests/basic-types/floats.vala5
-rw-r--r--tests/basic-types/integers.vala14
2 files changed, 19 insertions, 0 deletions
diff --git a/tests/basic-types/floats.vala b/tests/basic-types/floats.vala
index 3f6eaa18e..e0e8aef6b 100644
--- a/tests/basic-types/floats.vala
+++ b/tests/basic-types/floats.vala
@@ -45,6 +45,11 @@ void test_double () {
string s = d.to_string ();
assert (s == "42");
+ unowned string unparsed;
+ double.try_parse ("3.45mm", out d, out unparsed);
+ assert (d == 3.45);
+ assert (unparsed == "mm");
+
// ensure that MIN and MAX are valid values
d = double.MIN;
assert (d == double.MIN);
diff --git a/tests/basic-types/integers.vala b/tests/basic-types/integers.vala
index 40eebfae6..4e91071b0 100644
--- a/tests/basic-types/integers.vala
+++ b/tests/basic-types/integers.vala
@@ -70,6 +70,20 @@ void test_int () {
string s = i.to_string ();
assert (s == "42");
+ unowned string unparsed;
+ int64 i64;
+ int64.try_parse ("-4711inch", out i64, out unparsed);
+ assert (i64 == -4711);
+ assert (unparsed == "inch");
+ int64.try_parse ("-31415km", out i64);
+ assert (i64 == -31415);
+ uint64 ui64;
+ uint64.try_parse ("4711yards", out ui64, out unparsed);
+ assert (ui64 == 4711);
+ assert (unparsed == "yards");
+ uint64.try_parse ("31415yards", out ui64);
+ assert (ui64 == 31415);
+
// ensure that MIN and MAX are valid values
i = int.MIN;
assert (i == int.MIN);