diff options
Diffstat (limited to 'test/test_lang.ml')
| -rw-r--r-- | test/test_lang.ml | 48 |
1 files changed, 47 insertions, 1 deletions
diff --git a/test/test_lang.ml b/test/test_lang.ml index c9b7f1a..59bb9a0 100644 --- a/test/test_lang.ml +++ b/test/test_lang.ml @@ -104,6 +104,48 @@ let test_duplicate_key_within_section_last_wins () = let t = ok (L.of_string "[meta]\nlang = la\n[celebration]\na = FIRST\na = SECOND\n") in Alcotest.(check string) "later line's value wins" "SECOND" (L.celebration t "a") +(* Task 6: [bible] and [sigla] used to be two more section names [of_string] + never looked for -- a tenth (or eleventh) section a file author writes was + silently ignored, not rejected. Verified directly against a checked-out + scratch executable before this change: [Lang.keys] on a table built from + text containing a [bible] section came back with zero entries, no error + either. *) +let test_bible_section_is_read () = + let text = "[meta]\nlang = xx\n[bible]\nluke.abbr = Lc\nluke.full = Ewangelia\n" in + match L.of_string text with + | Error e -> Alcotest.failf "parse: %s" e + | Ok t -> + Alcotest.(check string) "abbr" "Lc" (L.bible t "luke.abbr"); + Alcotest.(check string) "full" "Ewangelia" (L.bible t "luke.full"); + (* the TOTAL contract: a miss returns the key *) + Alcotest.(check string) "miss" "mark.abbr" (L.bible t "mark.abbr") + +let test_sigla_section_is_read () = + let text = "[meta]\nlang = xx\n[sigla]\nbook = full\npart_sep = \"; \"\n" in + match L.of_string text with + | Error e -> Alcotest.failf "parse: %s" e + | Ok t -> + let f = L.sigla_fields t in + Alcotest.(check (option string)) "book" (Some "full") (List.assoc_opt "book" f); + (* the quotes survive Lang; Render.style_of_fields strips them *) + Alcotest.(check (option string)) "sep" (Some "\"; \"") (List.assoc_opt "part_sep" f) + +(* The deliberate asymmetry: [bible] joins [keys] (lang --check's reference + set, so a translation missing every book name is reported as incomplete); + [sigla] does not (it is five settings with working defaults, not names a + translator owes -- putting it in [keys] would make --check demand five + settings from every language file). Pinned so a later change here is a + deliberate one, not a drive-by. *) +let test_check_demands_bible_not_sigla () = + let text = "[meta]\nlang = xx\n[bible]\nluke.abbr = Lc\n[sigla]\nbook = full\n" in + match L.of_string text with + | Error e -> Alcotest.failf "parse: %s" e + | Ok t -> + let ks = L.keys t in + Alcotest.(check bool) "bible in keys" true (List.mem_assoc "bible.luke.abbr" ks); + Alcotest.(check bool) "sigla not in keys" false + (List.exists (fun (k, _) -> String.length k > 6 && String.sub k 0 6 = "sigla.") ks) + let suite = ( "Lang", [ Alcotest.test_case "meta" `Quick test_meta; @@ -117,4 +159,8 @@ let suite = Alcotest.test_case "duplicate key across sections: last wins" `Quick test_duplicate_key_across_sections_last_wins; Alcotest.test_case "duplicate key within section: last wins" `Quick - test_duplicate_key_within_section_last_wins ] ) + test_duplicate_key_within_section_last_wins; + Alcotest.test_case "bible section is read" `Quick test_bible_section_is_read; + Alcotest.test_case "sigla section is read" `Quick test_sigla_section_is_read; + Alcotest.test_case "check demands bible not sigla" `Quick + test_check_demands_bible_not_sigla ] ) |
