[glib/wip/pwithnall/freebsd-math: 3/3] tests: Add more tests for GDateTime ISO 8601 seconds parsing




commit 580170ab87f275d2e95873cc41a7afa410ac8112
Author: Philip Withnall <pwithnall endlessos org>
Date:   Fri Dec 11 15:41:42 2020 +0000

    tests: Add more tests for GDateTime ISO 8601 seconds parsing
    
    This should add a few more lines/branches to the test coverage.
    
    Signed-off-by: Philip Withnall <pwithnall endlessos org>

 glib/tests/gdatetime.c | 30 ++++++++++++++++++++++++++++++
 1 file changed, 30 insertions(+)
---
diff --git a/glib/tests/gdatetime.c b/glib/tests/gdatetime.c
index 0e6b5bdd3..72537f4e1 100644
--- a/glib/tests/gdatetime.c
+++ b/glib/tests/gdatetime.c
@@ -743,6 +743,14 @@ test_GDateTime_new_from_iso8601 (void)
   dt = g_date_time_new_from_iso8601 ("--0824T22:10:42Z", NULL);
   g_assert_null (dt);
 
+  /* Seconds must be two digits. */
+  dt = g_date_time_new_from_iso8601 ("2016-08-10T22:10:4Z", NULL);
+  g_assert_null (dt);
+
+  /* Seconds must all be digits. */
+  dt = g_date_time_new_from_iso8601 ("2016-08-10T22:10:4aZ", NULL);
+  g_assert_null (dt);
+
   /* Check subseconds work */
   dt = g_date_time_new_from_iso8601 ("2016-08-24T22:10:42.123456Z", NULL);
   ASSERT_DATE (dt, 2016, 8, 24);
@@ -759,6 +767,28 @@ test_GDateTime_new_from_iso8601 (void)
   ASSERT_TIME (dt, 22, 10, 42, 123456);
   g_date_time_unref (dt);
 
+  /* Subseconds must all be digits. */
+  dt = g_date_time_new_from_iso8601 ("2016-08-10T22:10:42.5aZ", NULL);
+  g_assert_null (dt);
+
+  /* Subseconds can be an arbitrary length, but must not overflow.
+   * The ASSERT_TIME() comparisons are constrained by only comparing up to
+   * microsecond granularity. */
+  dt = g_date_time_new_from_iso8601 ("2016-08-10T22:10:09.222222222222222222Z", NULL);
+  ASSERT_DATE (dt, 2016, 8, 10);
+  ASSERT_TIME (dt, 22, 10, 9, 222222);
+  g_date_time_unref (dt);
+  dt = g_date_time_new_from_iso8601 ("2016-08-10T22:10:09.2222222222222222222Z", NULL);
+  g_assert_null (dt);
+
+  /* Small numerator, large divisor when parsing the subseconds. */
+  dt = g_date_time_new_from_iso8601 ("2016-08-10T22:10:00.0000000000000000001Z", NULL);
+  ASSERT_DATE (dt, 2016, 8, 10);
+  ASSERT_TIME (dt, 22, 10, 0, 0);
+  g_date_time_unref (dt);
+  dt = g_date_time_new_from_iso8601 ("2016-08-10T22:10:00.00000000000000000001Z", NULL);
+  g_assert_null (dt);
+
   /* We don't support times without minutes / seconds (valid ISO 8601) */
   dt = g_date_time_new_from_iso8601 ("2016-08-24T22Z", NULL);
   g_assert_null (dt);


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]