diff options
Diffstat (limited to 'test')
| -rw-r--r-- | test/test_names.ml | 32 |
1 files changed, 31 insertions, 1 deletions
diff --git a/test/test_names.ml b/test/test_names.ml index 6089b5f..9db8217 100644 --- a/test/test_names.ml +++ b/test/test_names.ml @@ -25,6 +25,24 @@ let test_names_set_remove () = let n = N.remove n (lang "en") in Alcotest.(check (option string)) "removed" None (N.find n (lang "en")) +let test_names_of_list_duplicates () = + (* of_list with duplicate language: last entry wins *) + let n = N.of_list [ (lang "en", "Easter"); (lang "en", "Easter Sunday") ] in + Alcotest.(check (option string)) "of_list last wins" (Some "Easter Sunday") (N.find n (lang "en")) + +let test_names_sexp_canonical () = + (* Two Names.t with different input order must serialize identically *) + let n1 = N.of_list [ (lang "pl", "Wielkanoc"); (lang "la", "Pascha"); (lang "en", "Easter") ] in + let n2 = N.of_list [ (lang "en", "Easter"); (lang "pl", "Wielkanoc"); (lang "la", "Pascha") ] in + Alcotest.(check bool) "same sexp despite different input order" + true (N.sexp_of_t n1 = N.sexp_of_t n2) + +let test_names_sexp_roundtrip () = + let n = N.of_list [ (lang "la", "Pascha"); (lang "en", "Easter") ] in + let sexp = N.sexp_of_t n in + let n' = N.t_of_sexp sexp in + Alcotest.(check bool) "sexp roundtrip" true (n = n') + let test_citation () = let c = { C.part = C.Gospel; reference = "Jn 3:16" } in Alcotest.(check bool) "sexp roundtrip" true (C.t_of_sexp (C.sexp_of_t c) = c); @@ -48,9 +66,21 @@ let test_date_spec () = Alcotest.(check bool) "reject Apr 31" true (Result.is_error (DS.fixed ~month:4 ~day:31)); Alcotest.(check bool) "reject month 13" true (Result.is_error (DS.fixed ~month:13 ~day:1)) +let test_date_spec_sexp_roundtrip () = + (match DS.fixed ~month:3 ~day:25 with + | Ok ds -> + let sexp = DS.sexp_of_t ds in + let ds' = DS.t_of_sexp sexp in + Alcotest.(check bool) "sexp roundtrip" true (ds = ds') + | Error e -> Alcotest.failf "fixed: %s" e) + let suite = ( "Names/Citation/DateSpec", [ Alcotest.test_case "names basics" `Quick test_names_basics; Alcotest.test_case "names set/remove" `Quick test_names_set_remove; + Alcotest.test_case "names of_list duplicates" `Quick test_names_of_list_duplicates; + Alcotest.test_case "names sexp canonical" `Quick test_names_sexp_canonical; + Alcotest.test_case "names sexp roundtrip" `Quick test_names_sexp_roundtrip; Alcotest.test_case "citation" `Quick test_citation; - Alcotest.test_case "date_spec" `Quick test_date_spec ] ) + Alcotest.test_case "date_spec" `Quick test_date_spec; + Alcotest.test_case "date_spec sexp roundtrip" `Quick test_date_spec_sexp_roundtrip ] ) |
