iso8601-tests.el 3.44 KB
Newer Older
Lars Ingebrigtsen's avatar
Lars Ingebrigtsen committed
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68
;;; iso8601-tests.el --- tests for calendar/iso8601.el    -*- lexical-binding:t -*-

;; Copyright (C) 2019 Free Software Foundation, Inc.

;; This file is part of GNU Emacs.

;; GNU Emacs is free software: you can redistribute it and/or modify
;; it under the terms of the GNU General Public License as published by
;; the Free Software Foundation, either version 3 of the License, or
;; (at your option) any later version.

;; GNU Emacs is distributed in the hope that it will be useful,
;; but WITHOUT ANY WARRANTY; without even the implied warranty of
;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
;; GNU General Public License for more details.

;; You should have received a copy of the GNU General Public License
;; along with GNU Emacs.  If not, see <https://www.gnu.org/licenses/>.

;;; Code:

(require 'ert)
(require 'iso8601)

(ert-deftest test-iso8601-date-years ()
  (should (equal (iso8601-parse-date "1985")
                 '(0 0 0 1 1 1985 nil nil nil)))
  (should (equal (iso8601-parse-date "-0003")
                 '(0 0 0 1 1 2 nil nil nil)))
  (should (equal (iso8601-parse-date "+1985")
                 '(0 0 0 1 1 1985 nil nil nil))))

(ert-deftest test-iso8601-date-dates ()
  (should (equal (iso8601-parse-date "1985-03-14")
                 '(0 0 0 14 3 1985 nil nil nil)))
  (should (equal (iso8601-parse-date "19850314")
                 '(0 0 0 14 3 1985 nil nil nil)))
  (should (equal (iso8601-parse-date "1985-02")
                 '(0 0 0 1 2 1985 nil nil nil))))

(ert-deftest test-iso8601-date-obsolete ()
  (should (equal (iso8601-parse-date "--02-01")
                 '(0 0 0 1 2 0 nil nil nil)))
  (should (equal (iso8601-parse-date "--0201")
                 '(0 0 0 1 2 0 nil nil nil))))

(ert-deftest test-iso8601-date-weeks ()
  (should (equal (iso8601-parse-date "2008W39-6")
                 '(0 0 0 27 9 2008 nil nil nil)))
  (should (equal (iso8601-parse-date "2009W01-1")
                 '(0 0 0 29 12 2008 nil nil nil)))
  (should (equal (iso8601-parse-date "2009W53-7")
                 '(0 0 0 3 1 2010 nil nil nil))))

(ert-deftest test-iso8601-date-ordinals ()
  (should (equal (iso8601-parse-date "1981-095")
                 '(0 0 0 5 4 1981 nil nil nil))))

(ert-deftest test-iso8601-time ()
  (should (equal (iso8601-parse-time "13:47:30")
                 '(30 47 13 1 1 0 nil nil nil)))
  (should (equal (iso8601-parse-time "134730")
                 '(30 47 13 1 1 0 nil nil nil)))
  (should (equal (iso8601-parse-time "1347")
                 '(0 47 13 1 1 0 nil nil nil))))

(ert-deftest test-iso8601-combined ()
  (should (equal (iso8601-parse "2008-03-02T13:47:30")
Lars Ingebrigtsen's avatar
Lars Ingebrigtsen committed
69 70 71 72 73 74 75
                 '(30 47 13 2 3 2008 nil nil nil)))
  (should (equal (iso8601-parse "2008-03-02T13:47:30Z")
                 '(30 47 13 2 3 2008 nil nil 0)))
  (should (equal (iso8601-parse "2008-03-02T13:47:30+01:00")
                 '(30 47 13 2 3 2008 nil nil 3600)))
  (should (equal (iso8601-parse "2008-03-02T13:47:30-01")
                 '(30 47 13 2 3 2008 nil nil -3600))))
Lars Ingebrigtsen's avatar
Lars Ingebrigtsen committed
76 77 78 79 80 81 82 83 84 85 86 87

(ert-deftest test-iso8601-duration ()
  (should (equal (iso8601-parse-duration "P3Y6M4DT12H30M5S")
                 '(5 30 12 4 6 3 nil nil nil)))
  (should (equal (iso8601-parse-duration "P1M")
                 '(0 0 0 0 1 0 nil nil nil)))
  (should (equal (iso8601-parse-duration "PT1M")
                 '(0 1 0 0 0 0 nil nil nil)))
  (should (equal (iso8601-parse-duration "P0003-06-04T12:30:05")
                 '(5 30 12 4 6 3 nil nil nil))))

;;; iso8601-tests.el ends here