Advertisement
Guest User

Untitled

a guest
Dec 15th, 2016
567
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Vala 1.47 KB | None | 0 0
  1. /*
  2.  * Copyright 2016 Michael Gratton <mike@vee.net>
  3.  *
  4.  * This software is licensed under the GNU Lesser General Public License
  5.  * (version 2.1 or later). See the COPYING file in this distribution.
  6.  */
  7.  
  8. class Geary.RFC822.DateTest : Gee.TestCase {
  9.  
  10.     public DateTest() {
  11.         base("Geary.RFC822.DateTest");
  12.         add_test("is_valid_date", is_valid_date);
  13.     }
  14.  
  15.     // ISO 8601 "2006-08-14T02:34:56-06:00"
  16.     // RFC5322 -> RFC2822 -> RFC822 "Wed, 24 Oct 2009 14:31:12 EST"
  17.     // new date (8601)
  18.     private void test_date(string? input, string? expected, bool should_throw) {
  19.         try {
  20.             string val = new Geary.RFC822.Date(input).to_iso_8601();
  21.  
  22.             assert(val == expected);
  23.             assert_true(!should_throw);
  24.         } catch (Error e) {
  25.             assert_true(should_throw);
  26.         }
  27.     }
  28.  
  29.     public void is_valid_date() {
  30.         test_date("2016-12-13T18:09:07+01:00", "2016-12-13T18:09:07+01:00", false);
  31.         test_date("Mon, 24 Oct 2016 14:31:12 EST", "2016-10-24T21:31:12+02:00", false);
  32.         test_date("Mon, 24 Oct 2016 14:31:12 GMT", "2016-10-24T16:31:12+02:00", false);
  33.         test_date("Mon, 24 Oct 2016 14:31:12 +0400", "2016-10-24T12:31:12+02:00", false);
  34.  
  35.         test_date("Thu, 21 Jan 1970 00:00:00 +0000", "1970-01-21T01:00:00+01:00", false);
  36.         test_date("Thu, 01 Jan 1970 00:00:00 +0000", "1970-01-01T01:00:00+01:00", false);
  37.  
  38.         test_date("2002-10-02T08:00:00-05:00", null, true);
  39.     }
  40. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement