aboutsummaryrefslogtreecommitdiff
path: root/test
diff options
context:
space:
mode:
Diffstat (limited to 'test')
-rw-r--r--test/test_config.ml46
1 files changed, 45 insertions, 1 deletions
diff --git a/test/test_config.ml b/test/test_config.ml
index 067b255..83da015 100644
--- a/test/test_config.ml
+++ b/test/test_config.ml
@@ -66,6 +66,42 @@ let test_misspelled_section_is_reported_not_silently_dropped () =
Alcotest.(check (option string)) "lang not read from the wrong section" None (C.lang c);
Alcotest.(check (list string)) "section reported" [ "deafults" ] (C.unknown_sections c)
+(* THE regression test for the cross-module inconsistency: [config.ml] used
+ to locate [\[defaults\]] with [List.find_opt], taking only the FIRST
+ matching section and silently discarding every later one, while
+ [lang.ml]'s [of_string] folds over ALL matching sections. A scalar set in
+ the first block and a DIFFERENT scalar set only in the second block must
+ both resolve -- before the fix, [template] (second-block-only) came back
+ [None]. *)
+let test_two_defaults_blocks_both_contribute () =
+ let text = "[defaults]\nlang = pl\n\n[defaults]\ntemplate = ~/my-ordo.tex\n" in
+ let c = ok (C.of_string text) in
+ Alcotest.(check (option string)) "lang from first block" (Some "pl") (C.lang c);
+ Alcotest.(check (option string)) "template from second block" (Some "~/my-ordo.tex") (C.template c)
+
+(* Consistent with the existing within-section last-wins rule (see
+ [config.mli]'s [lang] comment): a key repeated ACROSS two [\[defaults\]]
+ blocks resolves to the value from the LATER block, exactly as it would if
+ both lines sat in one block. *)
+let test_key_repeated_across_blocks_last_wins () =
+ let text = "[defaults]\nlang = pl\n\n[defaults]\nlang = en\n" in
+ let c = ok (C.of_string text) in
+ Alcotest.(check (option string)) "later block's lang wins" (Some "en") (C.lang c)
+
+(* [overlay] must keep accumulating across block boundaries, in file order,
+ not merely within one block. *)
+let test_overlays_accumulate_across_blocks () =
+ let text = "[defaults]\noverlay = ~/a.ini\n\n[defaults]\noverlay = ~/b.ini\n" in
+ let c = ok (C.of_string text) in
+ Alcotest.(check (list string)) "both overlays, in file order" [ "~/a.ini"; "~/b.ini" ] (C.overlays c)
+
+(* Merging a second [\[defaults\]] block is the whole point -- it must not
+ start being reported as an unknown section. *)
+let test_two_defaults_blocks_report_no_unknown_sections () =
+ let text = "[defaults]\nlang = pl\n\n[defaults]\ntemplate = ~/my-ordo.tex\n" in
+ let c = ok (C.of_string text) in
+ Alcotest.(check (list string)) "no unknown sections" [] (C.unknown_sections c)
+
let suite =
( "Config",
[ Alcotest.test_case "reads defaults" `Quick test_reads_defaults;
@@ -75,4 +111,12 @@ let suite =
Alcotest.test_case "malformed is error" `Quick test_malformed_is_error_not_crash;
Alcotest.test_case "unknown key not fatal" `Quick test_unknown_key_is_reported_not_fatal;
Alcotest.test_case "misspelled section reported"
- `Quick test_misspelled_section_is_reported_not_silently_dropped ] )
+ `Quick test_misspelled_section_is_reported_not_silently_dropped;
+ Alcotest.test_case "two defaults blocks both contribute"
+ `Quick test_two_defaults_blocks_both_contribute;
+ Alcotest.test_case "key repeated across blocks last wins"
+ `Quick test_key_repeated_across_blocks_last_wins;
+ 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 ] )