1 (*i $Id: test_printer.ml,v 1.9 2008/07/07 09:42:17 signoles Exp $ i*)
3 Printf.printf "Tests of Printer:\n";;
10 let d = Date.make 2003 1 6;;
11 test (sprint "%D" d = "01/06/03") "sprint %D";;
12 test (sprint "the date is %B, the %-dth" d = "the date is January, the 6th")
13 "sprint (long sentence)";;
14 test (sprint "%j" d = "006") "sprint %j";;
15 test (sprint "%-j" d = "6") "sprint %j";;
16 test (sprint "%_j" d = " 6") "sprint %j";;
17 test (sprint "%j" (Date.make 2003 1 10) = "010") "sprint %j";;
18 test (sprint "%-j" (Date.make 2003 1 10) = "10") "sprint %j";;
19 test (sprint "%_j" (Date.make 2003 1 10) = " 10") "sprint %j";;
20 test (from_string "2003-01-06" = Date.make 2003 1 6) "from_string";;
21 test (from_fstring "%y-%m-%d" "03-01-06" = Date.make 1903 1 6) "from_fstring";;
23 (from_fstring "%Y%t%m%t%d" "1903\t01\t06" = Date.make 1903 1 6)
26 (from_fstring "%Y-%B-%d" "2007-May-14" = Date.make 2007 5 14)
30 (from_fstring "%Y-%b-%d" "2007-Jan-14" = Date.make 2007 1 14)
33 test (from_fstring "%Y %V %w" "2004 01 1" = Date.make 2003 12 29)
34 "from_fstring %Y %V %w";;
35 test (from_fstring "%V %Y %w" "52 1999 7" = Date.make 2000 1 2)
36 "from_fstring %w %Y %V";;
37 test_exn (lazy (from_fstring "%Y %w" "1999 7")) "from_fstring_exn";;
38 test (from_fstring "%Y%j" "1903001" = Date.make 1903 1 1) "from_fstring %Y%j";;
39 test (from_fstring "%j%Y" "0011903" = Date.make 1903 1 1) "from_fstring %j%Y";;
40 test_exn (lazy (from_fstring "%j" "001")) "from_fstring_exn 2";;
43 test (to_string (Time.make 12 1 4) = "12:01:04") "to_string (on TimePrinter)";;
44 test (sprint "%I" (Time.make 36 4 3) = "12") "sprint %I (on TimePrinter)";;
45 test (sprint "%r" (Time.make 24 4 3) = "12:04:03 AM")
46 "sprint %r (on TimePrinter)";;
47 test (from_fstring "%r" "10:47:25 AM" = Time.make 10 47 25)
48 "from_fstring AM (on TimePrinter)";;
49 test (from_fstring "%r" "10:47:25 PM" = Time.make 22 47 25)
50 "from_fstring PM (on TimePrinter)";;
51 test_exn (lazy (from_fstring "%p %I:%M:%S" "TM 5:26:17"))
52 "from_fstring error on %p (on TimePrinter)";;
54 open Printer.Calendar;;
55 test (sprint "%c" (Calendar.make 2003 1 6 12 1 4) = "Mon Jan 06 12:01:04 2003")
57 test (to_string (Calendar.make 2004 10 25 24 0 1) = "2004-10-26 00:00:01")
58 "to_string (on CalendarPrinter)";;
60 (from_fstring "%c" "Mon May 14 10:30:00 2007"
61 = Calendar.make 2007 5 14 10 30 0)
62 "from_fstring (on CalendarPrinter)";;
66 Printf.printf "tests ok : %d; tests ko : %d\n" ok bug;;