diff options
| author | Lukasz Kasprzak <lukas@labunix.xyz> | 2026-08-20 15:49:00 +0200 |
|---|---|---|
| committer | Lukasz Kasprzak <lukas@labunix.xyz> | 2026-08-20 15:49:00 +0200 |
| commit | c02e77b73aad34fb5a672a5234a66d64f23b45ce (patch) | |
| tree | bff3ae0751e8005bc4f5448cc2992c3bcad2d86b /test/test_lang.ml | |
| parent | 987175105ead0ea78b960c0e638a81c6fd2384cf (diff) | |
| download | colitur-c02e77b73aad34fb5a672a5234a66d64f23b45ce.tar.gz colitur-c02e77b73aad34fb5a672a5234a66d64f23b45ce.zip | |
feat(lang): read [bible] and [sigla] sections
Lang reads a hardcoded list of section names and ignores anything else
silently, so without this a [bible] section would appear to work and do
nothing -- confirmed directly with a scratch executable: before this
change, of_string on text containing a [bible] section parsed without
error and Lang.keys came back empty, no trace of the section anywhere.
Lang.bible keeps the total-lookup contract every other lookup in this
module has: a miss returns the key itself, never the empty string.
Lang.sigla_fields returns the [sigla] section's raw fields, values
trimmed but still quoted, for Render.style_of_fields to unquote.
[bible] joins the keys reference set so lang --check reports missing
book names; [sigla] deliberately does not, being settings with working
defaults rather than translatable names -- adding it would make --check
demand five settings from every language file.
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 ] ) |
