Command-line and Emacs Calendar Client
at main 2.4 kB view raw
1(* Test the Calendar_dir.module *) 2 3open Caledonia_lib 4 5let calendar_dir_path = Filename.concat (Sys.getcwd ()) "calendar" 6 7let test_list_calendar_names ~fs () = 8 let calendar_dir = 9 match Calendar_dir.create ~fs calendar_dir_path with 10 | Ok dir -> dir 11 | Error (`Msg msg) -> 12 Alcotest.fail ("Calendar directory creation failed: " ^ msg) 13 in 14 match Calendar_dir.list_calendar_names ~fs calendar_dir with 15 | Error (`Msg msg) -> Alcotest.fail ("List calendar_names failed: " ^ msg) 16 | Ok calendar_names -> 17 Alcotest.(check int) 18 "Should find two calendar_names" 2 19 (List.length calendar_names); 20 Alcotest.(check bool) 21 "example should be in the list" true 22 (List.exists (fun c -> c = "example") calendar_names); 23 Alcotest.(check bool) 24 "recurrence should be in the list" true 25 (List.exists (fun c -> c = "recurrence") calendar_names); 26 () 27 28let test_get_calendar_events ~fs () = 29 let calendar_dir = 30 match Calendar_dir.create ~fs calendar_dir_path with 31 | Ok dir -> dir 32 | Error (`Msg msg) -> 33 Alcotest.fail ("Calendar directory creation failed: " ^ msg) 34 in 35 let result = Calendar_dir.get_calendar_events ~fs calendar_dir "example" in 36 match result with 37 | Ok _ -> Alcotest.(check pass) "Should find example calendar_name" () () 38 | Error `Not_found -> Alcotest.fail "Failed to find example calendar_name" 39 | Error (`Msg msg) -> Alcotest.fail ("Error getting calendar_name: " ^ msg) 40 41let test_get_events ~fs () = 42 let calendar_dir = 43 match Calendar_dir.create ~fs calendar_dir_path with 44 | Ok dir -> dir 45 | Error (`Msg msg) -> 46 Alcotest.fail ("Calendar directory creation failed: " ^ msg) 47 in 48 match Calendar_dir.get_events ~fs calendar_dir with 49 | Ok events -> 50 Alcotest.(check int) "Should find two events" 32 (List.length events); 51 () 52 | Error e -> 53 let msg = match e with `Msg m -> m in 54 Alcotest.fail ("Error getting calendar_names: " ^ msg) 55 56let calendar_tests fs = 57 [ 58 ("list calendar_names", `Quick, test_list_calendar_names ~fs); 59 ("get calendar_name", `Quick, test_get_calendar_events ~fs); 60 ("get all calendar_names", `Quick, test_get_events ~fs); 61 ] 62 63let () = 64 Eio_main.run @@ fun env -> 65 let fs = Eio.Stdenv.fs env in 66 Alcotest.run "Calendar_dir.Tests" [ ("calendar", calendar_tests fs) ]