test-rfc3339.ss
#! /usr/bin/env mzscheme
;; See file rfc3339.ss for legal info.
;; $Id: test-rfc3339.ss,v 1.2 2009/03/04 01:53:00 neilpair Exp $

#lang scheme/base

(require (planet neil/testeez:1:2)
         "rfc3339.ss")

(testeez
 "rfc3339"

 ;;

 ;;  (test/equal "leap years"
 ;;              (map %rfc3339:leap-year? '(1600 1984 1996 2000 2400))
 ;;              '(#t #t #t #t #t))
 ;;
 ;;  (test/equal "non-leap years"
 ;;              (map %rfc3339:leap-year? '(1700 1800 1899 1900 2100))
 ;;              '(#f #f #f #f #f))
 
 ;;

 (test/equal ""
             (rfc3339-string->list "1985-04-12T23:20:50.52Z")
             '(1985 4 12 23 20 50 0.52 0))

 (test/equal ""
             (rfc3339-string->list "1985-04-12T23:20:50.52")
             '(1985 4 12 23 20 50 0.52 #f))

 (test/equal ""
             (rfc3339-string->list "1985-04-12T23:20:50")
             '(1985 4 12 23 20 50 #f #f))

 (test/equal ""
             (rfc3339-string->list "1985-04-12T23:20")
             '(1985 4 12 23 20 #f #f #f))

 (test/equal ""
             (rfc3339-string->list "1985-04-12T23")
             '(1985 4 12 23 #f #f #f #f))

 (test/equal ""
             (rfc3339-string->list "1985-04-12T")
             '(1985 4 12 #f #f #f #f #f))

 (test/equal ""
             (rfc3339-string->list "1985-04-12")
             '(1985 4 12 #f #f #f #f #f))

 (test/equal ""
             (rfc3339-string->list "1985-04")
             '(1985 4 #f #f #f #f #f #f))

 (test/equal ""
             (rfc3339-string->list "1985")
             '(1985 #f #f #f #f #f #f #f))

 ;;

 (test/equal
  ""
  (rfc3339-record->string (string->rfc3339-record "1111-11-11T11:11:11.123"))
  "1111-11-11T11:11:11.123")

 (test/equal
  ""
  (rfc3339-record->string (string->rfc3339-record "1111-11-11T11:11:11"))
  "1111-11-11T11:11:11")

 (test/equal
  ""
  (rfc3339-record->string (string->rfc3339-record "1111-11-11T11:11:11.0"))
  "1111-11-11T11:11:11.0")

 ;;

 (test/equal ""
             (rfc3339-record->string (string->rfc3339-record "1-1-1"))
             "0001-01-01")

 (test/equal ""
             (rfc3339-record->string (string->rfc3339-record "1:1:1"))
             "01:01:01")

 ;;

 (test/equal
  "" (rfc3339-record->string (string->rfc3339-record "T+0:0")) "Z")
 (test/equal
  "" (rfc3339-record->string (string->rfc3339-record "+0:0"))  "Z")
 (test/equal
  "" (rfc3339-record->string (string->rfc3339-record "T-0:0")) "Z")
 (test/equal
  "" (rfc3339-record->string (string->rfc3339-record "-0:0"))  "Z")
 (test/equal
  "" (rfc3339-record->string (string->rfc3339-record "TZ"))    "Z")
 (test/equal
  "" (rfc3339-record->string (string->rfc3339-record "Z"))     "Z")

 (test/equal
  "" (rfc3339-record->string (string->rfc3339-record "+0:01"))   "+0:01")
 (test/equal
  "" (rfc3339-record->string (string->rfc3339-record "+000:01")) "+0:01")

 ;;

 (test/equal
  "" (rfc3339-record->string (string->rfc3339-record "T12:34")) "12:34:00")
 (test/equal
  "" (rfc3339-record->string (string->rfc3339-record "12:34"))  "12:34:00"))