diff options
Diffstat (limited to 'test')
| -rw-r--r-- | test/cli.t | 99 | ||||
| -rw-r--r-- | test/test_config.ml | 35 |
2 files changed, 121 insertions, 13 deletions
@@ -1258,10 +1258,13 @@ literally either): $ XDG_CONFIG_HOME=xdg-test colitur config --show config file: xdg-test/colitur/config.ini (not found) - lang la (default) - template (none) (default) - format (none) (default) - overlay (none) (default) + lang la (default) + template (none) (default) + format (none) (default) + sigla_style la (default) + sigla_book abbr (default) + sigla_tradition vulgate (default) + overlay (none) (default) A flag on the SAME command line previews exactly what it would resolve to on any other command -- `overlay` has no single scalar value, so it is @@ -1269,10 +1272,13 @@ listed one line per effective entry instead: $ XDG_CONFIG_HOME=xdg-test colitur config --show --lang fr --overlay mine.sexp config file: xdg-test/colitur/config.ini (not found) - lang fr (flag) - template (none) (default) - format (none) (default) - overlay mine.sexp (flag) + lang fr (flag) + template (none) (default) + format (none) (default) + sigla_style fr (default) + sigla_book abbr (default) + sigla_tradition vulgate (default) + overlay mine.sexp (flag) A real config file supplies a default that a command with no explicit flag then uses. An unrecognised key and an unrecognised section are each warned @@ -1284,13 +1290,82 @@ differently from a misspelled key inside a recognised one: $ printf '[defaults]\nlang = en\noverlay = /nonexistent/parish.sexp\nbogus = 1\n\n[deafults]\nlang = xx\n' > xdg-test/colitur/config.ini $ XDG_CONFIG_HOME=xdg-test colitur config --show config file: xdg-test/colitur/config.ini (exists) - lang en (config) - template (none) (default) - format (none) (default) - overlay /nonexistent/parish.sexp (config) + lang en (config) + template (none) (default) + format (none) (default) + sigla_style en (default) + sigla_book abbr (default) + sigla_tradition vulgate (default) + overlay /nonexistent/parish.sexp (config) colitur: xdg-test/colitur/config.ini: unknown setting "bogus" (ignored) colitur: xdg-test/colitur/config.ini: unknown section [deafults] (ignored) +`--sigla-style`/`--sigla-book`/`--sigla-tradition` (Task 8) resolve through +the identical flag > config > default precedence as --lang/--template/ +--format, each reported by its own row. `sigla_style` defaults to the +RESOLVED language, not a literal "la" -- a booklet that asked for a +different --lang gets its citations in that language too unless told +otherwise. Run through a fresh XDG_CONFIG_HOME, so this does not depend on +the config file the earlier examples left behind: + + $ XDG_CONFIG_HOME=xdg-sigla colitur config --show --sigla-style pl --sigla-book full --sigla-tradition modern + config file: xdg-sigla/colitur/config.ini (not found) + lang la (default) + template (none) (default) + format (none) (default) + sigla_style pl (flag) + sigla_book full (flag) + sigla_tradition modern (flag) + overlay (none) (default) + +An unrecognised `--sigla-book` is a hard usage ERROR -- exit 2, one line on +stderr -- the same discipline an unrecognised `--lang` gets, never a silent +fallback: `Colitur_citation.Render.with_book` takes a closed variant, not an +arbitrary string, so anything other than "full"/"abbr" could never mean +anything downstream. + + $ XDG_CONFIG_HOME=xdg-sigla colitur config --show --sigla-book bogus + config file: xdg-sigla/colitur/config.ini (not found) + lang la (default) + template (none) (default) + format (none) (default) + sigla_style la (default) + colitur: unknown --sigla-book "bogus" (want "full" or "abbr") + [2] + +An unrecognised `--sigla-tradition`, by contrast, is NOT fatal: it is +resolved for real against lang/traditions.ini (the same reader a future +renderer will use), and a name matching no section there degrades to the +Vulgate with a warning on stderr, exactly as an unknown tradition does +everywhere else in this project -- asking for a renumbering is optional the +way asking for a language is not, so a run is not lost over a typo here. +The warning itself carries lang/traditions.ini's own resolved PATH, which is +absolute and build-tree-specific -- grepped for rather than matched in +full, the same way the pre-existing "unknown language" case above already +sidesteps that same non-portability: + + $ XDG_CONFIG_HOME=xdg-sigla colitur config --show --sigla-tradition nonsense 2>/dev/null + config file: xdg-sigla/colitur/config.ini (not found) + lang la (default) + template (none) (default) + format (none) (default) + sigla_style la (default) + sigla_book abbr (default) + sigla_tradition nonsense (flag) + overlay (none) (default) + $ XDG_CONFIG_HOME=xdg-sigla colitur config --show --sigla-tradition nonsense 2>&1 >/dev/null | grep -c 'no tradition "nonsense"; falling back to the Vulgate' + 1 + +`--sigla-style`/`--sigla-book`/`--sigla-tradition` have no effect on any +other command yet -- resolving and reporting them is all this build does; +actually rendering a citation through them is a later task -- refused +rather than silently ignored, the same discipline `--dump`/`--check`/ +`--list`/`--show` already get above: + + $ colitur day 2027 --sigla-style la > /dev/null + colitur: --sigla-style/--sigla-book/--sigla-tradition have no effect on `day`; refusing rather than ignoring them + [2] + `config` requires --show: $ colitur config diff --git a/test/test_config.ml b/test/test_config.ml index 83da015..d348d9b 100644 --- a/test/test_config.ml +++ b/test/test_config.ml @@ -102,6 +102,35 @@ let test_two_defaults_blocks_report_no_unknown_sections () = let c = ok (C.of_string text) in Alcotest.(check (list string)) "no unknown sections" [] (C.unknown_sections c) +(* Task 8: sigla_style/sigla_book/sigla_tradition read the same way + lang/template/format do, in the same [\[defaults\]] section -- no new + section, and every key recognised (so [unknown_keys] stays empty). *) +let test_sigla_keys_are_read () = + let text = + "[defaults]\nsigla_style = la\nsigla_book = full\nsigla_tradition = modern\n" + in + match C.of_string text with + | Error e -> Alcotest.failf "parse: %s" e + | Ok c -> + Alcotest.(check (option string)) "style" (Some "la") (C.sigla_style c); + Alcotest.(check (option string)) "book" (Some "full") (C.sigla_book c); + Alcotest.(check (option string)) "tradition" (Some "modern") (C.sigla_tradition c); + Alcotest.(check (list string)) "nothing unknown" [] (C.unknown_keys c) + +(* The empty config carries no sigla settings either -- same "all None" + contract [test_empty_config_is_all_none] already asserts for lang. *) +let test_empty_config_sigla_keys_are_none () = + Alcotest.(check (option string)) "sigla_style" None (C.sigla_style C.empty); + Alcotest.(check (option string)) "sigla_book" None (C.sigla_book C.empty); + Alcotest.(check (option string)) "sigla_tradition" None (C.sigla_tradition C.empty) + +(* Same last-wins duplicate policy as lang/template/format: a key repeated + across two [\[defaults\]] blocks resolves to the LATER block's value. *) +let test_sigla_key_repeated_across_blocks_last_wins () = + let text = "[defaults]\nsigla_book = full\n\n[defaults]\nsigla_book = abbr\n" in + let c = ok (C.of_string text) in + Alcotest.(check (option string)) "later block's sigla_book wins" (Some "abbr") (C.sigla_book c) + let suite = ( "Config", [ Alcotest.test_case "reads defaults" `Quick test_reads_defaults; @@ -119,4 +148,8 @@ let suite = Alcotest.test_case "overlays accumulate across blocks" `Quick test_overlays_accumulate_across_blocks; Alcotest.test_case "two defaults blocks report no unknown sections" - `Quick test_two_defaults_blocks_report_no_unknown_sections ] ) + `Quick test_two_defaults_blocks_report_no_unknown_sections; + Alcotest.test_case "sigla keys are read" `Quick test_sigla_keys_are_read; + Alcotest.test_case "empty config sigla keys are none" `Quick test_empty_config_sigla_keys_are_none; + Alcotest.test_case "sigla key repeated across blocks last wins" + `Quick test_sigla_key_repeated_across_blocks_last_wins ] ) |
